aboutsummaryrefslogtreecommitdiff
path: root/src/api/routes/admin/fileGET.js
diff options
context:
space:
mode:
authorPitu <[email protected]>2020-05-11 00:19:10 +0900
committerPitu <[email protected]>2020-05-11 00:19:10 +0900
commitb886fda0793b8a26de58cd462acf6676a0a8e7ed (patch)
tree07fcc32486b7654bf3ba173cef4061dc7cb6f12e /src/api/routes/admin/fileGET.js
parentfix: remove uuid from user registration (diff)
downloadhost.fuwn.me-b886fda0793b8a26de58cd462acf6676a0a8e7ed.tar.xz
host.fuwn.me-b886fda0793b8a26de58cd462acf6676a0a8e7ed.zip
chore: cleanup and todo
Diffstat (limited to 'src/api/routes/admin/fileGET.js')
-rw-r--r--src/api/routes/admin/fileGET.js29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/api/routes/admin/fileGET.js b/src/api/routes/admin/fileGET.js
new file mode 100644
index 0000000..3bb8da4
--- /dev/null
+++ b/src/api/routes/admin/fileGET.js
@@ -0,0 +1,29 @@
+const Route = require('../../structures/Route');
+const Util = require('../../utils/Util');
+
+class filesGET extends Route {
+ constructor() {
+ super('/file/:id', 'get', { adminOnly: true });
+ }
+
+ async run(req, res, db) {
+ const { id } = req.params;
+ if (!id) return res.status(400).json({ message: 'Invalid file ID supplied' });
+
+ let file = await db.table('files').where({ id }).first();
+ const user = await db.table('users').where({ id: file.userId }).first();
+ file = Util.constructFilePublicLink(file);
+
+ // Additional relevant data
+ const filesFromUser = await db.table('files').where({ userId: user.id }).select('id');
+ user.fileCount = filesFromUser.length;
+
+ return res.json({
+ message: 'Successfully retrieved file',
+ file,
+ user
+ });
+ }
+}
+
+module.exports = filesGET;