|
|
@@ -9,7 +9,7 @@ const { ACCESS_TO, AccessModel } = require("../model/access.js");
|
|
|
const MediaFileModel = require("../model/mediaItem.js").MediaFileModel;
|
|
|
const MediaFileMetaModel = require("../model/mediaItemMeta.js").MediaFileMetaModel;
|
|
|
const MediaFileTagModel = require("../model/mediaItemTag.js").MediaFileTagModel;
|
|
|
-const MANAGED_FILES = [ ".cr2" ]; // TODO
|
|
|
+const MANAGED_FILES = [ /* ".cr2" */ ]; // TODO
|
|
|
const BUFFER_MAXSIZE = 100;
|
|
|
|
|
|
function File(fullPath, name) {
|
|
|
@@ -28,7 +28,7 @@ File.prototype.getIsMedia = function() {
|
|
|
return this.isMedia;
|
|
|
if (!this.mimeType)
|
|
|
this.mimeType = mime.lookup(this.name) || "";
|
|
|
- this.isMedia = this.mimeType.startsWith("image/") || this.mimeType.startsWith("video/") || !!MANAGED_FILES.find(i => lowerName.endsWith(i));
|
|
|
+ this.isMedia = this.mimeType.startsWith("image/") || /*this.mimeType.startsWith("video/") || */!!MANAGED_FILES.find(i => this.name.toLowerCase().endsWith(i));
|
|
|
return this.isMedia;
|
|
|
}
|
|
|
|
|
|
@@ -55,9 +55,10 @@ File.prototype.enrich = async function() {
|
|
|
File.prototype.saveDb = async function(db, libraryHash) {
|
|
|
if (this.dbItem) {
|
|
|
await db.remove(MediaFileModel, { path: this.dbItem.path, md5sum: this.dbItem.md5sum });
|
|
|
- await db.remove(MediaFileMetaModel, { md5sum: this.dbItem.md5sum });
|
|
|
+ await db.remove(MediaFileMetaModel, { md5sum: this.dbItem.md5sum, fromFile: true });
|
|
|
await db.remove(MediaFileTagModel, { md5sum: this.dbItem.md5sum, fromMeta: true });
|
|
|
await db.rawUpdate(MediaFileTagModel, { md5sum: this.dbItem.md5sum }, { md5sum: this.checksum });
|
|
|
+ await db.rawUpdate(MediaFileMetaModel, { md5sum: this.dbItem.md5sum }, { md5sum: this.checksum });
|
|
|
await db.rawUpdate(AccessModel, { accessToData: this.dbItem.md5sum, accessTo: ACCESS_TO.item }, { accessToData: this.checksum });
|
|
|
}
|
|
|
let entity = new MediaFileModel();
|
|
|
@@ -68,7 +69,7 @@ File.prototype.saveDb = async function(db, libraryHash) {
|
|
|
await db.insertOne(entity);
|
|
|
this.meta.photochamberImport = new Date();
|
|
|
this.meta.libraryPath = libraryHash;
|
|
|
- let metaEntities = Object.keys(this.meta).filter(i => i !== 'tags').map(i => new MediaFileMetaModel(_this.checksum, i, _this.meta[i]));
|
|
|
+ let metaEntities = Object.keys(this.meta).filter(i => i !== 'tags').map(i => new MediaFileMetaModel(_this.checksum, i, _this.meta[i], true));
|
|
|
await db.insertMultipleSameTable(metaEntities);
|
|
|
if (this.tags.length) {
|
|
|
let tagsEntities = this.tags.map(i => new MediaFileTagModel(_this.checksum, i, true));
|
|
|
@@ -106,6 +107,8 @@ async function Library_depthupdate(dbHelper, library, dir) {
|
|
|
await Library_depthupdate(dbHelper, library, fullPath);
|
|
|
else if (o.isFile()) {
|
|
|
let f = new File(fullPath, o.name);
|
|
|
+ if (!f.getIsMedia())
|
|
|
+ continue;
|
|
|
await f.computeChecksum();
|
|
|
library.buff.push(f);
|
|
|
if (library.buff.length >= BUFFER_MAXSIZE)
|
|
|
@@ -115,7 +118,9 @@ async function Library_depthupdate(dbHelper, library, dir) {
|
|
|
}
|
|
|
|
|
|
function Library_isValid(_this) {
|
|
|
- return fs.existsSync(_this.path);
|
|
|
+ if (fs.existsSync(_this.path))
|
|
|
+ return true;
|
|
|
+ console.error(`Library folder not found (${_this.path})`);
|
|
|
}
|
|
|
|
|
|
function Library(p) {
|
|
|
@@ -124,6 +129,7 @@ function Library(p) {
|
|
|
}
|
|
|
|
|
|
Library.prototype.updateLibrary = async function(dbHelper) {
|
|
|
+ const startTime = Date.now();
|
|
|
console.log(`Starting update of library ${this.path}`);
|
|
|
this.foundMedias = [];
|
|
|
this.buff = [];
|
|
|
@@ -135,7 +141,10 @@ Library.prototype.updateLibrary = async function(dbHelper) {
|
|
|
} catch (err) {
|
|
|
console.err(`Cannot update Library ${this.path}:`, err);
|
|
|
}
|
|
|
- console.log(`Done updating library ${this.path}. Managed ${this.foundMedias.length} new media files.`);
|
|
|
+ let timeDiff = (Date.now() - startTime) / 1000;
|
|
|
+ const timeDiffMin = Math.floor(timeDiff / 60);
|
|
|
+ timeDiff -= timeDiffMin*60;
|
|
|
+ console.log(`Done updating library ${this.path}. Managed ${this.foundMedias.length} new media files. in ${timeDiffMin}m ${timeDiff}s`);
|
|
|
}
|
|
|
|
|
|
Library.prototype.findMedia = async function(p) {
|