Fixed EMFILE problem

Signed-off-by: James Ketrenos <james_git@ketrenos.com>
This commit is contained in:
James Ketr 2018-09-28 01:37:44 -07:00
parent dd329dfd75
commit 4a9bb061b0
4 changed files with 56 additions and 43 deletions

View File

@ -258,7 +258,10 @@
font-weight: bold; font-weight: bold;
} }
#memories [is-today] paper-icon-button { #requestAccess {
max-width: 60ex;
border: 1px solid #444;
box-sizing: border-box;
} }
#requestAccess div > div { #requestAccess div > div {
@ -372,15 +375,16 @@
</div> </div>
<paper-dialog id="requestAccess" modal> <paper-dialog id="requestAccess" modal>
<div class="layout vertical"> <div class="layout vertical">
<div class="title">Hello!</div> <div class="title">Create an account</div>
<div> <div>
Unfortunately, I haven't built this part of the site yet... send me an email (james @ ketrenos.com) <p>To have your account activated, tell me who you know in the 'who do you know?' field.</p>
and I'll create an account for you. <p>Thanks,</p>
<p>James</p>
</div> </div>
<paper-input tabindex=0 autofocus id="username" label="User ID" value="{{username}}" on-keypress="enterCheck"></paper-input> <paper-input tabindex=0 autofocus id="mail" label="E-mail" value="{{mail}}" on-keypress="enterCheck"></paper-input>
<paper-input tabindex=0 id="password" label="Password" type="password" value="{{password}}" on-keypress="enterCheck"></paper-input> <paper-input tabindex=0 id="password" label="Password" type="password" value="{{password}}" on-keypress="enterCheck"></paper-input>
<paper-input tabindex=0 id="name" label="Display name" value="{{name}}" on-keypress="enterCheck"></paper-input> <paper-input tabindex=0 id="name" label="Display name" value="{{name}}" on-keypress="enterCheck"></paper-input>
<paper-input tabindex=0 id="mail" label="E-mail" value="{{mail}}" on-keypress="enterCheck"></paper-input> <paper-input tabindex=0 id="who" label="Who do you know?" value="{{who}}" on-keypress="enterCheck"></paper-input>
<paper-button tabindex=0 id="createButton" disabled$="[[disableCreate(username,name,password,mail)]]" on-tap="create" raised><div hidden$="[[loggingIn]]">create</div><div hidden$="[[!loggingIn]]"><paper-spinner active$="[[loggingIn]]"></paper-spinner></div></paper-button> <paper-button tabindex=0 id="createButton" disabled$="[[disableCreate(username,name,password,mail)]]" on-tap="create" raised><div hidden$="[[loggingIn]]">create</div><div hidden$="[[!loggingIn]]"><paper-spinner active$="[[loggingIn]]"></paper-spinner></div></paper-button>
</div> </div>
</paper-dialog> </paper-dialog>
@ -600,7 +604,7 @@
this.user = user; this.user = user;
} }
}.bind(this), null, "POST", { }.bind(this), null, "POST", {
u: this.username, w: this.who,
p: this.password, p: this.password,
n: this.name, n: this.name,
m: this.mail m: this.mail

View File

@ -32,6 +32,7 @@ function init() {
autoIncrement: true autoIncrement: true
}, },
displayName: Sequelize.STRING, displayName: Sequelize.STRING,
notes: Sequelize.STRING,
uid: Sequelize.STRING, uid: Sequelize.STRING,
isLDAP: Sequelize.BOOLEAN, isLDAP: Sequelize.BOOLEAN,
authToken: Sequelize.STRING, authToken: Sequelize.STRING,

View File

@ -43,34 +43,35 @@ function ldapPromise(username, password) {
} }
router.post("/create", function(req, res) { router.post("/create", function(req, res) {
let username = req.query.u || req.body.u || "", let who = req.query.w || req.body.w || "",
password = req.query.p || req.body.p || "", password = req.query.p || req.body.p || "",
name = req.query.n || req.body.n || username, name = req.query.n || req.body.n || username,
mail = req.query.m || req.body.m; mail = req.query.m || req.body.m;
if (!username || !password || !mail || !name) { if (!who || !password || !mail || !name) {
return res.status(400).send("Missing user id, name, password, and/or email"); return res.status(400).send("Missing who you know, name, password, and/or email");
} }
let query = "SELECT * FROM users WHERE uid=:username"; let query = "SELECT * FROM users WHERE uid=:username";
return userDB.sequelize.query(query, { return userDB.sequelize.query(query, {
replacements: { replacements: {
username: username username: mail
}, },
type: userDB.Sequelize.QueryTypes.SELECT type: userDB.Sequelize.QueryTypes.SELECT
}).then(function(results) { }).then(function(results) {
if (results.length != 0) { if (results.length != 0) {
return res.status(400).send("Username already exists."); return res.status(400).send("Email address already used.");
} }
return userDB.sequelize.query("INSERT INTO users " + return userDB.sequelize.query("INSERT INTO users " +
"(uid,displayName,password,mail,memberSince,authenticated) " + "(uid,displayName,password,mail,memberSince,authenticated,notes) " +
"VALUES(:username,:name,:password,:mail,CURRENT_TIMESTAMP,0)", { "VALUES(:username,:name,:password,:mail,CURRENT_TIMESTAMP,0,:notes)", {
replacements: { replacements: {
username: username, username: mail,
name: name, name: name,
password: crypto.createHash('sha256').update(password).digest('base64'), password: crypto.createHash('sha256').update(password).digest('base64'),
mail: mail mail: mail,
notes: who
} }
}).then(function(results) { }).then(function(results) {
/* /*

View File

@ -7,8 +7,6 @@ const Promise = require("bluebird"),
crypto = require("crypto"); crypto = require("crypto");
let scanning = 0;
let photoDB = null; let photoDB = null;
const picturesPath = config.get("picturesPath").replace(/\/$/, "") + "/"; const picturesPath = config.get("picturesPath").replace(/\/$/, "") + "/";
@ -39,9 +37,6 @@ function removeNewerFile(path, fileA, fileB) {
}); });
} }
const startStamp = Date.now();
let processRunning = false; let processRunning = false;
const { spawn } = require('child_process'); const { spawn } = require('child_process');
@ -185,7 +180,6 @@ function moveCorrupt(path, file) {
}); });
} }
/*******************************************************************************************************/
function processBlock(items) { function processBlock(items) {
if (items) { if (items) {
@ -207,10 +201,19 @@ function processBlock(items) {
return a.stats.mtime - b.stats.mtime; return a.stats.mtime - b.stats.mtime;
}); });
let toProcess = processing.length, lastMessage = moment();
return Promise.map(processing, function(asset) { return Promise.map(processing, function(asset) {
return computeHash(picturesPath + asset.album.path + asset.filename).then(function(hash) { return computeHash(picturesPath + asset.album.path + asset.filename).then(function(hash) {
asset.hash = hash; asset.hash = hash;
}).then(function() {
toProcess--;
if (moment().add(-5, 'seconds') > lastMessage) {
console.log("Hash items to be processed: " + toProcess);
lastMessage = moment();
}
}); });
}, {
concurrency: 5
}).then(function() { }).then(function() {
let toProcess = processing.length, lastMessage = moment(); let toProcess = processing.length, lastMessage = moment();
/* Needs to be one at a time in case there are multiple HASH collisions */ /* Needs to be one at a time in case there are multiple HASH collisions */
@ -248,7 +251,7 @@ function processBlock(items) {
}).then(function() { }).then(function() {
toProcess--; toProcess--;
if (moment().add(-5, 'seconds') > lastMessage) { if (moment().add(-5, 'seconds') > lastMessage) {
console.log("Hash items to be processed: " + toProcess); console.log("Hash items to be checked: " + toProcess);
lastMessage = moment(); lastMessage = moment();
} }
}); });
@ -526,7 +529,10 @@ function scanDir(parent, path) {
assets.push({ assets.push({
filename: file.replace(rawExtension, ".jpg"), /* We will be converting from NEF/ORF => JPG */ filename: file.replace(rawExtension, ".jpg"), /* We will be converting from NEF/ORF => JPG */
name: file.replace(/.[^.]*$/, ""), name: file.replace(/.[^.]*$/, ""),
stats: stats, stats: {
ctime: stats.ctime,
mtime: stats.mtime
},
album: album album: album
}); });
}); });
@ -611,25 +617,23 @@ function findOrUpdateDBAsset(asset) {
function computeHash(filepath) { function computeHash(filepath) {
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
try { let input = fs.createReadStream(filepath),
const input = fs.createReadStream(filepath), hash = crypto.createHash("sha256");
hash = crypto.createHash("sha256"); if (!input) {
if (!input) { return reject()
return reject()
}
input.on("readable", function() {
const data = input.read();
if (data) {
hash.update(data);
} else {
resolve(hash.digest("hex"));
}
});
} catch(error) {
console.error("Unable to create hash: " + error);
return reject(error);
} }
input.on("readable", function() {
const data = input.read();
if (data) {
hash.update(data);
} else {
input.close();
resolve(hash.digest("hex"));
hash = null;
input = null;
}
});
}); });
} }
@ -653,7 +657,7 @@ module.exports = {
*/ */
let initialized = Date.now(); let initialized = Date.now();
let now = Date.now(); let now = Date.now();
const needsProcessing = []; let needsProcessing = [];
lastScan = new Date(); lastScan = new Date();
return scanDir(null, picturesPath).spread(function(albums, assets) { return scanDir(null, picturesPath).spread(function(albums, assets) {
@ -709,14 +713,17 @@ module.exports = {
} }
}).then(function() { }).then(function() {
console.log("Updated scan date of " + updateScanned.length + " assets"); console.log("Updated scan date of " + updateScanned.length + " assets");
updateScanned = [];
}); });
} }
}).then(function() { }).then(function() {
console.log(needsProcessing.length + " assets need HASH computed"); console.log(needsProcessing.length + " assets need HASH computed");
processBlock(needsProcessing); processBlock(needsProcessing);
needsProcessing = [];
}).then(function() { }).then(function() {
console.log("Scanned " + assets.length + " asset DB entries in " + console.log("Scanned " + assets.length + " asset DB entries in " +
((Date.now() - now) / 1000) + "s"); ((Date.now() - now) / 1000) + "s");
assets = [];
}); });
}); });
}).then(function() { }).then(function() {