aboutsummaryrefslogtreecommitdiff
path: root/src/api/routes/files
diff options
context:
space:
mode:
Diffstat (limited to 'src/api/routes/files')
-rw-r--r--src/api/routes/files/fileDELETE.js13
-rw-r--r--src/api/routes/files/filesGET.js8
2 files changed, 16 insertions, 5 deletions
diff --git a/src/api/routes/files/fileDELETE.js b/src/api/routes/files/fileDELETE.js
index 2f2a4cf..b50e576 100644
--- a/src/api/routes/files/fileDELETE.js
+++ b/src/api/routes/files/fileDELETE.js
@@ -13,12 +13,15 @@ class fileDELETE extends Route {
const { id } = req.params;
if (!id) return res.status(400).json({ message: 'Invalid file ID supplied' });
- const file = await db.table('files').where({
- id,
- userId: user.id
- }).first();
-
+ /*
+ Make sure the file exists
+ */
+ const 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' });
+
+ /*
+ Delete the file
+ */
try {
await Util.deleteFile(file.name, true);
return res.json({ message: 'The file was deleted successfully' });
diff --git a/src/api/routes/files/filesGET.js b/src/api/routes/files/filesGET.js
index 98cf3aa..d1b6619 100644
--- a/src/api/routes/files/filesGET.js
+++ b/src/api/routes/files/filesGET.js
@@ -9,12 +9,20 @@ class filesGET extends Route {
}
async run(req, res, user) {
+ /*
+ Get all the files from the user
+ */
const files = await db.table('files')
.where('userId', user.id)
.orderBy('id', 'desc');
+
+ /*
+ For each file, create the public link to be able to display the file
+ */
for (let file of files) {
file = Util.constructFilePublicLink(file);
}
+
return res.json({
message: 'Successfully retrieved files',
files