aboutsummaryrefslogtreecommitdiff
path: root/src/api
diff options
context:
space:
mode:
authorPitu <[email protected]>2021-01-20 01:33:35 +0900
committerPitu <[email protected]>2021-01-20 01:33:35 +0900
commit68fd5bd13307e893800028486798334490d8d521 (patch)
treeffb1711f5d17d8f273b85dc9b6faa554619f1dd1 /src/api
parentfeat: add pagination to user files in admin view (diff)
downloadhost.fuwn.me-68fd5bd13307e893800028486798334490d8d521.tar.xz
host.fuwn.me-68fd5bd13307e893800028486798334490d8d521.zip
feat: add pagination to public album links
Diffstat (limited to 'src/api')
-rw-r--r--src/api/routes/albums/albumGET.js26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/api/routes/albums/albumGET.js b/src/api/routes/albums/albumGET.js
index c9f6763..3949fc7 100644
--- a/src/api/routes/albums/albumGET.js
+++ b/src/api/routes/albums/albumGET.js
@@ -18,14 +18,31 @@ class albumGET extends Route {
const album = await db.table('albums').where('id', link.albumId).first();
if (!album) return res.status(404).json({ message: 'Album not found' });
- const files = await db.table('albumsFiles')
+ let count = 0;
+ let files = db.table('albumsFiles')
.where({ albumId: link.albumId })
.join('files', 'albumsFiles.fileId', 'files.id')
.select('files.name', 'files.id')
.orderBy('files.id', 'desc');
- // Create the links for each file
- // eslint-disable-next-line no-restricted-syntax
+ const { page, limit = 100 } = req.query;
+ if (page && page >= 0) {
+ files = await files.offset((page - 1) * limit).limit(limit);
+
+ const dbRes = await db.table('albumsFiles')
+ .where({ albumId: link.albumId })
+ .join('files', 'albumsFiles.fileId', 'files.id')
+ .select('files.name', 'files.id')
+ .orderBy('files.id', 'desc')
+ .count('* as count')
+ .first();
+
+ count = dbRes.count;
+ } else {
+ files = await files; // execute the query
+ count = files.length;
+ }
+
for (let file of files) {
file = Util.constructFilePublicLink(file);
}
@@ -38,7 +55,8 @@ class albumGET extends Route {
name: album.name,
downloadEnabled: link.enableDownload,
isNsfw: album.nsfw,
- files
+ files,
+ count
});
}
}