Added placeholder for utils/check
This commit is contained in:
parent
77332428e6
commit
d0ffda22b6
@ -22,10 +22,6 @@ require("./console-line.js"); /* Monkey-patch console.log with line numbers */
|
||||
const picturesPath = config.get("picturesPath").replace(/\/$/, ""),
|
||||
serverConfig = config.get("server");
|
||||
|
||||
config.get("admin.mail");
|
||||
config.get("smtp.host");
|
||||
config.get("smtp.sender");
|
||||
|
||||
let basePath = config.get("basePath");
|
||||
|
||||
let photoDB = null, userDB = null;
|
||||
@ -102,11 +98,17 @@ app.use(session({
|
||||
|
||||
const index = require("./routes/index");
|
||||
|
||||
const transporter = require("nodemailer").createTransport({
|
||||
host: config.get("smtp.host"),
|
||||
pool: true,
|
||||
port: config.has("smtp.port") ? config.get("smtp.port") : 25
|
||||
});
|
||||
if (config.has("admin.mail") &&
|
||||
config.has("smtp.host") &&
|
||||
config.has("smtp.sender")) {
|
||||
app.set("transporter", require("nodemailer").createTransport({
|
||||
host: config.get("smtp.host"),
|
||||
pool: true,
|
||||
port: config.has("smtp.port") ? config.get("smtp.port") : 25
|
||||
}));
|
||||
} else {
|
||||
console.log("SMTP disabled. To enable SMTP, configure admin.mail, smtp.host, and smtp.sender");
|
||||
}
|
||||
|
||||
const templates = {
|
||||
"html": [
|
||||
@ -176,6 +178,11 @@ app.use(basePath, function(req, res, next) {
|
||||
throw "DB mis-match between authentications and users table";
|
||||
}
|
||||
|
||||
if (!app.get("transporter")) {
|
||||
console.log("Not sending VERIFIED email; SMTP not configured.");
|
||||
return;
|
||||
}
|
||||
|
||||
let user = results[0],
|
||||
envelope = {
|
||||
to: config.get("admin.mail"),
|
||||
|
@ -11,12 +11,6 @@ const router = express.Router();
|
||||
|
||||
let userDB;
|
||||
|
||||
let transporter = createTransport({
|
||||
host: config.get("smtp.host"),
|
||||
pool: true,
|
||||
port: config.has("smtp.port") ? config.get("smtp.port") : 25
|
||||
});
|
||||
|
||||
let ldap;
|
||||
if (config.has("ldap.url")) {
|
||||
ldap = new LdapAuth(config.get("ldap"));
|
||||
@ -145,6 +139,12 @@ router.post("/create", function(req, res) {
|
||||
throw error;
|
||||
});
|
||||
}).then(function() {
|
||||
const transporter = app.get("transporter");
|
||||
if (!transporter) {
|
||||
console.log("Not sending VERIFY email; SMTP not configured.");
|
||||
return;
|
||||
}
|
||||
|
||||
let data = {
|
||||
username: name,
|
||||
mail: mail,
|
||||
|
78
util/check.js
Normal file
78
util/check.js
Normal file
@ -0,0 +1,78 @@
|
||||
"use strict";
|
||||
|
||||
const fs = require("fs"),
|
||||
Promise = require("bluebird"),
|
||||
config = require("config");
|
||||
|
||||
if (process.argv.length <= 2) {
|
||||
console.log("usage: node check file|id [file|id] ... ");
|
||||
process.exit(-1);
|
||||
}
|
||||
const items = process.argv.splice(2);
|
||||
|
||||
const picturesPath = config.get("picturesPath").replace(/\/$/, "");
|
||||
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
if (parseInt(items[i]) == items[i]) {
|
||||
items[i] = {
|
||||
type: "id",
|
||||
value: items[i]
|
||||
};
|
||||
} else {
|
||||
items[i] = {
|
||||
type: "file",
|
||||
value: items[i]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const exists = function(path) {
|
||||
return stat(path).then(function() {
|
||||
return true;
|
||||
}).catch(function() {
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
const stat = function (_path) {
|
||||
if (_path.indexOf(picturesPath.replace(/\/$/, "")) == 0) {
|
||||
_path = _path.substring(picturesPath.length);
|
||||
}
|
||||
|
||||
let path = picturesPath + _path;
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
fs.stat(path, function (error, stats) {
|
||||
if (error) {
|
||||
return reject(error);
|
||||
}
|
||||
return resolve(stats);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
require("../server/db/photos").then(function(db) {
|
||||
const photoDB = db;
|
||||
return Promise.mapSeries(items, function(item) {
|
||||
switch (item.type) {
|
||||
case "file":
|
||||
return exists(item.value).then(function(exists) {
|
||||
console.log("File '" + item.value + "' " + (exists ? "exists" : "does not exist."));
|
||||
});
|
||||
case "id":
|
||||
return photoDB.sequelize.query("SELECT * FROM photos WHERE id=:id", {
|
||||
replacements: {
|
||||
id: item.value
|
||||
},
|
||||
type: photoDB.Sequelize.QueryTypes.SELECT,
|
||||
raw: true
|
||||
}).then(function(photos) {
|
||||
if (photos.length == 0) {
|
||||
console.log("Item " + item.value + " does not exist.");
|
||||
} else {
|
||||
console.log("Item " + item.value + " exists:", photos[0]);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user