filesafe/routes/album.js
Bobby Wibowo 5bb960756f
Updates
uploadController.js:

 * Fixed chunk uploads failing when "blockedExtensions" is missing from the config file.

config.sample.js:

* Renamed "blockedExtensions" to "extensionsFilter", and added a new option named "filterBlacklist". When "filterBlacklist" is set to 'true', all extensions in "extensionsFilter" array will be blacklisted, otherwise it will be a whitelist, so only files with those extensions that can be uploaded.

* Renamed "uploads.chunkedUploads.maxSize" to "uploads.chunkedUploads.chunkSize".

* Added "uploads.chunkedUploads.noJsMaxSize" which can be used to change the 'displayed' file size on the No-JS uploader page.

* Some other phrases updates.

_globals.njk:

* Updated static files' version string since there is a small update to home.js.

other files:

* Regular code improvements/tweaks.
2018-04-25 20:16:34 +07:00

62 lines
1.9 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/' })
}
const files = await db.table('files').select('name').where('albumid', album.id).orderBy('id', 'DESC')
let thumb = ''
const basedomain = config.domain
for (const file of files) {
file.file = `${basedomain}/${file.name}`
const ext = path.extname(file.name).toLowerCase()
if ((config.uploads.generateThumbnails.image && utils.imageExtensions.includes(ext)) || (config.uploads.generateThumbnails.video && utils.videoExtensions.includes(ext))) {
file.thumb = `${basedomain}/thumbs/${file.name.slice(0, -ext.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
}
file.thumb = `<img src="${file.thumb}"/>`
} else {
file.thumb = `<h1 class="title">${ext}</h1>`
}
}
let enableDownload = false
if (config.uploads.generateZips) { enableDownload = true }
return res.render('album', {
title: album.name,
count: files.length,
thumb,
files,
identifier,
enableDownload,
url: `${homeDomain}/a/${album.identifier}`
})
})
module.exports = routes