aboutsummaryrefslogtreecommitdiff
path: root/src/api/routes/files/filesGET.js
diff options
context:
space:
mode:
authorKana <[email protected]>2020-12-24 21:41:24 +0900
committerGitHub <[email protected]>2020-12-24 21:41:24 +0900
commit2412a60bd4cb2364a477a3af79a8c6dcb6b0ddab (patch)
treedbf2b2cad342f31849a62089dedd40165758af86 /src/api/routes/files/filesGET.js
parentEnable deleting files with the API key (diff)
parentbug: fix showlist resetting itself every time the page is changed (diff)
downloadhost.fuwn.me-2412a60bd4cb2364a477a3af79a8c6dcb6b0ddab.tar.xz
host.fuwn.me-2412a60bd4cb2364a477a3af79a8c6dcb6b0ddab.zip
Merge pull request #228 from Zephyrrus/begone_trailing_commas
Merge own dev branch into main dev branch
Diffstat (limited to 'src/api/routes/files/filesGET.js')
-rw-r--r--src/api/routes/files/filesGET.js27
1 files changed, 22 insertions, 5 deletions
diff --git a/src/api/routes/files/filesGET.js b/src/api/routes/files/filesGET.js
index f1a3a26..9e90633 100644
--- a/src/api/routes/files/filesGET.js
+++ b/src/api/routes/files/filesGET.js
@@ -7,10 +7,26 @@ class filesGET extends Route {
}
async run(req, res, db, user) {
- // Get all the files from the user
- const files = await db.table('files')
- .where('userId', user.id)
- .orderBy('id', 'desc');
+ let count = 0;
+
+ let files = db.table('files')
+ .where({ userId: user.id })
+ .orderBy('createdAt', 'desc');
+
+ const { page, limit = 100 } = req.query;
+ if (page && page >= 0) {
+ files = await files.offset((page - 1) * limit).limit(limit);
+
+ const dbRes = await db.table('files')
+ .count('* as count')
+ .where({ userId: user.id })
+ .first();
+
+ count = dbRes.count;
+ } else {
+ files = await files; // execute the query
+ count = files.length;
+ }
// For each file, create the public link to be able to display the file
for (let file of files) {
@@ -19,7 +35,8 @@ class filesGET extends Route {
return res.json({
message: 'Successfully retrieved files',
- files
+ files,
+ count
});
}
}