aboutsummaryrefslogtreecommitdiff
path: root/src/api/utils/Util.js
diff options
context:
space:
mode:
authorZephyrrus <[email protected]>2020-07-08 02:32:12 +0300
committerZephyrrus <[email protected]>2020-07-08 02:32:12 +0300
commiteccbb1ca93f1b86e9bc93dcbc1ec0ee9b168d949 (patch)
treedf24e25d570213cc0e10822cc74dc444bc55243b /src/api/utils/Util.js
parentfeat: refactor waterfall to be more efficient (diff)
downloadhost.fuwn.me-eccbb1ca93f1b86e9bc93dcbc1ec0ee9b168d949.tar.xz
host.fuwn.me-eccbb1ca93f1b86e9bc93dcbc1ec0ee9b168d949.zip
fix: errors in Util caused by separating into different classes improperly
Diffstat (limited to 'src/api/utils/Util.js')
-rw-r--r--src/api/utils/Util.js24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/api/utils/Util.js b/src/api/utils/Util.js
index 496ea18..ab59c95 100644
--- a/src/api/utils/Util.js
+++ b/src/api/utils/Util.js
@@ -1,3 +1,4 @@
+/* eslint-disable no-await-in-loop */
const jetpack = require('fs-jetpack');
const randomstring = require('randomstring');
const path = require('path');
@@ -9,9 +10,9 @@ const db = require('knex')({
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_DATABASE,
- filename: path.join(__dirname, '..', '..', '..', 'database.sqlite')
+ filename: path.join(__dirname, '../../../database.sqlite'),
},
- useNullAsDefault: process.env.DB_CLIENT === 'sqlite' ? true : false
+ useNullAsDefault: process.env.DB_CLIENT === 'sqlite',
});
const moment = require('moment');
const crypto = require('crypto');
@@ -51,11 +52,10 @@ class Util {
static getUniqueFilename(name) {
const retry = (i = 0) => {
- const filename =
- randomstring.generate({
- length: parseInt(process.env.GENERATED_FILENAME_LENGTH, 10),
- capitalization: 'lowercase'
- }) + path.extname(name).toLowerCase();
+ const filename = randomstring.generate({
+ length: parseInt(process.env.GENERATED_FILENAME_LENGTH, 10),
+ capitalization: 'lowercase',
+ }) + path.extname(name).toLowerCase();
// TODO: Change this to look for the file in the db instead of in the filesystem
const exists = jetpack.exists(path.join(Util.uploadPath, filename));
@@ -71,7 +71,7 @@ class Util {
const retry = async (i = 0) => {
const identifier = randomstring.generate({
length: parseInt(process.env.GENERATED_ALBUM_LENGTH, 10),
- capitalization: 'lowercase'
+ capitalization: 'lowercase',
});
const exists = await db
.table('links')
@@ -138,7 +138,9 @@ class Util {
.table('files')
.where({ id: fileAlbum.fileId })
.first();
+
if (!file) continue;
+
await this.deleteFile(file.name, true);
}
} catch (error) {
@@ -211,13 +213,15 @@ class Util {
'..',
process.env.UPLOAD_FOLDER,
'zips',
- `${album.userId}-${album.id}.zip`
- )
+ `${album.userId}-${album.id}.zip`,
+ ),
);
} catch (error) {
log.error(error);
}
}
+
+ static generateThumbnails = ThumbUtil.generateThumbnails;
}
module.exports = Util;