aboutsummaryrefslogtreecommitdiff
path: root/src/api
diff options
context:
space:
mode:
authorZephyrrus <[email protected]>2020-07-19 22:27:11 +0300
committerZephyrrus <[email protected]>2020-07-19 22:27:11 +0300
commitc93ddb09008c45942544b13bbb03319c367f9cd8 (patch)
tree7f6e334b8d33b42574dc19a256a944fadbaa7f66 /src/api
parentchore: add custom class to inputs until fix is released on buefy's master (diff)
downloadhost.fuwn.me-c93ddb09008c45942544b13bbb03319c367f9cd8.tar.xz
host.fuwn.me-c93ddb09008c45942544b13bbb03319c367f9cd8.zip
feat: Start working on a new album/tags/image info modal
Diffstat (limited to 'src/api')
-rw-r--r--src/api/routes/admin/fileGET.js2
-rw-r--r--src/api/routes/files/fileGET.js46
2 files changed, 47 insertions, 1 deletions
diff --git a/src/api/routes/admin/fileGET.js b/src/api/routes/admin/fileGET.js
index 239b128..7e40659 100644
--- a/src/api/routes/admin/fileGET.js
+++ b/src/api/routes/admin/fileGET.js
@@ -3,7 +3,7 @@ const Util = require('../../utils/Util');
class filesGET extends Route {
constructor() {
- super('/file/:id', 'get', { adminOnly: true });
+ super('/admin/file/:id', 'get', { adminOnly: true });
}
async run(req, res, db) {
diff --git a/src/api/routes/files/fileGET.js b/src/api/routes/files/fileGET.js
new file mode 100644
index 0000000..e9ce90e
--- /dev/null
+++ b/src/api/routes/files/fileGET.js
@@ -0,0 +1,46 @@
+const Route = require('../../structures/Route');
+const Util = require('../../utils/Util');
+
+class fileGET extends Route {
+ constructor() {
+ super('/file/:id', 'get');
+ }
+
+ async run(req, res, db, user) {
+ const { id } = req.params;
+ if (!id) return res.status(400).json({ message: 'Invalid file ID supplied' });
+
+ /*
+ Make sure the file exists
+ */
+ let file = await db.table('files').where({ id, userId: user.id }).first();
+ if (!file) return res.status(400).json({ message: 'The file doesn\'t exist or doesn\'t belong to the user' });
+
+ file = Util.constructFilePublicLink(file);
+
+ /*
+ Fetch the albums
+ */
+ const albums = await db.table('albumsFiles')
+ .where('fileId', id)
+ .join('albums', 'albums.id', 'albumsFiles.albumId')
+ .select('albums.id', 'albums.name');
+
+ /*
+ Fetch the tags
+ */
+ const tags = await db.table('fileTags')
+ .where('fileId', id)
+ .join('tags', 'tags.id', 'fileTags.id')
+ .select('tags.id', 'tags.uuid', 'tags.name');
+
+ return res.json({
+ message: 'Successfully retrieved file',
+ file,
+ albums,
+ tags,
+ });
+ }
+}
+
+module.exports = fileGET;