From e7767ac7095f93393a627fd5e867af4a1ca4b011 Mon Sep 17 00:00:00 2001 From: Pitu <7425261+Pitu@users.noreply.github.com> Date: Sun, 16 Sep 2018 00:56:13 -0300 Subject: Routes --- src/api/routes/albums/albumGET.js | 52 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/api/routes/albums/albumGET.js (limited to 'src/api/routes/albums/albumGET.js') diff --git a/src/api/routes/albums/albumGET.js b/src/api/routes/albums/albumGET.js new file mode 100644 index 0000000..80affd2 --- /dev/null +++ b/src/api/routes/albums/albumGET.js @@ -0,0 +1,52 @@ +const Route = require('../../structures/Route'); +const config = require('../../../../config'); +const db = require('knex')(config.server.database); + +class albumGET extends Route { + constructor() { + super('/album/:identifier', 'get', { bypassAuth: true }); + } + + async run(req, res) { + const { identifier } = req.params; + if (!identifier) return res.status(400).json({ message: 'Invalid identifier supplied' }); + + const link = await db.table('links').where({ + identifier, + enabled: true + }).first(); + if (!link) return res.status(400).json({ message: 'The identifier supplied could not be found' }); + + const album = await db.table('albums').where('id', link.albumId).first(); + 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 files = await db.table('files') + .where('id', fileIds) + .select('name'); + + return res.json({ + message: 'Successfully retrieved files', + files + }); + } +} + +class albumsDropdownGET extends Route { + constructor() { + super('/albums/:identifier', 'get'); + } + + async run(req, res, user) { + const albums = await db.table('albums') + .where('userId', user.id) + .select('id', 'name'); + return res.json({ + message: 'Successfully retrieved albums', + albums + }); + } +} + +module.exports = [albumGET, albumsDropdownGET]; -- cgit v1.2.3 From 04cb6dcce574efbaecf80071acd8219a8b5fd6f7 Mon Sep 17 00:00:00 2001 From: Pitu <7425261+Pitu@users.noreply.github.com> Date: Sun, 16 Sep 2018 01:10:46 -0300 Subject: We dont need the second one, probably --- src/api/routes/albums/albumGET.js | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) (limited to 'src/api/routes/albums/albumGET.js') diff --git a/src/api/routes/albums/albumGET.js b/src/api/routes/albums/albumGET.js index 80affd2..f9e5208 100644 --- a/src/api/routes/albums/albumGET.js +++ b/src/api/routes/albums/albumGET.js @@ -33,20 +33,4 @@ class albumGET extends Route { } } -class albumsDropdownGET extends Route { - constructor() { - super('/albums/:identifier', 'get'); - } - - async run(req, res, user) { - const albums = await db.table('albums') - .where('userId', user.id) - .select('id', 'name'); - return res.json({ - message: 'Successfully retrieved albums', - albums - }); - } -} - -module.exports = [albumGET, albumsDropdownGET]; +module.exports = albumGET; -- cgit v1.2.3 From c2c6e99878853fafdbd5e708c3163921f8529ae1 Mon Sep 17 00:00:00 2001 From: Pitu <7425261+Pitu@users.noreply.github.com> Date: Mon, 17 Sep 2018 04:38:25 -0300 Subject: Public albums wooo! --- src/api/routes/albums/albumGET.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/api/routes/albums/albumGET.js') 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 }); } -- cgit v1.2.3 From f2c885b718528d42df412e612520fb471c46d0bd Mon Sep 17 00:00:00 2001 From: Pitu <7425261+Pitu@users.noreply.github.com> Date: Mon, 17 Sep 2018 04:55:42 -0300 Subject: Commented all the code --- src/api/routes/albums/albumGET.js | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'src/api/routes/albums/albumGET.js') diff --git a/src/api/routes/albums/albumGET.js b/src/api/routes/albums/albumGET.js index 655db13..b63811c 100644 --- a/src/api/routes/albums/albumGET.js +++ b/src/api/routes/albums/albumGET.js @@ -12,25 +12,40 @@ class albumGET extends Route { const { identifier } = req.params; if (!identifier) return res.status(400).json({ message: 'Invalid identifier supplied' }); - const link = await db.table('links').where({ - identifier, - enabled: true - }).first(); + /* + Make sure it exists and it's enabled + */ + const link = await db.table('links').where({ identifier, enabled: true }).first(); if (!link) return res.status(400).json({ message: 'The identifier supplied could not be found' }); + /* + Same with the album, just to make sure is not a deleted album and a leftover link + */ const album = await db.table('albums').where('id', link.albumId).first(); if (!album) return res.status(400).json({ message: 'Album not found' }); - const fileList = await db.table('albumsFiles').where('albumId', link.albumId); + /* + Grab the files in a very unoptimized way. (This should be a join between both tables) + */ + const fileList = await db.table('albumsFiles').where('albumId', link.albumId).select('fileId'); const fileIds = fileList.map(el => el.fileId); const files = await db.table('files') .whereIn('id', fileIds) .orderBy('id', 'desc') .select('name'); + /* + Create the links for each file + */ for (let file of files) { file = Util.constructFilePublicLink(file); } + + /* + Add 1 more view to the link + */ + await db.table('links').where({ identifier }).update('views', Number(link.views) + 1); + return res.json({ message: 'Successfully retrieved files', name: album.name, -- cgit v1.2.3 From 8ca6784eec8d8f1e4a9c4f6875704f09aae1103a Mon Sep 17 00:00:00 2001 From: Pitu <7425261+Pitu@users.noreply.github.com> Date: Tue, 18 Sep 2018 03:52:49 -0300 Subject: Better error handling on invalid links --- src/api/routes/albums/albumGET.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/api/routes/albums/albumGET.js') diff --git a/src/api/routes/albums/albumGET.js b/src/api/routes/albums/albumGET.js index b63811c..f5e339f 100644 --- a/src/api/routes/albums/albumGET.js +++ b/src/api/routes/albums/albumGET.js @@ -16,13 +16,13 @@ class albumGET extends Route { Make sure it exists and it's enabled */ const link = await db.table('links').where({ identifier, enabled: true }).first(); - if (!link) return res.status(400).json({ message: 'The identifier supplied could not be found' }); + if (!link) return res.status(404).json({ message: 'The identifier supplied could not be found' }); /* Same with the album, just to make sure is not a deleted album and a leftover link */ const album = await db.table('albums').where('id', link.albumId).first(); - if (!album) return res.status(400).json({ message: 'Album not found' }); + if (!album) return res.status(404).json({ message: 'Album not found' }); /* Grab the files in a very unoptimized way. (This should be a join between both tables) -- cgit v1.2.3 From 89a271818ed25b0a17a17dd1d6804e34d1f2ec0f Mon Sep 17 00:00:00 2001 From: Pitu Date: Tue, 19 Feb 2019 23:52:24 +0900 Subject: Switch config to .env --- src/api/routes/albums/albumGET.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/api/routes/albums/albumGET.js') diff --git a/src/api/routes/albums/albumGET.js b/src/api/routes/albums/albumGET.js index f5e339f..59398a1 100644 --- a/src/api/routes/albums/albumGET.js +++ b/src/api/routes/albums/albumGET.js @@ -1,6 +1,4 @@ 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 { @@ -8,7 +6,7 @@ class albumGET extends Route { super('/album/:identifier', 'get', { bypassAuth: true }); } - async run(req, res) { + async run(req, res, db) { const { identifier } = req.params; if (!identifier) return res.status(400).json({ message: 'Invalid identifier supplied' }); -- cgit v1.2.3 From 3ce7657871bfe392d73ab67a6c1a8a10543e3d98 Mon Sep 17 00:00:00 2001 From: Pitu Date: Sat, 2 Mar 2019 22:36:28 +0900 Subject: wip --- src/api/routes/albums/albumGET.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/api/routes/albums/albumGET.js') diff --git a/src/api/routes/albums/albumGET.js b/src/api/routes/albums/albumGET.js index 59398a1..fae7dd1 100644 --- a/src/api/routes/albums/albumGET.js +++ b/src/api/routes/albums/albumGET.js @@ -14,7 +14,7 @@ class albumGET extends Route { Make sure it exists and it's enabled */ const link = await db.table('links').where({ identifier, enabled: true }).first(); - if (!link) return res.status(404).json({ message: 'The identifier supplied could not be found' }); + if (!link) return res.status(404).json({ message: 'The album could not be found' }); /* Same with the album, just to make sure is not a deleted album and a leftover link -- cgit v1.2.3 From d1340c26b5f72a45fb577ad7879addcb548dcf12 Mon Sep 17 00:00:00 2001 From: Pitu Date: Thu, 25 Jun 2020 02:06:00 +0900 Subject: Optimize album view --- src/api/routes/albums/albumGET.js | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) (limited to 'src/api/routes/albums/albumGET.js') diff --git a/src/api/routes/albums/albumGET.js b/src/api/routes/albums/albumGET.js index fae7dd1..1bf3630 100644 --- a/src/api/routes/albums/albumGET.js +++ b/src/api/routes/albums/albumGET.js @@ -10,38 +10,26 @@ class albumGET extends Route { const { identifier } = req.params; if (!identifier) return res.status(400).json({ message: 'Invalid identifier supplied' }); - /* - Make sure it exists and it's enabled - */ + // Make sure it exists and it's enabled const link = await db.table('links').where({ identifier, enabled: true }).first(); if (!link) return res.status(404).json({ message: 'The album could not be found' }); - /* - Same with the album, just to make sure is not a deleted album and a leftover link - */ + // Same with the album, just to make sure is not a deleted album and a leftover link const album = await db.table('albums').where('id', link.albumId).first(); if (!album) return res.status(404).json({ message: 'Album not found' }); - /* - Grab the files in a very unoptimized way. (This should be a join between both tables) - */ - const fileList = await db.table('albumsFiles').where('albumId', link.albumId).select('fileId'); - const fileIds = fileList.map(el => el.fileId); - const files = await db.table('files') - .whereIn('id', fileIds) - .orderBy('id', 'desc') - .select('name'); - - /* - Create the links for each file - */ + const files = await db.table('albumsFiles') + .where({ albumId: link.albumId }) + .join('files', 'albumsFiles.fileId', 'files.id') + .select('files.name') + .orderBy('files.id', 'desc'); + + // Create the links for each file for (let file of files) { file = Util.constructFilePublicLink(file); } - /* - Add 1 more view to the link - */ + // Add 1 more view to the link await db.table('links').where({ identifier }).update('views', Number(link.views) + 1); return res.json({ -- cgit v1.2.3 From 04fdd63cee5327f49e5e11d5837a9031027c34ef Mon Sep 17 00:00:00 2001 From: Zephyrrus Date: Sun, 5 Jul 2020 04:17:09 +0300 Subject: feat: refactor single album page to use vuex --- src/api/routes/albums/albumGET.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/api/routes/albums/albumGET.js') diff --git a/src/api/routes/albums/albumGET.js b/src/api/routes/albums/albumGET.js index 1bf3630..f40750b 100644 --- a/src/api/routes/albums/albumGET.js +++ b/src/api/routes/albums/albumGET.js @@ -21,7 +21,7 @@ class albumGET extends Route { const files = await db.table('albumsFiles') .where({ albumId: link.albumId }) .join('files', 'albumsFiles.fileId', 'files.id') - .select('files.name') + .select('files.name', 'files.id') .orderBy('files.id', 'desc'); // Create the links for each file @@ -36,7 +36,7 @@ class albumGET extends Route { message: 'Successfully retrieved files', name: album.name, downloadEnabled: link.enableDownload, - files + files, }); } } -- cgit v1.2.3 From fb0bc57542a44dcc94149f393d8a4ff0c2e7902b Mon Sep 17 00:00:00 2001 From: Zephyrrus Date: Tue, 7 Jul 2020 02:02:59 +0300 Subject: feat: try fixing THE SHITTY WATERFALL --- src/api/routes/albums/albumGET.js | 1 + 1 file changed, 1 insertion(+) (limited to 'src/api/routes/albums/albumGET.js') diff --git a/src/api/routes/albums/albumGET.js b/src/api/routes/albums/albumGET.js index f40750b..81edc95 100644 --- a/src/api/routes/albums/albumGET.js +++ b/src/api/routes/albums/albumGET.js @@ -25,6 +25,7 @@ class albumGET extends Route { .orderBy('files.id', 'desc'); // Create the links for each file + // eslint-disable-next-line no-restricted-syntax for (let file of files) { file = Util.constructFilePublicLink(file); } -- cgit v1.2.3 From 90001c2df56d58e69fd199a518ae7f3e4ed327fc Mon Sep 17 00:00:00 2001 From: Zephyrrus Date: Thu, 24 Dec 2020 10:40:50 +0200 Subject: chore: remove trailing commas --- src/api/routes/albums/albumGET.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/api/routes/albums/albumGET.js') diff --git a/src/api/routes/albums/albumGET.js b/src/api/routes/albums/albumGET.js index 81edc95..950a1fd 100644 --- a/src/api/routes/albums/albumGET.js +++ b/src/api/routes/albums/albumGET.js @@ -37,7 +37,7 @@ class albumGET extends Route { message: 'Successfully retrieved files', name: album.name, downloadEnabled: link.enableDownload, - files, + files }); } } -- cgit v1.2.3 From edb3bed98864e34695a5ae0093c414a2b578073a Mon Sep 17 00:00:00 2001 From: Pitu Date: Mon, 28 Dec 2020 00:10:59 +0900 Subject: feat: Add warning to nsfw albums --- src/api/routes/albums/albumGET.js | 1 + 1 file changed, 1 insertion(+) (limited to 'src/api/routes/albums/albumGET.js') diff --git a/src/api/routes/albums/albumGET.js b/src/api/routes/albums/albumGET.js index 950a1fd..c9f6763 100644 --- a/src/api/routes/albums/albumGET.js +++ b/src/api/routes/albums/albumGET.js @@ -37,6 +37,7 @@ class albumGET extends Route { message: 'Successfully retrieved files', name: album.name, downloadEnabled: link.enableDownload, + isNsfw: album.nsfw, files }); } -- cgit v1.2.3