فهرست منبع

Fix Imagemagick memory issue
Fix selection issue when removing multiple items

isundil 1 سال پیش
والد
کامیت
28584a94ec
8فایلهای تغییر یافته به همراه24 افزوده شده و 16 حذف شده
  1. 2 6
      main.js
  2. 1 1
      router/api.js
  3. 4 2
      src/filetype/imagemagick.js
  4. 3 1
      src/library.js
  5. 5 3
      src/libraryManager.js
  6. 2 2
      static/public/css/style.css
  7. 3 1
      static/public/js/medias.js
  8. 4 0
      static/public/js/uiMedia.js

+ 2 - 6
main.js

@@ -36,14 +36,10 @@ App.prototype.init = async function() {
 }
 
 App.prototype.run = async function() {
-    let BuilderClass = require('./src/autotagBuilder');
-
     http.createServer(this.router).listen(CONFIG.port);
-    await this.libraryManager.updateLibraries(this.databaseHelper);
-    await BuilderClass.rebuildPathTags(this);
+    await this.libraryManager.updateLibraries(this);
     setInterval(async () => {
-        await this.libraryManager.updateLibraries(this.databaseHelper);
-        BuilderClass.rebuildPathTags(this);
+        await this.libraryManager.updateLibraries(this);
     }, UPDATE_INTERVAL);
 }
 

+ 1 - 1
router/api.js

@@ -48,7 +48,7 @@ module.exports = { register: app => {
         app.routerUtils.onApiRequest(req, res);
         if (!await req.sessionObj?.accessList?.isAdmin(app, req.sessionObj?.accessList))
             return app.routerUtils.onBadRequest(res);
-        app.libraryManager.updateLibraries(app.databaseHelper).finally(x => { require('../src/autotagBuilder').rebuildPathTags(app); });
+        app.libraryManager.updateLibraries(app);
         app.routerUtils.jsonResponse(res, {});
     });
     app.router.get("/api/access/list", async (req, res) => {

+ 4 - 2
src/filetype/imagemagick.js

@@ -5,8 +5,10 @@ const imLib = require('imagemagick');
 const ThreadPool = require('../threadPool.js');
 const MetaStruct = require('./metaStruct.js').MetaStruct;
 
+const IMAGEMAGICK_THREAD_COUNT = 3;
+
 class ImagemagickWrapper {
-    #threadPool = new ThreadPool(5);
+    #threadPool = new ThreadPool(IMAGEMAGICK_THREAD_COUNT);
 
     readMeta(path) {
         return this.#threadPool.pushTask(() => new Promise((ok, ko) => {
@@ -115,7 +117,7 @@ module.exports.parse = async (fileObj, data) => {
         result.tags = readTags(imdata);
     }
     catch (err) {
-        result.imException = err.toString();
+        return {};
     }
     for (let i of Object.keys(result))
         if (result[i] === undefined || result[i].length === 0)

+ 3 - 1
src/library.js

@@ -48,13 +48,15 @@ File.prototype.enrich = async function() {
     this.meta = null;
     await this.computeChecksum();
     if (this.getIsMedia()) {
-        this.meta = await FileTypeManager.createMeta(this);
+        this.meta = (await FileTypeManager.createMeta(this)) || {};
         this.tags = this.meta.tags || [];
         this.meta.tags = undefined;
     }
 }
 
 File.prototype.saveDb = async function(db, libraryHash) {
+    if (!Object.keys(this.meta).length)
+        return;
     if (this.dbItem) {
         this.fixedSum = this.dbItem.fixedSum;
         await db.remove(MediaFileModel, { path: this.dbItem.path, fixedSum: this.dbItem.fixedSum });

+ 5 - 3
src/libraryManager.js

@@ -1,7 +1,8 @@
 
+const Path = require('path');
 const CONFIG = require('./config.js');
 const Library = require('./library.js').Library;
-const Path = require('path');
+const BuilderClass = require('./autotagBuilder');
 
 function LibraryManager() {
     this.libraries = [];
@@ -15,11 +16,12 @@ LibraryManager.prototype.push = function(path) {
     this.libraries.push(new Library(path));
 }
 
-LibraryManager.prototype.updateLibraries = async function(dbHelper) {
+LibraryManager.prototype.updateLibraries = async function(app) {
     if (this.updating)
         return;
     this.updating = true;
-    await Promise.allSettled(this.libraries.map(i => i.updateLibrary(dbHelper)));
+    await Promise.allSettled(this.libraries.map(i => i.updateLibrary(app.databaseHelper)));
+    await BuilderClass.rebuildPathTags(app);
     this.updating = false;
 }
 

+ 2 - 2
static/public/css/style.css

@@ -232,7 +232,7 @@ body.filter-active #pch-navbar .bt-filter-inactive {
 }
 
 #pch-fullPageMedia .modal-body > .row > .col {
-    height: 100%;
+    min-height: 100%;
     overflow-x: hidden;
     overflow-y: auto;
 }
@@ -251,7 +251,7 @@ body.filter-active #pch-navbar .bt-filter-inactive {
 }
 
 #pch-fullPageMedia .leaflet-container > div {
-    min-height: 300px;
+    min-height: 600px;
 }
 
 #pch-fullPagePreview {

+ 3 - 1
static/public/js/medias.js

@@ -286,8 +286,10 @@ class MediaStorage extends EventTarget
     removeMedia(md5sums) {
         let medias = this.medias.filter(x => md5sums.indexOf(x.fixedSum) >= 0);
         this.medias = this.medias.filter(x => md5sums.indexOf(x.fixedSum) === -1);
-        for (let i of medias)
+        for (let i of medias) {
             i.ui && i.ui.root.remove();
+            this.dispatchEvent(new CustomEvent("mediaRemoved", { detail: i }));
+        }
     }
 
     getMediaLocal(md5sum) {

+ 4 - 0
static/public/js/uiMedia.js

@@ -186,6 +186,10 @@ $(() => {
         }
     });
 
+    MediaStorage.Instance.addEventListener("mediaRemoved", evt => {
+        setSelectionCheckboxValue(evt.detail, false);
+    });
+
     window.displayMoreMedia = () => {
         targetDisplayedItems += displayItemBatchCount;
         let container = document.getElementById('pch-mediaList');