diff --git a/controllers/albumsController.js b/controllers/albumsController.js index 2f56c8c..fb2364c 100644 --- a/controllers/albumsController.js +++ b/controllers/albumsController.js @@ -5,6 +5,7 @@ const randomstring = require('randomstring') const Zip = require('jszip') const paths = require('./pathsController') const perms = require('./permissionController') +const uploadController = require('./uploadController') const utils = require('./utilsController') const config = require('./../config') const logger = require('./../logger') @@ -382,16 +383,8 @@ self.get = async (req, res, next) => { }) .first() - if (!album) { - return res.json({ - success: false, - description: 'Album not found.' - }) - } else if (album.public === 0) { - return res.status(403).json({ - success: false, - description: 'This album is not available for public.' - }) + if (!album || album.public === 0) { + return res.status(404).json({ success: false, description: 'The album could not be found.' }) } const title = album.name @@ -401,17 +394,24 @@ self.get = async (req, res, next) => { .orderBy('id', 'desc') for (const file of files) { - file.file = `${config.domain}/${file.name}` + if (req._upstreamCompat) { + file.url = `${config.domain}/${file.name}` + } else { + file.file = `${config.domain}/${file.name}` + } const extname = utils.extname(file.name) if (utils.mayGenerateThumb(extname)) { file.thumb = `${config.domain}/thumbs/${file.name.slice(0, -extname.length)}.png` + if (req._upstreamCompat) file.thumbSquare = file.thumb } } return res.json({ success: true, + description: 'Successfully retrieved files.', title, + download: Boolean(album.download), count: files.length, files }) @@ -552,6 +552,42 @@ self.generateZip = async (req, res, next) => { } } +self.listFiles = async (req, res, next) => { + if (req.params.page === undefined) { + // Map to /api/album/get, but with lolisafe upstream compatibility, when accessed with this API route + req.params.identifier = req.params.id + delete req.params.id + + req._upstreamCompat = true + res._json = res.json + res.json = (body = {}) => { + // Rebuild JSON payload to match lolisafe upstream + const rebuild = {} + const maps = { + success: null, + description: 'message', + title: 'name', + download: 'downloadEnabled', + count: null + } + + Object.keys(body).forEach(key => { + if (maps[key] !== undefined) { + if (maps[key]) rebuild[maps[key]] = body[key] + } else { + rebuild[key] = body[key] + } + }) + + if (rebuild.message) rebuild.message = rebuild.message.replace(/\.$/, '') + return res._json(rebuild) + } + return self.get(req, res, next) + } else { + return uploadController.list(req, res, next) + } +} + self.addFiles = async (req, res, next) => { const user = await utils.authorize(req, res) if (!user) return diff --git a/routes/api.js b/routes/api.js index 85f0d40..bb43e1a 100644 --- a/routes/api.js +++ b/routes/api.js @@ -33,8 +33,8 @@ routes.post('/upload/finishchunks', (req, res, next) => uploadController.finishC routes.post('/upload/:albumid', (req, res, next) => uploadController.upload(req, res, next)) routes.get('/album/get/:identifier', (req, res, next) => albumsController.get(req, res, next)) routes.get('/album/zip/:identifier', (req, res, next) => albumsController.generateZip(req, res, next)) -routes.get('/album/:id', (req, res, next) => uploadController.list(req, res, next)) -routes.get('/album/:id/:page', (req, res, next) => uploadController.list(req, res, next)) +routes.get('/album/:id', (req, res, next) => albumsController.listFiles(req, res, next)) +routes.get('/album/:id/:page', (req, res, next) => albumsController.listFiles(req, res, next)) routes.get('/albums', (req, res, next) => albumsController.list(req, res, next)) routes.get('/albums/:page', (req, res, next) => albumsController.list(req, res, next)) routes.post('/albums', (req, res, next) => albumsController.create(req, res, next)) diff --git a/src/js/dashboard.js b/src/js/dashboard.js index 841343e..1bab9fe 100644 --- a/src/js/dashboard.js +++ b/src/js/dashboard.js @@ -808,7 +808,7 @@ page.getUploads = (params = {}) => { ${params.all ? '