fixed not using the `diskFilePath` variable

pull/20/head
tycrek 3 years ago
parent 5386406d94
commit 89da459d72
No known key found for this signature in database
GPG Key ID: 25D74F3943625263

@ -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);

@ -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)

@ -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) {

@ -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,

@ -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)));

Loading…
Cancel
Save