|
|
@@ -6,6 +6,7 @@ const md5String = require('craftlabhttpserver/src/md5sum.js').string;
|
|
|
const FileTypeManager = require('./fileTypeManager.js');
|
|
|
|
|
|
const { ACCESS_TO, AccessModel } = require("../model/access.js");
|
|
|
+const CreateConfigLoader = require('../model/configModel.js').ConfigLoader;
|
|
|
const MediaFileModel = require("../model/mediaItem.js").MediaFileModel;
|
|
|
const MediaFileMetaModel = require("../model/mediaItemMeta.js").MediaFileMetaModel;
|
|
|
const MediaFileTagModel = require("../model/mediaItemTag.js").MediaFileTagModel;
|
|
|
@@ -92,9 +93,9 @@ async function Library_doUpdate(dbHelper, lib) {
|
|
|
if (lib.buff.length === 0)
|
|
|
return;
|
|
|
lib.buff = lib.buff.filter(i => !!i.checksum);
|
|
|
- const dbItems = (await dbHelper.fetchRaw(["path", "md5sum", "fixedSum"], MediaFileModel.prototype.getTableName.call(null), { "path": lib.buff.map(i => i.path) }));
|
|
|
+ const dbItems = (await dbHelper.fetchRaw(["path", "md5sum", "fixedSum", "inaccessible"], MediaFileModel.prototype.getTableName.call(null), { "path": lib.buff.map(i => i.path) }));
|
|
|
lib.buff.forEach(i => i.dbItem = dbItems.find(x => x.path == i.path));
|
|
|
- lib.buff = lib.buff.filter(i => !i.dbItem || i.dbItem.md5sum != i.checksum);
|
|
|
+ lib.buff = lib.buff.filter(i => !i.dbItem || i.dbItem.md5sum != i.checksum || i.dbItem.inaccessible);
|
|
|
await enrichAll(lib);
|
|
|
(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);
|
|
|
@@ -130,6 +131,28 @@ function Library(p) {
|
|
|
this.dbHash = md5String(this.path);
|
|
|
}
|
|
|
|
|
|
+function notReadable(path) {
|
|
|
+ return !fs.existsSync(path);
|
|
|
+}
|
|
|
+
|
|
|
+Library.prototype.findInaccessibleItems = async function(dbHelper) {
|
|
|
+ let i =0;
|
|
|
+ const pager = 500;
|
|
|
+ const currentVersion = Date.now();
|
|
|
+ let data = [];
|
|
|
+ do {
|
|
|
+ data = (await dbHelper.runSql(`select mediaFile.fixedSum, mediaFile.path from mediaFile
|
|
|
+ inner join mediaMeta on mediaMeta.md5sum=mediaFile.fixedSum
|
|
|
+ where mediaMeta.key=? and mediaMeta.value=? and mediaFile.inaccessible=0 limit ? offset ?`, ["libraryPath", this.dbHash, pager, pager*i]));
|
|
|
+ let missing = data.filter(x => notReadable(x.path));
|
|
|
+ if (missing.length) {
|
|
|
+ console.log(missing);
|
|
|
+ await dbHelper.runSql("update mediaFile set version=?, inaccessible=? where fixedSum in ("+missing.map(x => '?').join(',')+")", [ currentVersion, currentVersion].concat(missing.map(x => x.fixedSum)));
|
|
|
+ }
|
|
|
+ ++i;
|
|
|
+ } while (data.length == pager);
|
|
|
+}
|
|
|
+
|
|
|
Library.prototype.updateLibrary = async function(dbHelper) {
|
|
|
const startTime = Date.now();
|
|
|
console.log(`Starting update of library ${this.path}`);
|
|
|
@@ -140,6 +163,7 @@ Library.prototype.updateLibrary = async function(dbHelper) {
|
|
|
if (Library_isValid(this))
|
|
|
await Library_depthupdate(dbHelper, this, this.path);
|
|
|
await Library_doUpdate(dbHelper, this)
|
|
|
+ await this.findInaccessibleItems(dbHelper);
|
|
|
} catch (err) {
|
|
|
console.err(`Cannot update Library ${this.path}:`, err);
|
|
|
}
|