aboutsummaryrefslogtreecommitdiff
path: root/src/api
diff options
context:
space:
mode:
authorPitu <[email protected]>2019-03-12 06:03:15 +0000
committerPitu <[email protected]>2019-03-12 06:03:15 +0000
commit00058e9915a09f5abcd8d130a144f5c68d10428a (patch)
treeac17abcda7731243bf4851d9e0de3ac87368699f /src/api
parentPrevent snowflakes from demoting/disabling themselves (diff)
downloadhost.fuwn.me-00058e9915a09f5abcd8d130a144f5c68d10428a.tar.xz
host.fuwn.me-00058e9915a09f5abcd8d130a144f5c68d10428a.zip
stuff
Diffstat (limited to 'src/api')
-rw-r--r--src/api/routes/albums/albumDELETE.js2
-rw-r--r--src/api/routes/albums/albumZipGET.js18
2 files changed, 14 insertions, 6 deletions
diff --git a/src/api/routes/albums/albumDELETE.js b/src/api/routes/albums/albumDELETE.js
index 23dcf40..adaa02f 100644
--- a/src/api/routes/albums/albumDELETE.js
+++ b/src/api/routes/albums/albumDELETE.js
@@ -12,7 +12,7 @@ class albumDELETE extends Route {
if (!id) return res.status(400).json({ message: 'Invalid album ID supplied' });
/*
- Check fi the album exists
+ Check if the album exists
*/
const album = await db.table('albums').where({ id, userId: user.id }).first();
if (!album) return res.status(400).json({ message: 'The file doesn\'t exist or doesn\'t belong to the user' });
diff --git a/src/api/routes/albums/albumZipGET.js b/src/api/routes/albums/albumZipGET.js
index 9419654..b2c9fa7 100644
--- a/src/api/routes/albums/albumZipGET.js
+++ b/src/api/routes/albums/albumZipGET.js
@@ -16,13 +16,17 @@ class albumGET extends Route {
/*
Make sure it exists and it's enabled
*/
- const link = await db.table('links').where({ identifier, enabled: true }).first();
+ const link = await db.table('links')
+ .where({ identifier, enabled: true })
+ .first();
if (!link) return res.status(400).json({ message: 'The identifier supplied could not be found' });
/*
Same with the album, just to make sure is not a deleted album and a leftover link
*/
- const album = await db.table('albums').where('id', link.albumId).first();
+ const album = await db.table('albums')
+ .where('id', link.albumId)
+ .first();
if (!album) return res.status(400).json({ message: 'Album not found' });
/*
@@ -43,12 +47,14 @@ class albumGET extends Route {
/*
Grab the files in a very unoptimized way. (This should be a join between both tables)
*/
- const fileList = await db.table('albumsFiles').where('albumId', link.albumId).select('fileId');
+ const fileList = await db.table('albumsFiles')
+ .where('albumId', link.albumId)
+ .select('fileId');
/*
If there are no files, stop here
*/
- if (!fileList) return res.status(400).json({ message: 'Can\'t download an empty album' });
+ if (!fileList || !fileList.length) return res.status(400).json({ message: 'Can\'t download an empty album' });
/*
Get the actual files
@@ -61,7 +67,9 @@ class albumGET extends Route {
try {
Util.createZip(filesToZip, album);
- await db.table('albums').where('id', link.albumId).update('zippedAt', db.fn.now());
+ await db.table('albums')
+ .where('id', link.albumId)
+ .update('zippedAt', db.fn.now());
const filePath = path.join(__dirname, '..', '..', '..', '..', process.env.UPLOAD_FOLDER, 'zips', `${album.userId}-${album.id}.zip`);
const fileName = `lolisafe-${identifier}.zip`;