diff options
| author | Pitu <[email protected]> | 2018-09-17 04:55:42 -0300 |
|---|---|---|
| committer | Pitu <[email protected]> | 2018-09-17 04:55:42 -0300 |
| commit | f2c885b718528d42df412e612520fb471c46d0bd (patch) | |
| tree | 8841d063055b6a3ce9abdbd1e3482d8557996f4f /src/api/routes/albums/albumGET.js | |
| parent | Changes (diff) | |
| download | host.fuwn.me-f2c885b718528d42df412e612520fb471c46d0bd.tar.xz host.fuwn.me-f2c885b718528d42df412e612520fb471c46d0bd.zip | |
Commented all the code
Diffstat (limited to 'src/api/routes/albums/albumGET.js')
| -rw-r--r-- | src/api/routes/albums/albumGET.js | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/src/api/routes/albums/albumGET.js b/src/api/routes/albums/albumGET.js index 655db13..b63811c 100644 --- a/src/api/routes/albums/albumGET.js +++ b/src/api/routes/albums/albumGET.js @@ -12,25 +12,40 @@ class albumGET extends Route { const { identifier } = req.params; if (!identifier) return res.status(400).json({ message: 'Invalid identifier supplied' }); - const link = await db.table('links').where({ - identifier, - enabled: true - }).first(); + /* + Make sure it exists and it's enabled + */ + 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(); if (!album) return res.status(400).json({ message: 'Album not found' }); - const fileList = await db.table('albumsFiles').where('albumId', link.albumId); + /* + 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 fileIds = fileList.map(el => el.fileId); const files = await db.table('files') .whereIn('id', fileIds) .orderBy('id', 'desc') .select('name'); + /* + Create the links for each file + */ for (let file of files) { file = Util.constructFilePublicLink(file); } + + /* + Add 1 more view to the link + */ + await db.table('links').where({ identifier }).update('views', Number(link.views) + 1); + return res.json({ message: 'Successfully retrieved files', name: album.name, |