|
|
@@ -37,7 +37,7 @@ File.prototype.saveDb = async function(db, libraryHash) {
|
|
|
let _this = this;
|
|
|
entity.path = this.path;
|
|
|
entity.md5sum = this.checksum;
|
|
|
- entity.date = this.meta.dateTime || new Date(fs.statsSync(this.path)?.birthtimeMs || Date.now());
|
|
|
+ entity.date = this.meta.dateTime || new Date(fs.statSync(this.path)?.birthtimeMs || Date.now());
|
|
|
await db.insertOne(entity);
|
|
|
this.meta.photochamberImport = new Date();
|
|
|
this.meta.libraryPath = libraryHash;
|
|
|
@@ -45,6 +45,10 @@ File.prototype.saveDb = async function(db, libraryHash) {
|
|
|
await db.insertMultipleSameTable(metaEntities);
|
|
|
}
|
|
|
|
|
|
+File.prototype.createThumbnail = async function(w, h) {
|
|
|
+ return await FileTypeManager.createThumbnail(this, w, h);
|
|
|
+}
|
|
|
+
|
|
|
async function enrichAll(lib) {
|
|
|
for (let i =0; i < lib.buff.length; i += 5)
|
|
|
await Promise.allSettled(lib.buff.slice(i, i+5).map(i => i.enrich()));
|
|
|
@@ -57,7 +61,7 @@ async function Library_doUpdate(dbHelper, lib) {
|
|
|
lib.buff = lib.buff.filter(i => dbItems.indexOf(i.path) === -1);
|
|
|
await enrichAll(lib);
|
|
|
lib.buff = lib.buff.filter(i => !!i.checksum);
|
|
|
- await Promise.allSettled(lib.buff.map(i => i.saveDb(dbHelper, lib.dbHash)));
|
|
|
+ (await Promise.allSettled(lib.buff.map(i => i.saveDb(dbHelper, lib.dbHash)))).forEach(x => { if (x.status === 'rejected') { console.log(`Cannot update item: `, x.reason); }});
|
|
|
lib.foundMedias = lib.foundMedias.concat(lib.buff);
|
|
|
lib.buff = [];
|
|
|
}
|
|
|
@@ -79,20 +83,33 @@ function Library_isValid(_this) {
|
|
|
return fs.existsSync(_this.path);
|
|
|
}
|
|
|
|
|
|
-function Library(path) {
|
|
|
- this.path = path;
|
|
|
- this.dbHash = md5String(path);
|
|
|
+function Library(p) {
|
|
|
+ this.path = path.normalize(p);
|
|
|
+ this.dbHash = md5String(this.path);
|
|
|
}
|
|
|
|
|
|
Library.prototype.updateLibrary = async function(dbHelper) {
|
|
|
console.log(`Starting update of library ${this.path}`);
|
|
|
this.foundMedias = [];
|
|
|
this.buff = [];
|
|
|
- if (Library_isValid(this))
|
|
|
- await Library_depthupdate(dbHelper, this, this.path);
|
|
|
- await Library_doUpdate(dbHelper, this)
|
|
|
+ this.errors = {};
|
|
|
+ try {
|
|
|
+ if (Library_isValid(this))
|
|
|
+ await Library_depthupdate(dbHelper, this, this.path);
|
|
|
+ await Library_doUpdate(dbHelper, this)
|
|
|
+ } catch (err) {
|
|
|
+ console.err(`Cannot update Library ${this.path}:`, err);
|
|
|
+ }
|
|
|
console.log(`Done updating library ${this.path}. Managed ${this.foundMedias.length} new media files.`);
|
|
|
}
|
|
|
|
|
|
+Library.prototype.findMedia = async function(p) {
|
|
|
+ if (!p.startsWith(this.path))
|
|
|
+ return null;
|
|
|
+ let result = new File(p, path.basename(p));
|
|
|
+ await result.enrich();
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
module.exports.Library = Library;
|
|
|
|