diff --git a/.jsdoc.json b/.jsdoc.json index 961c6ad..9daee9e 100644 --- a/.jsdoc.json +++ b/.jsdoc.json @@ -13,6 +13,9 @@ "recurse": true }, "templates": { - "cleverLinks": false + "cleverLinks": false, + "monospaceLinks": true, + "useLongnameInNav": false, + "showInheritedInNav": true } } \ No newline at end of file diff --git a/docs/TorrentLibrary.html b/docs/TorrentLibrary.html index 0801abc..adad21c 100644 --- a/docs/TorrentLibrary.html +++ b/docs/TorrentLibrary.html @@ -24,7 +24,7 @@
@@ -103,7 +103,7 @@

new Tor
Source:
@@ -219,7 +219,7 @@

(static)
Source:
@@ -283,7 +283,141 @@

(static) Source:
+ + + + + + + + + + + + + + + +

+ + + +
+

allMovies

+ + + + +
+ Getter for all found movies +
+ + + + + +
+ + + + +
Since:
+
  • 0.0.0
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + +
+ + + +
+

allTvSeries

+ + + + +
+ Getter for all found tv-series +
+ + + + + +
+ + + + +
Since:
+
  • 0.0.0
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
@@ -347,7 +481,7 @@

catego
Source:
@@ -431,7 +565,7 @@

defaultPat
Source:
@@ -510,7 +644,7 @@

pathsSource:
@@ -589,7 +723,7 @@

storesSource:
@@ -676,7 +810,7 @@

(static)
Source:
@@ -794,7 +928,7 @@

addNewPath<
Source:
@@ -922,7 +1056,7 @@

Returns:
Example
-
// return resolved Promise "All paths were added!"
TorrentLibraryInstance.addNewPath("C:\Users\jy95\Desktop\New folder");
+
// return resolved Promise "All paths were added!"
TorrentLibraryInstance.addNewPath("C:\Users\jy95\Desktop\New folder","C:\Users\jy95\Desktop\New folder2");
@@ -979,7 +1113,7 @@

Source:
@@ -1040,12 +1174,16 @@

Returns:
-

scan()

+

scan() → {external:Promise}

+
+ Scans the paths in search for new files to be added inside this lib +
+ @@ -1055,6 +1193,9 @@

scanSince: +
  • 0.0.0
+ @@ -1079,7 +1220,7 @@

scanSource:
@@ -1088,15 +1229,6 @@

scanTo Do: -
-
    -
  • Write the documentation.
  • - -
  • Implement this function.
  • -
-
-

@@ -1118,6 +1250,31 @@

scan +
Returns:
+ + + +
+
+ Type: +
+
+ +external:Promise + + +
+
+ + +
+ On success the promise will be resolved with "Scanning completed"
On error the promise will be rejected with an Error object from sub modules
+
+ + +

@@ -1140,7 +1297,7 @@

scan
- Generated by JSDoc 3.5.4 on Sat Aug 26 2017 19:02:13 GMT+0200 (Romance Daylight Time) using the Minami theme. + Generated by JSDoc 3.5.4 on Sat Aug 26 2017 23:46:40 GMT+0200 (Romance Daylight Time) using the Minami theme.
diff --git a/docs/TorrentLibrary.js.html b/docs/TorrentLibrary.js.html index e7c1393..65e1c6e 100644 --- a/docs/TorrentLibrary.js.html +++ b/docs/TorrentLibrary.js.html @@ -24,7 +24,7 @@
@@ -119,6 +119,13 @@

TorrentLibrary.js

*/ import {access} from 'fs'; +/** + * Basename method from module path (node) + * @external basename + * @see {@link https://nodejs.org/api/path.html#path_path_basename_path_ext} + */ +import {basename} from 'path'; + /** * uniq method from Lodash * @external uniq @@ -245,7 +252,8 @@

TorrentLibrary.js

// process each file for (let file of newFiles) { // get data from nameParser lib - let jsonFile = nameParser(file); + // what we need is only the basename, not the full path + let jsonFile = nameParser(basename(file)); // extend this object in order to be used by this library Object.assign(jsonFile, {"filePath": file}); // find out which type of this file @@ -297,7 +305,6 @@

TorrentLibrary.js

// updates the stores var this.stores.set(TorrentLibrary.MOVIES_TYPE, newMovies); this.stores.set(TorrentLibrary.TV_SERIES_TYPE, newTvSeries); - } } @@ -320,7 +327,7 @@

TorrentLibrary.js

* @since 0.0.0 * @example * // return resolved Promise "All paths were added!" - * TorrentLibraryInstance.addNewPath("C:\Users\jy95\Desktop\New folder"); + * TorrentLibraryInstance.addNewPath("C:\Users\jy95\Desktop\New folder","C:\Users\jy95\Desktop\New folder2"); * @return {external:Promise} On success the promise will be resolved with "All paths were added!"<br> * On error the promise will be rejected with an Error object "Missing parameter" if the argument is missing<br> * or an Error object from fs <br> @@ -334,7 +341,7 @@

TorrentLibrary.js

return new PromiseLib(function (resolve, reject) { PromiseLib.map(paths, function (path) { - return access(path, FsConstants.F_OK | FsConstants.R_OK); + return promisifiedAccess(path); }).then(function () { // keep only unique paths that.paths = uniq([...that.paths, ...paths]); @@ -357,8 +364,10 @@

TorrentLibrary.js

} /** - * @todo Write the documentation. - * @todo Implement this function. + * Scans the paths in search for new files to be added inside this lib + * @since 0.0.0 + * @return {external:Promise} On success the promise will be resolved with "Scanning completed"<br> + * On error the promise will be rejected with an Error object from sub modules<br> */ scan() { @@ -380,6 +389,24 @@

TorrentLibrary.js

}); } + /** + * Getter for all found movies + * @since 0.0.0 + * @return {Set.<TPN_Extended>} + */ + get allMovies() { + return this.stores.get(TorrentLibrary.MOVIES_TYPE); + } + + /** + * Getter for all found tv-series + * @since 0.0.0 + * @return {Map.<string, Set.<TPN_Extended>>} + */ + get allTvSeries() { + return this.stores.get(TorrentLibrary.TV_SERIES_TYPE); + } + } // rejected promise when someone doesn't provide @@ -396,6 +423,21 @@

TorrentLibrary.js

}) } +/** + * Bluebird seems to have an issue with fs.access - Workaround function + * @private + * @param path {string} + * @see {@link https://github.com/petkaantonov/bluebird/issues/1442} + */ +function promisifiedAccess(path) { + return new PromiseLib(function (resolve,reject) { + access(path, FsConstants.F_OK | FsConstants.R_OK, (err) => { + if (err) reject(err); + resolve(); + }); + }) +} + export default TorrentLibrary; @@ -408,7 +450,7 @@

TorrentLibrary.js


- Generated by JSDoc 3.5.4 on Sat Aug 26 2017 19:02:13 GMT+0200 (Romance Daylight Time) using the Minami theme. + Generated by JSDoc 3.5.4 on Sat Aug 26 2017 23:46:39 GMT+0200 (Romance Daylight Time) using the Minami theme.
diff --git a/docs/external-FileHound.html b/docs/external-FileHound.html index ec35014..7145626 100644 --- a/docs/external-FileHound.html +++ b/docs/external-FileHound.html @@ -24,7 +24,7 @@
@@ -139,7 +139,7 @@


- Generated by JSDoc 3.5.4 on Sat Aug 26 2017 19:02:13 GMT+0200 (Romance Daylight Time) using the Minami theme. + Generated by JSDoc 3.5.4 on Sat Aug 26 2017 23:46:40 GMT+0200 (Romance Daylight Time) using the Minami theme.
diff --git a/docs/external-Promise.html b/docs/external-Promise.html index 9f556fa..de62668 100644 --- a/docs/external-Promise.html +++ b/docs/external-Promise.html @@ -24,7 +24,7 @@
@@ -87,7 +87,7 @@

Source:
@@ -139,7 +139,7 @@


- Generated by JSDoc 3.5.4 on Sat Aug 26 2017 19:02:13 GMT+0200 (Romance Daylight Time) using the Minami theme. + Generated by JSDoc 3.5.4 on Sat Aug 26 2017 23:46:40 GMT+0200 (Romance Daylight Time) using the Minami theme.
diff --git a/docs/external-access.html b/docs/external-access.html index 4cd3115..d01ccdc 100644 --- a/docs/external-access.html +++ b/docs/external-access.html @@ -24,7 +24,7 @@
@@ -139,7 +139,7 @@


- Generated by JSDoc 3.5.4 on Sat Aug 26 2017 19:02:13 GMT+0200 (Romance Daylight Time) using the Minami theme. + Generated by JSDoc 3.5.4 on Sat Aug 26 2017 23:46:40 GMT+0200 (Romance Daylight Time) using the Minami theme.
diff --git a/docs/external-basename.html b/docs/external-basename.html new file mode 100644 index 0000000..4f0ec5d --- /dev/null +++ b/docs/external-basename.html @@ -0,0 +1,148 @@ + + + + + + basename - Documentation + + + + + + + + + + + + + + + + + +
+ +

basename

+ + + + + + + +
+ +
+ +

+ basename +

+ + +
+ + + +
+ + + + +
+ +
+ +
+ Generated by JSDoc 3.5.4 on Sat Aug 26 2017 23:46:40 GMT+0200 (Romance Daylight Time) using the Minami theme. +
+ + + + + \ No newline at end of file diff --git a/docs/external-difference.html b/docs/external-difference.html index 20c0ab9..a2020de 100644 --- a/docs/external-difference.html +++ b/docs/external-difference.html @@ -24,7 +24,7 @@
@@ -87,7 +87,7 @@

Source:
@@ -139,7 +139,7 @@


- Generated by JSDoc 3.5.4 on Sat Aug 26 2017 19:02:13 GMT+0200 (Romance Daylight Time) using the Minami theme. + Generated by JSDoc 3.5.4 on Sat Aug 26 2017 23:46:40 GMT+0200 (Romance Daylight Time) using the Minami theme.
diff --git a/docs/external-nameParser.html b/docs/external-nameParser.html index b26559a..be9c702 100644 --- a/docs/external-nameParser.html +++ b/docs/external-nameParser.html @@ -24,7 +24,7 @@
@@ -87,7 +87,7 @@

Source:
@@ -139,7 +139,7 @@


- Generated by JSDoc 3.5.4 on Sat Aug 26 2017 19:02:13 GMT+0200 (Romance Daylight Time) using the Minami theme. + Generated by JSDoc 3.5.4 on Sat Aug 26 2017 23:46:40 GMT+0200 (Romance Daylight Time) using the Minami theme.
diff --git a/docs/external-uniq.html b/docs/external-uniq.html index 7b102c5..77a736f 100644 --- a/docs/external-uniq.html +++ b/docs/external-uniq.html @@ -24,7 +24,7 @@
@@ -87,7 +87,7 @@

Source:
@@ -139,7 +139,7 @@


- Generated by JSDoc 3.5.4 on Sat Aug 26 2017 19:02:13 GMT+0200 (Romance Daylight Time) using the Minami theme. + Generated by JSDoc 3.5.4 on Sat Aug 26 2017 23:46:40 GMT+0200 (Romance Daylight Time) using the Minami theme.
diff --git a/docs/external-videosExtension.html b/docs/external-videosExtension.html index d492dd4..a7977e5 100644 --- a/docs/external-videosExtension.html +++ b/docs/external-videosExtension.html @@ -24,7 +24,7 @@
@@ -87,7 +87,7 @@

Source:
@@ -139,7 +139,7 @@


- Generated by JSDoc 3.5.4 on Sat Aug 26 2017 19:02:13 GMT+0200 (Romance Daylight Time) using the Minami theme. + Generated by JSDoc 3.5.4 on Sat Aug 26 2017 23:46:40 GMT+0200 (Romance Daylight Time) using the Minami theme.
diff --git a/docs/global.html b/docs/global.html index 7afcf9c..0553edb 100644 --- a/docs/global.html +++ b/docs/global.html @@ -24,7 +24,7 @@
@@ -975,7 +975,7 @@
Type:

- Generated by JSDoc 3.5.4 on Sat Aug 26 2017 19:02:13 GMT+0200 (Romance Daylight Time) using the Minami theme. + Generated by JSDoc 3.5.4 on Sat Aug 26 2017 23:46:40 GMT+0200 (Romance Daylight Time) using the Minami theme.
diff --git a/docs/index.html b/docs/index.html index 51b6d65..73afaa7 100644 --- a/docs/index.html +++ b/docs/index.html @@ -24,7 +24,7 @@
@@ -57,7 +57,7 @@
- Generated by JSDoc 3.5.4 on Sat Aug 26 2017 19:02:13 GMT+0200 (Romance Daylight Time) using the Minami theme. + Generated by JSDoc 3.5.4 on Sat Aug 26 2017 23:46:40 GMT+0200 (Romance Daylight Time) using the Minami theme.
diff --git a/src/TorrentLibrary.js b/src/TorrentLibrary.js index ea36669..5b714b3 100644 --- a/src/TorrentLibrary.js +++ b/src/TorrentLibrary.js @@ -78,6 +78,13 @@ import FileHound from 'filehound'; */ import {access} from 'fs'; +/** + * Basename method from module path (node) + * @external basename + * @see {@link https://nodejs.org/api/path.html#path_path_basename_path_ext} + */ +import {basename} from 'path'; + /** * uniq method from Lodash * @external uniq @@ -204,7 +211,8 @@ class TorrentLibrary extends EventEmitter { // process each file for (let file of newFiles) { // get data from nameParser lib - let jsonFile = nameParser(file); + // what we need is only the basename, not the full path + let jsonFile = nameParser(basename(file)); // extend this object in order to be used by this library Object.assign(jsonFile, {"filePath": file}); // find out which type of this file @@ -256,7 +264,6 @@ class TorrentLibrary extends EventEmitter { // updates the stores var this.stores.set(TorrentLibrary.MOVIES_TYPE, newMovies); this.stores.set(TorrentLibrary.TV_SERIES_TYPE, newTvSeries); - } } @@ -279,7 +286,7 @@ class TorrentLibrary extends EventEmitter { * @since 0.0.0 * @example * // return resolved Promise "All paths were added!" - * TorrentLibraryInstance.addNewPath("C:\Users\jy95\Desktop\New folder"); + * TorrentLibraryInstance.addNewPath("C:\Users\jy95\Desktop\New folder","C:\Users\jy95\Desktop\New folder2"); * @return {external:Promise} On success the promise will be resolved with "All paths were added!"
* On error the promise will be rejected with an Error object "Missing parameter" if the argument is missing
* or an Error object from fs
@@ -293,7 +300,7 @@ class TorrentLibrary extends EventEmitter { return new PromiseLib(function (resolve, reject) { PromiseLib.map(paths, function (path) { - return access(path, FsConstants.F_OK | FsConstants.R_OK); + return promisifiedAccess(path); }).then(function () { // keep only unique paths that.paths = uniq([...that.paths, ...paths]); @@ -316,8 +323,10 @@ class TorrentLibrary extends EventEmitter { } /** - * @todo Write the documentation. - * @todo Implement this function. + * Scans the paths in search for new files to be added inside this lib + * @since 0.0.0 + * @return {external:Promise} On success the promise will be resolved with "Scanning completed"
+ * On error the promise will be rejected with an Error object from sub modules
*/ scan() { @@ -339,6 +348,24 @@ class TorrentLibrary extends EventEmitter { }); } + /** + * Getter for all found movies + * @since 0.0.0 + * @return {Set.} + */ + get allMovies() { + return this.stores.get(TorrentLibrary.MOVIES_TYPE); + } + + /** + * Getter for all found tv-series + * @since 0.0.0 + * @return {Map.>} + */ + get allTvSeries() { + return this.stores.get(TorrentLibrary.TV_SERIES_TYPE); + } + } // rejected promise when someone doesn't provide @@ -355,4 +382,19 @@ function checkProperties(obj, properties) { }) } +/** + * Bluebird seems to have an issue with fs.access - Workaround function + * @private + * @param path {string} + * @see {@link https://github.com/petkaantonov/bluebird/issues/1442} + */ +function promisifiedAccess(path) { + return new PromiseLib(function (resolve,reject) { + access(path, FsConstants.F_OK | FsConstants.R_OK, (err) => { + if (err) reject(err); + resolve(); + }); + }) +} + export default TorrentLibrary; \ No newline at end of file diff --git a/test/APITests.js b/test/APITests.js index 4de98a8..f07c9b7 100644 --- a/test/APITests.js +++ b/test/APITests.js @@ -98,16 +98,15 @@ describe("TorrentLibrary tests", function () { }) }); - /* + it("existent paths", function (done) { - libInstance.addNewPath(folders) + libInstance.addNewPath(...folders) .then(() => { done() }).catch((err) => { done(err); }) }); - */ }); context("scan()", function () {