aboutsummaryrefslogtreecommitdiff
path: root/src/api/routes/albums/albumGET.js
diff options
context:
space:
mode:
authorPitu <[email protected]>2018-09-16 00:56:13 -0300
committerPitu <[email protected]>2018-09-16 00:56:13 -0300
commite7767ac7095f93393a627fd5e867af4a1ca4b011 (patch)
treec571d5a13ac949bc8c826a27772b78992b320d58 /src/api/routes/albums/albumGET.js
parentUtils (diff)
downloadhost.fuwn.me-e7767ac7095f93393a627fd5e867af4a1ca4b011.tar.xz
host.fuwn.me-e7767ac7095f93393a627fd5e867af4a1ca4b011.zip
Routes
Diffstat (limited to 'src/api/routes/albums/albumGET.js')
-rw-r--r--src/api/routes/albums/albumGET.js52
1 files changed, 52 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..80affd2
--- /dev/null
+++ b/src/api/routes/albums/albumGET.js
@@ -0,0 +1,52 @@
+const Route = require('../../structures/Route');
+const config = require('../../../../config');
+const db = require('knex')(config.server.database);
+
+class albumGET extends Route {
+ constructor() {
+ super('/album/:identifier', 'get', { bypassAuth: true });
+ }
+
+ async run(req, res) {
+ 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();
+ if (!link) return res.status(400).json({ message: 'The identifier supplied could not be found' });
+
+ 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);
+ const fileIds = fileList.filter(el => el.file.fileId);
+ const files = await db.table('files')
+ .where('id', fileIds)
+ .select('name');
+
+ return res.json({
+ message: 'Successfully retrieved files',
+ files
+ });
+ }
+}
+
+class albumsDropdownGET extends Route {
+ constructor() {
+ super('/albums/:identifier', 'get');
+ }
+
+ async run(req, res, user) {
+ const albums = await db.table('albums')
+ .where('userId', user.id)
+ .select('id', 'name');
+ return res.json({
+ message: 'Successfully retrieved albums',
+ albums
+ });
+ }
+}
+
+module.exports = [albumGET, albumsDropdownGET];