From 6b72453d4a74af49767dabb1f5f3e27b765b4d2b Mon Sep 17 00:00:00 2001
From: Pitu <7425261+Pitu@users.noreply.github.com>
Date: Wed, 20 Sep 2017 03:03:31 -0300
Subject: =?UTF-8?q?Made=20the=20album=20viewer=20route=20SSR=20so=20crawle?=
=?UTF-8?q?rs=20dont=20have=20issues=20=F0=9F=8E=89?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
routes/album.js | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 61 insertions(+)
create mode 100644 routes/album.js
(limited to 'routes')
diff --git a/routes/album.js b/routes/album.js
new file mode 100644
index 0000000..4fbb971
--- /dev/null
+++ b/routes/album.js
@@ -0,0 +1,61 @@
+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', (req, res, next) => {
+
+ let identifier = req.params.identifier
+ if (identifier === undefined) return res.status(401).json({ success: false, description: 'No identifier provided' })
+
+ db.table('albums')
+ .where('identifier', identifier)
+ .then((albums) => {
+ if (albums.length === 0) return res.json({ success: false, description: 'Album not found' })
+
+ let title = albums[0].name
+ db.table('files').select('name').where('albumid', albums[0].id).orderBy('id', 'DESC').then((files) => {
+
+ let thumb = ''
+ let basedomain = req.get('host')
+ for (let domain of config.domains)
+ if (domain.host === req.get('host'))
+ if (domain.hasOwnProperty('resolve'))
+ basedomain = domain.resolve
+
+ for (let file of files) {
+ file.file = basedomain + '/' + file.name
+
+ let ext = path.extname(file.name).toLowerCase()
+ if (utils.extensions.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 = ``
+ } else {
+ file.thumb = `