Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
app.post('/very-secure-manifest-convert', upload.single('pdf'), async (req, res) => {
const {file:pdf} = req;
// logging
log(req, {file:pdf.path});
// hash check for duplicate files
const hash = await hasha.fromFile(pdf.path);
const viewUrl = `${req.protocol}://${req.get('host')}/uploads/${pdf.filename}.html`;
console.log({hash});
if ( State.Files.has(hash) ) {
const existingViewUrl = State.Files.get(hash);
log(req, {note:'File exists', hash, existingViewUrl});
return res.end(existingViewUrl);
} else {
newFiles += 1;
State.Files.set(hash, viewUrl);
if ( newFiles % WAIT_NEW_FILES_BEFORE_DISK_SYNC == 0 ) {
syncHashes(State.Files);
}
}
// job start
const subshell = spawn(CONVERTER, [pdf.path, uploadPath]);
async isFileDownloaded(path, sha1) {
try {
const hash = await hasha.fromFile(path, {algorithm: 'sha1'});
return hash === sha1;
}
catch (e) {
return false;
}
}
async function hash_file(filename, algo='sha256') {
const hasha = require('hasha');
return await hasha.fromFile(filename, { algorithm: algo }).then(hash => {
return Promise.resolve(hash);
});
}
async function hash_file(filename, algo) {
const hasha = require('hasha');
var hash = await hasha.fromFile(filename, { algorithm: algo });
return hash;
}
};
}
if (options.reverse) album.reverse = true;
if (options.title) album.title = options.title;
if (options.desc) album.description = options.desc;
if (options.font) album.font = options.font;
/*
* Read directory in ./uploads and get checksums of .jpg
*/
let checksums = [];
for (let file of (await fs.readdir(folders.upload))) {
if (path.extname(file) === '.jpg') {
try {
let hash = await hasha.fromFile(path.join(folders.upload, file), {algorithm: 'md5'});
checksums.push([file, hash]);
} catch (e) {
checksums.push([file, false]);
}
}
}
let i = 0;
for (let checksum of checksums) {
i++;
let file = checksum[0];
let hash = checksum[1];
if (album.pictures[i - 1] && hash !== false && album.pictures[i - 1].hash === hash) {
/*
* Skip existing files with same checksum
const fileHash = file => {
return hasha.fromFile(file, {
algorithm: 'sha1',
});
};
SHA256(filename) {
return hasha.fromFile(filename, {algorithm: 'sha256'});
}
}