Przeglądaj źródła

init of libraries

isundil 2 lat temu
rodzic
commit
da3b23e5b3
4 zmienionych plików z 36 dodań i 9 usunięć
  1. 2 2
      main.js
  2. 0 4
      model/session.js
  3. 5 1
      src/config.js
  4. 29 2
      src/md5sum.js

+ 2 - 2
main.js

@@ -12,17 +12,17 @@ function App() {
     this.router = new Router({ static_route: __dirname+"/static/" });
     this.routerUtils = new RouterUtils(this);
     this.databaseHelper = require('./src/databaseHelper.js').DatabaseHelper;
+    this.libraryManager = require('./src/libraryManager.js').LibraryManager;
 }
 
 App.prototype.init = async function() {
-    const _app = this;
     require('./router/mdi.js').register(this);
-
     await this.databaseHelper.init();
 }
 
 App.prototype.run = function() {
     http.createServer(this.router).listen(CONFIG.port);
+    this.libraryManager.updateLibraries().then(() => process.exit());
 }
 
 let app = new App();

+ 0 - 4
model/session.js

@@ -7,7 +7,6 @@ function SessionModel(sessionInfos) {
     this.ipAddress = sessionInfos?.ipAddress || "";
     this.loginDateTime = new Date(sessionInfos?.loginDateTime || 0);
     this.username = sessionInfos?.username || "";
-    this.mail = sessionInfos?.mail || "";
     this.sessionId = sessionInfos?.sessionId || "";
     this.instance = sessionInfos?.instance || "";
 }
@@ -26,7 +25,6 @@ SessionModel.prototype.createOrUpdateBase = async function(dbHelper) {
         remoteAddress STRING NOT NULL,
         loginDateTime TIMESTAMP NOT NULL,
         username STRING NOT NULL,
-        mail STRING NOT NULL,
         PRIMARY KEY (sessionId, instance))`);
 }
 
@@ -37,7 +35,6 @@ SessionModel.prototype.describe = function() {
         "remoteAddress": this.ipAddress,
         "loginDateTime": this.loginDateTime.getTime(),
         "username": this.username,
-        "mail": this.mail,
         "instance": this.instance
     };
 }
@@ -50,7 +47,6 @@ SessionModel.prototype.fromDb = function(dbObj) {
     this.ipAddress = dbObj["remoteAddress"];
     this.loginDateTime.setTime(dbObj["loginDateTime"]);
     this.username = dbObj["username"];
-    this.mail = dbObj["mail"];
     this.instance = dbObj["instance"];
 }
 

+ 5 - 1
src/config.js

@@ -41,12 +41,16 @@ let configEntries = {};
         ldapFilter: { value: "", valid: validNotEmptyString },
         ldapBase: { value: "", valid: validNotEmptyString },
         database: { value: "", valid: validNotEmptyString },
-        archivePath: { value: path.join(__dirname, "../archives/"), valid: validNotEmptyString },
         DEBUG_forceLogin: { value: null, valid: () => true }
     };
 
     configEntries = pickConfig(defaultConfig, configContent);
 
+    configEntries.photoLibraries = [];
+    for (let i of configContent.photoLibraries)
+        if (validNotEmptyString(i))
+            configEntries.photoLibraries.push(i);
+
     console.log(configEntries);
     if (hasErrors)
         throw "Errors found while parsing configuration";

+ 29 - 2
src/md5sum.js

@@ -3,15 +3,42 @@ const crypto = require('crypto');
 const fs = require('fs');
 
 function md5File(path) {
-    return crypto.createHash('md5').update(fs.readFileSync(path)).digest('hex');
+    return new Promise((ok, ko) => {
+        const readStream = fs.createReadStream(path);
+        let hash = crypto.createHash('md5');
+
+        readStream.on('data', chunk => hash.update(chunk.toString()));
+        readStream.once('end', () => {
+            ok(hash.digest('hex'));
+        });
+        readStream.once('error', () => ok(""));
+    });
 }
 
 function md5String(input) {
     return crypto.createHash('md5').update(input).digest('hex');
 }
 
+function md5Stats(path) {
+    return new Promise((ok, ko) => {
+        fs.stat(path, (err, st) => {
+            if (err)
+                ok("");
+            else
+                ok(md5String(JSON.stringify({
+                    path: path,
+                    size: st.size,
+                    atimeMs: st.atimeMs,
+                    mtimeMs: st.mtimeMs,
+                    ctimeMs: st.ctimeMs
+                })));
+        });
+    });
+}
+
 module.exports = {
     file: md5File,
-    string: md5String
+    string: md5String,
+    stats: md5Stats
 }