From 89da459d72e51dfd6ec231cd650719129cbf2194 Mon Sep 17 00:00:00 2001 From: tycrek Date: Sun, 20 Jun 2021 20:35:11 -0600 Subject: [PATCH] fixed not using the `diskFilePath` variable --- ass.js | 10 +++++----- hash.js | 4 ++-- thumbnails.js | 6 +++--- utils.js | 4 ++-- vibrant.js | 4 ++-- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/ass.js b/ass.js index 49d7c48..78db917 100755 --- a/ass.js +++ b/ass.js @@ -7,7 +7,7 @@ try { } // Load the config -const { host, port, resourceIdSize, gfyIdSize, resourceIdType, isProxied, s3enabled, saveAsOriginal } = require('./config.json'); +const { host, port, resourceIdSize, diskFilePath, gfyIdSize, resourceIdType, isProxied, s3enabled, saveAsOriginal } = require('./config.json'); //#region Imports const fs = require('fs-extra'); @@ -63,7 +63,7 @@ function preStartup() { .catch(console.error)); // Create thumbnails directory - fs.ensureDirSync(path('uploads/thumbnails')); + fs.ensureDirSync(path(diskFilePath, 'thumbnails')); } function startup() { @@ -120,7 +120,7 @@ function startup() { )) // Remove the temp file if using S3 storage, otherwise rename the local file - .then(() => (s3enabled ? fs.remove(path('uploads/', req.file.originalname)) : renameFile(req, saveAsOriginal ? req.file.originalname : req.file.sha1))) + .then(() => (s3enabled ? fs.remove(path(diskFilePath, req.file.originalname)) : renameFile(req, saveAsOriginal ? req.file.originalname : req.file.sha1))) .then(() => next()) .catch((err) => next(err)); }); @@ -247,7 +247,7 @@ function startup() { const { resourceId } = req.ass; // Read the file and send it to the client - fs.readFile(path('uploads/thumbnails/', data[resourceId].thumbnail)) + fs.readFile(path(diskFilePath, 'thumbnails/', data[resourceId].thumbnail)) .then((fileData) => res.type('jpg').send(fileData)) .catch(console.error); }); @@ -285,7 +285,7 @@ function startup() { log(`Deleted: ${fileData.originalname} (${fileData.mimetype})`); // Save the file information - Promise.all([s3enabled ? deleteS3(fileData) : fs.rmSync(path(fileData.path)), fs.rmSync(path('uploads/thumbnails/', fileData.thumbnail))]) + Promise.all([s3enabled ? deleteS3(fileData) : fs.rmSync(path(fileData.path)), fs.rmSync(path(diskFilePath, 'thumbnails/', fileData.thumbnail))]) .then(() => { delete data[resourceId]; saveData(data); diff --git a/hash.js b/hash.js index 1138fee..efc8ded 100644 --- a/hash.js +++ b/hash.js @@ -2,11 +2,11 @@ const fs = require('fs-extra'); const crypto = require('crypto'); const toArray = require('stream-to-array') const { path } = require('./utils'); -const { s3enabled } = require('./config.json'); +const { s3enabled, diskFilePath } = require('./config.json'); module.exports = (file) => new Promise((resolve, reject) => - toArray((fs.createReadStream(s3enabled ? path('uploads/', file.originalname) : path(file.path)))) + toArray((fs.createReadStream(s3enabled ? path(diskFilePath, file.originalname) : path(file.path)))) .then((parts) => Buffer.concat(parts.map((part) => (Buffer.isBuffer(part) ? part : Buffer.from(part))))) .then((buf) => crypto.createHash('sha1').update(buf).digest('hex')) .then(resolve) diff --git a/thumbnails.js b/thumbnails.js index b51b002..553bced 100644 --- a/thumbnails.js +++ b/thumbnails.js @@ -3,7 +3,7 @@ const Jimp = require('jimp'); const shell = require('any-shell-escape'); const { exec } = require('child_process'); const { path, getS3url } = require('./utils'); -const { s3enabled } = require('./config.json'); +const { s3enabled, diskFilePath } = require('./config.json'); const THUMBNAIL_QUALITY = 50; const THUMBNAIL_SIZE = 512; @@ -24,11 +24,11 @@ function getNewName(oldName) { } function getNewNamePath(oldName) { - return path('uploads/thumbnails/', getNewName(oldName)); + return path(diskFilePath, 'thumbnails/', getNewName(oldName)); } function getVideoThumbnail(file) { - return new Promise((resolve, reject) => exec(getCommand((s3enabled ? path('uploads/', file.originalname) : path(file.path)), getNewNamePath(file.originalname)), (err) => (err ? reject(err) : resolve()))); + return new Promise((resolve, reject) => exec(getCommand((s3enabled ? path(diskFilePath, file.originalname) : path(file.path)), getNewNamePath(file.originalname)), (err) => (err ? reject(err) : resolve()))); } function getResizedThumbnail(file) { diff --git a/utils.js b/utils.js index 617e9a1..54bdd91 100755 --- a/utils.js +++ b/utils.js @@ -6,7 +6,7 @@ const token = require('./generators/token'); const zwsGen = require('./generators/zws'); const randomGen = require('./generators/random'); const gfyGen = require('./generators/gfycat'); -const { useSsl, port, domain, isProxied, s3bucket, s3endpoint } = require('./config.json'); +const { useSsl, port, domain, isProxied, diskFilePath, s3bucket, s3endpoint } = require('./config.json'); const { HTTP, HTTPS, KILOBYTES } = require('./MagicNumbers.json'); const path = (...paths) => Path.join(__dirname, ...paths); @@ -66,7 +66,7 @@ module.exports = { arrayEquals: (arr1, arr2) => arr1.length === arr2.length && arr1.slice().sort().every((value, index) => value === arr2.slice().sort()[index]), downloadTempS3: (file) => new Promise((resolve, reject) => fetch(getS3url(file.randomId, file.mimetype)) - .then((f2) => f2.body.pipe(fs.createWriteStream(Path.join(__dirname, 'uploads/', sanitize(file.originalname))).on('close', () => resolve()))) + .then((f2) => f2.body.pipe(fs.createWriteStream(Path.join(__dirname, diskFilePath, sanitize(file.originalname))).on('close', () => resolve()))) .catch(reject)), getS3url, getSafeExt, diff --git a/vibrant.js b/vibrant.js index ba9d3fc..9d4ee45 100644 --- a/vibrant.js +++ b/vibrant.js @@ -1,6 +1,6 @@ const Vibrant = require('node-vibrant'); const { path, randomHexColour } = require('./utils'); -const { s3enabled } = require('./config.json'); +const { s3enabled, diskFilePath } = require('./config.json'); const COLOR_COUNT = 256; const QUALITY = 3; @@ -9,7 +9,7 @@ module.exports = (file) => new Promise((resolve, reject) => ( file.mimetype.includes('video') ? resolve(randomHexColour()) - : Vibrant.from(s3enabled ? path('uploads/', file.originalname) : path(file.path)) + : Vibrant.from(s3enabled ? path(diskFilePath, file.originalname) : path(file.path)) .maxColorCount(COLOR_COUNT).quality(QUALITY).getPalette() .then((palettes) => resolve(palettes[Object.keys(palettes).sort((a, b) => palettes[b].population - palettes[a].population)[0]].hex)) .catch(reject)));