diff options
| author | Pitu <[email protected]> | 2018-09-17 04:38:25 -0300 |
|---|---|---|
| committer | Pitu <[email protected]> | 2018-09-17 04:38:25 -0300 |
| commit | c2c6e99878853fafdbd5e708c3163921f8529ae1 (patch) | |
| tree | 8313268655c19bc74497172ee1d0642a52e93984 /src/api | |
| parent | This route should handle more stuff, so it does now (diff) | |
| download | host.fuwn.me-c2c6e99878853fafdbd5e708c3163921f8529ae1.tar.xz host.fuwn.me-c2c6e99878853fafdbd5e708c3163921f8529ae1.zip | |
Public albums wooo!
Diffstat (limited to 'src/api')
| -rw-r--r-- | src/api/routes/albums/albumGET.js | 11 | ||||
| -rw-r--r-- | src/api/routes/albums/link/linkPOST.js | 3 | ||||
| -rw-r--r-- | src/api/utils/Util.js | 4 |
3 files changed, 14 insertions, 4 deletions
diff --git a/src/api/routes/albums/albumGET.js b/src/api/routes/albums/albumGET.js index f9e5208..655db13 100644 --- a/src/api/routes/albums/albumGET.js +++ b/src/api/routes/albums/albumGET.js @@ -1,6 +1,7 @@ const Route = require('../../structures/Route'); const config = require('../../../../config'); const db = require('knex')(config.server.database); +const Util = require('../../utils/Util'); class albumGET extends Route { constructor() { @@ -21,13 +22,19 @@ class albumGET extends Route { if (!album) return res.status(400).json({ message: 'Album not found' }); const fileList = await db.table('albumsFiles').where('albumId', link.albumId); - const fileIds = fileList.filter(el => el.file.fileId); + const fileIds = fileList.map(el => el.fileId); const files = await db.table('files') - .where('id', fileIds) + .whereIn('id', fileIds) + .orderBy('id', 'desc') .select('name'); + for (let file of files) { + file = Util.constructFilePublicLink(file); + } return res.json({ message: 'Successfully retrieved files', + name: album.name, + downloadEnabled: link.enableDownload, files }); } diff --git a/src/api/routes/albums/link/linkPOST.js b/src/api/routes/albums/link/linkPOST.js index 26a527a..9c8c0bc 100644 --- a/src/api/routes/albums/link/linkPOST.js +++ b/src/api/routes/albums/link/linkPOST.js @@ -17,6 +17,9 @@ class linkPOST extends Route { const exists = await db.table('albums').where('id', albumId).first(); if (!exists) return res.status(400).json({ message: 'Album doesn\t exist' }); + const count = await db.table('links').where('albumId', albumId).count({ count: 'id' }); + if (count[0].count >= config.albums.maxLinksPerAlbum) return res.status(400).json({ message: 'Maximum links per album reached' }); + const identifier = await Util.getUniqueAlbumIdentifier(); if (!identifier) return res.status(500).json({ message: 'There was a problem allocating a link for your album' }); diff --git a/src/api/utils/Util.js b/src/api/utils/Util.js index d8ae735..e0ad031 100644 --- a/src/api/utils/Util.js +++ b/src/api/utils/Util.js @@ -105,7 +105,7 @@ class Util { static getUniqueAlbumIdentifier() { const retry = async (i = 0) => { const identifier = randomstring.generate({ - length: config.uploads.generatedAlbumLinkLength, + length: config.albums.generatedAlbumLinkLength, capitalization: 'lowercase' }); const exists = await db.table('links').where({ identifier }).first(); @@ -113,7 +113,7 @@ class Util { /* It's funny but if you do i++ the asignment never gets done resulting in an infinite loop */ - if (i < config.uploads.retryAlbumLinkTimes) return retry(i + 1); + if (i < config.albums.retryAlbumLinkTimes) return retry(i + 1); log.error('Couldnt allocate identifier for album'); return null; }; |