aboutsummaryrefslogtreecommitdiff
path: root/src/api/routes/albums/albumGET.js
diff options
context:
space:
mode:
authorPitu <[email protected]>2021-01-04 01:04:20 +0900
committerPitu <[email protected]>2021-01-04 01:04:20 +0900
commitfcd39dc550dec8dbcb8325e07e938c5024cbc33d (patch)
treef41acb4e0d5fd3c3b1236fe4324b3fef9ec6eafe /src/api/routes/albums/albumGET.js
parentCreate FUNDING.yml (diff)
parentchore: update todo (diff)
downloadhost.fuwn.me-fcd39dc550dec8dbcb8325e07e938c5024cbc33d.tar.xz
host.fuwn.me-fcd39dc550dec8dbcb8325e07e938c5024cbc33d.zip
Merge branch 'dev'
Diffstat (limited to 'src/api/routes/albums/albumGET.js')
-rw-r--r--src/api/routes/albums/albumGET.js46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/api/routes/albums/albumGET.js b/src/api/routes/albums/albumGET.js
new file mode 100644
index 0000000..c9f6763
--- /dev/null
+++ b/src/api/routes/albums/albumGET.js
@@ -0,0 +1,46 @@
+const Route = require('../../structures/Route');
+const Util = require('../../utils/Util');
+
+class albumGET extends Route {
+ constructor() {
+ super('/album/:identifier', 'get', { bypassAuth: true });
+ }
+
+ async run(req, res, db) {
+ const { identifier } = req.params;
+ if (!identifier) return res.status(400).json({ message: 'Invalid identifier supplied' });
+
+ // Make sure it exists and it's enabled
+ const link = await db.table('links').where({ identifier, enabled: true }).first();
+ if (!link) return res.status(404).json({ message: 'The album 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(404).json({ message: 'Album not found' });
+
+ const files = await db.table('albumsFiles')
+ .where({ albumId: link.albumId })
+ .join('files', 'albumsFiles.fileId', 'files.id')
+ .select('files.name', 'files.id')
+ .orderBy('files.id', 'desc');
+
+ // Create the links for each file
+ // eslint-disable-next-line no-restricted-syntax
+ 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,
+ downloadEnabled: link.enableDownload,
+ isNsfw: album.nsfw,
+ files
+ });
+ }
+}
+
+module.exports = albumGET;