mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2024-12-13 07:56:23 +00:00
00cbd3e76c
Updated ESLint rule: curly, again. Mainly to also enabled "consistent" rule, which enforces curly into else/elseif blocks, if its if block requires curly. Added support for GET requests to /api/delete route. Its usage is /api/delete/identifier, where identifier is the filename. Though just like its POST route, it needs token in the header.
72 lines
2.1 KiB
JavaScript
72 lines
2.1 KiB
JavaScript
const config = require('./../config')
|
|
const routes = require('express').Router()
|
|
const db = require('knex')(config.database)
|
|
const path = require('path')
|
|
const utils = require('./../controllers/utilsController')
|
|
|
|
const homeDomain = config.homeDomain || config.domain
|
|
|
|
routes.get('/a/:identifier', async (req, res, next) => {
|
|
const identifier = req.params.identifier
|
|
if (identifier === undefined)
|
|
return res.status(401).json({
|
|
success: false,
|
|
description: 'No identifier provided.'
|
|
})
|
|
|
|
const album = await db.table('albums')
|
|
.where({
|
|
identifier,
|
|
enabled: 1
|
|
})
|
|
.first()
|
|
|
|
if (!album)
|
|
return res.status(404).sendFile('404.html', { root: './pages/error/' })
|
|
else if (album.public === 0)
|
|
return res.status(401).json({
|
|
success: false,
|
|
description: 'This album is not available for public.'
|
|
})
|
|
|
|
const files = await db.table('files')
|
|
.select('name', 'size')
|
|
.where('albumid', album.id)
|
|
.orderBy('id', 'DESC')
|
|
|
|
let thumb = ''
|
|
const basedomain = config.domain
|
|
|
|
let totalSize = 0
|
|
for (const file of files) {
|
|
file.file = `${basedomain}/${file.name}`
|
|
file.extname = path.extname(file.name).toLowerCase()
|
|
if (utils.mayGenerateThumb(file.extname)) {
|
|
file.thumb = `${basedomain}/thumbs/${file.name.slice(0, -file.extname.length)}.png`
|
|
/*
|
|
If thumbnail for album is still not set, do it.
|
|
A potential improvement would be to let the user upload a specific image as an album cover
|
|
since embedding the first image could potentially result in nsfw content when pasting links.
|
|
*/
|
|
if (thumb === '') thumb = file.thumb
|
|
}
|
|
totalSize += parseInt(file.size)
|
|
}
|
|
|
|
return res.render('album', {
|
|
title: album.name,
|
|
description: album.description ? album.description.replace(/\n/g, '<br>') : null,
|
|
count: files.length,
|
|
thumb,
|
|
files,
|
|
identifier,
|
|
generateZips: config.uploads.generateZips,
|
|
downloadLink: album.download === 0 ? null : `../api/album/zip/${album.identifier}?v=${album.editedAt}`,
|
|
editedAt: album.editedAt,
|
|
url: `${homeDomain}/a/${album.identifier}`,
|
|
totalSize
|
|
})
|
|
})
|
|
|
|
module.exports = routes
|