aboutsummaryrefslogtreecommitdiff
path: root/routes/album.js
diff options
context:
space:
mode:
author8cy <[email protected]>2020-05-23 02:24:18 -0700
committer8cy <[email protected]>2020-05-23 02:24:18 -0700
commit454825558aef4320c82b3d3148537038364c9427 (patch)
treefc8366ce0203fd58bb65d843c04608d25a08ab16 /routes/album.js
downloadstrelizia-master.tar.xz
strelizia-master.zip
DARLING in the FRANXXHEADmaster
Diffstat (limited to 'routes/album.js')
-rw-r--r--routes/album.js56
1 files changed, 56 insertions, 0 deletions
diff --git a/routes/album.js b/routes/album.js
new file mode 100644
index 0000000..46f00d3
--- /dev/null
+++ b/routes/album.js
@@ -0,0 +1,56 @@
+const config = require('../config.js');
+const routes = require('express').Router();
+const db = require('knex')(config.database);
+const path = require('path');
+const utils = require('../controllers/utilsController.js');
+
+routes.get('/a/:identifier', async (req, res, next) => {
+ let 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 (let file of files) {
+ file.file = `${basedomain}/${file.name}`;
+
+ let ext = path.extname(file.name).toLowerCase();
+ if (utils.imageExtensions.includes(ext) || 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', {
+ layout: false,
+ title: album.name,
+ count: files.length,
+ thumb,
+ files,
+ identifier,
+ enableDownload
+ });
+});
+
+module.exports = routes;