Updates (very important to read)
Client-side CSS & JS files will now be processed with Gulp.
Gulp tasks are configured in gulpfile.js file.
CSS files will be optimized with postcss-preset-env, which will
auto-add vendor prefixes and convert any parts necessary for browsers
compatibility.
Afterwards they will be minified with cssnano.
JS files will be optimized with bublé,
likewise for browsers compatibility.
Afterwards they will be minified with terser.
Unprocessed CSS & JS files will now be located at src directory, while
the processed results will be located at dist directory.
Due to bublé, the JS files should now be compatible up to IE 11
at the minimum.
Previously the safe would not work in IE 11 due to extensive usage of
template literals.
Due to that as well, JS files in src directory will now extensively use
arrow functions for my personal comfort (as they will be converted too).
The server will use the processed files at dist directory by default.
If you want to rebuild the files by your own, you can run "yarn build".
Gulp is a development dependency, so make sure you have installed all
development dependencies (e.i. NOT using "yarn install --production").
---
yarn lint -> gulp lint
yarn build -> gulp default
yarn watch -> gulp watch
yarn develop -> env NODE_ENV=development yarn watch
---
Fixed not being able to demote staff into normal users.
/api/token/verify will no longer respond with 401 HTTP error code,
unless an error occurred (which will be 500 HTTP error code).
Fixed /nojs route not displaying file's original name when a duplicate
is found on the server.
Removed is-breeze CSS class name, in favor of Bulma's is-info.
Removed custom styling from auth page, in favor of global styling.
Removed all usage of style HTML attribute in favor of CSS classes.
Renamed js/s/ to js/misc/.
Use loading spinners on dashboard's sidebar menus.
Disable all other sidebar menus when something is loading.
Changed title HTML attribute of disabled control buttons in
uploads & users list.
Hid checkboxes and WIP controls from users list.
Better error messages handling.
Especially homepage will now support CF's HTTP error codes.
Updated various icons.
Also, added fontello config file at public/libs/fontello/config.json.
This should let you edit them more easily with fontello.
Use Gatsby icon for my blog's link in homepage's footer.
A bunch of other improvements here & there.
2019-09-15 06:20:11 +00:00
|
|
|
const routes = require('express').Router()
|
2018-01-23 20:06:30 +00:00
|
|
|
const path = require('path')
|
2019-09-08 01:56:29 +00:00
|
|
|
const paths = require('./../controllers/pathsController')
|
2018-04-13 16:20:57 +00:00
|
|
|
const utils = require('./../controllers/utilsController')
|
Updates (very important to read)
Client-side CSS & JS files will now be processed with Gulp.
Gulp tasks are configured in gulpfile.js file.
CSS files will be optimized with postcss-preset-env, which will
auto-add vendor prefixes and convert any parts necessary for browsers
compatibility.
Afterwards they will be minified with cssnano.
JS files will be optimized with bublé,
likewise for browsers compatibility.
Afterwards they will be minified with terser.
Unprocessed CSS & JS files will now be located at src directory, while
the processed results will be located at dist directory.
Due to bublé, the JS files should now be compatible up to IE 11
at the minimum.
Previously the safe would not work in IE 11 due to extensive usage of
template literals.
Due to that as well, JS files in src directory will now extensively use
arrow functions for my personal comfort (as they will be converted too).
The server will use the processed files at dist directory by default.
If you want to rebuild the files by your own, you can run "yarn build".
Gulp is a development dependency, so make sure you have installed all
development dependencies (e.i. NOT using "yarn install --production").
---
yarn lint -> gulp lint
yarn build -> gulp default
yarn watch -> gulp watch
yarn develop -> env NODE_ENV=development yarn watch
---
Fixed not being able to demote staff into normal users.
/api/token/verify will no longer respond with 401 HTTP error code,
unless an error occurred (which will be 500 HTTP error code).
Fixed /nojs route not displaying file's original name when a duplicate
is found on the server.
Removed is-breeze CSS class name, in favor of Bulma's is-info.
Removed custom styling from auth page, in favor of global styling.
Removed all usage of style HTML attribute in favor of CSS classes.
Renamed js/s/ to js/misc/.
Use loading spinners on dashboard's sidebar menus.
Disable all other sidebar menus when something is loading.
Changed title HTML attribute of disabled control buttons in
uploads & users list.
Hid checkboxes and WIP controls from users list.
Better error messages handling.
Especially homepage will now support CF's HTTP error codes.
Updated various icons.
Also, added fontello config file at public/libs/fontello/config.json.
This should let you edit them more easily with fontello.
Use Gatsby icon for my blog's link in homepage's footer.
A bunch of other improvements here & there.
2019-09-15 06:20:11 +00:00
|
|
|
const config = require('./../config')
|
|
|
|
const db = require('knex')(config.database)
|
2017-10-04 00:13:38 +00:00
|
|
|
|
|
|
|
routes.get('/a/:identifier', async (req, res, next) => {
|
2018-04-05 10:52:57 +00:00
|
|
|
const identifier = req.params.identifier
|
2020-11-02 11:39:28 +00:00
|
|
|
if (identifier === undefined) {
|
2020-06-01 01:51:17 +00:00
|
|
|
res.status(404).sendFile(path.join(paths.errorRoot, config.errorPages[404]))
|
2020-11-02 11:39:28 +00:00
|
|
|
}
|
2018-01-23 20:06:30 +00:00
|
|
|
|
2018-04-26 18:33:11 +00:00
|
|
|
const album = await db.table('albums')
|
2018-04-28 17:26:39 +00:00
|
|
|
.where({
|
|
|
|
identifier,
|
|
|
|
enabled: 1
|
|
|
|
})
|
2019-09-17 04:13:41 +00:00
|
|
|
.select('id', 'name', 'identifier', 'editedAt', 'download', 'public', 'description')
|
2018-04-26 18:33:11 +00:00
|
|
|
.first()
|
|
|
|
|
2020-11-02 11:39:28 +00:00
|
|
|
if (!album || album.public === 0) {
|
2019-09-08 01:56:29 +00:00
|
|
|
return res.status(404).sendFile(path.join(paths.errorRoot, config.errorPages[404]))
|
2020-11-02 11:39:28 +00:00
|
|
|
}
|
2018-01-23 20:06:30 +00:00
|
|
|
|
2019-09-17 04:13:41 +00:00
|
|
|
const nojs = req.query.nojs !== undefined
|
|
|
|
|
2020-04-18 19:52:11 +00:00
|
|
|
let cacheid
|
|
|
|
if (process.env.NODE_ENV !== 'development') {
|
|
|
|
// Cache ID - we initialize a separate cache for No-JS version
|
|
|
|
cacheid = nojs ? `${album.id}-nojs` : album.id
|
|
|
|
|
2020-11-02 11:39:28 +00:00
|
|
|
if (!utils.albumsCache[cacheid]) {
|
2020-04-18 19:52:11 +00:00
|
|
|
utils.albumsCache[cacheid] = {
|
|
|
|
cache: null,
|
Improved albums public page cache and more
Removed its dependency towards albums' editedAt property.
Editing album's metas (name, description, etc) will no longer update
its editedAt property.
Instead it will now ONLY be updated when adding/removing files to/from
it. Just like how it was meant to be, which was to be used to check
whether it's necessary to re-generate their downloadable ZIPs.
Albums public page cache will still be properly invalidated when
adding/removing files to/from it, as well as after editing their metas.
Added views/album-notice.njk to be used to render okay-ish notice when
an album's public page is still being generated.
I was originally thinking of using it for disabled albums as well, but
I refrained from it to reduce the possibility of disabled album IDs from
being easily scanned (as it just returns 404 now).
Removed invalidatedAt property from stats cache. Instead their caches
will immediately be nullified as they should (thus frees up memory
slightly as well).
Stats cache for albums will now only be cleared when truly necessary.
As in, adding/removing files to/from albums will no longer clear them.
Updated Nunjucks files to properly use h1, h2, h3 tags in actual
hierarchical orders.
Elements that don't need to use hX tags will now use P instead.
Nothing changes visually, only structurally.
Fixed some elements in Nunjucks using single quotes instead of
double quotes. They'd have worked the same, but consistency.
Added h1 title in FAQ page.
Make text for no JS warning a bit bigger, and improved the phrasing
a little bit.
2020-06-03 03:44:24 +00:00
|
|
|
generating: false
|
2020-04-18 19:52:11 +00:00
|
|
|
}
|
2020-11-02 11:39:28 +00:00
|
|
|
}
|
2020-04-18 19:52:11 +00:00
|
|
|
|
2020-11-02 11:39:28 +00:00
|
|
|
if (!utils.albumsCache[cacheid].cache && utils.albumsCache[cacheid].generating) {
|
Improved albums public page cache and more
Removed its dependency towards albums' editedAt property.
Editing album's metas (name, description, etc) will no longer update
its editedAt property.
Instead it will now ONLY be updated when adding/removing files to/from
it. Just like how it was meant to be, which was to be used to check
whether it's necessary to re-generate their downloadable ZIPs.
Albums public page cache will still be properly invalidated when
adding/removing files to/from it, as well as after editing their metas.
Added views/album-notice.njk to be used to render okay-ish notice when
an album's public page is still being generated.
I was originally thinking of using it for disabled albums as well, but
I refrained from it to reduce the possibility of disabled album IDs from
being easily scanned (as it just returns 404 now).
Removed invalidatedAt property from stats cache. Instead their caches
will immediately be nullified as they should (thus frees up memory
slightly as well).
Stats cache for albums will now only be cleared when truly necessary.
As in, adding/removing files to/from albums will no longer clear them.
Updated Nunjucks files to properly use h1, h2, h3 tags in actual
hierarchical orders.
Elements that don't need to use hX tags will now use P instead.
Nothing changes visually, only structurally.
Fixed some elements in Nunjucks using single quotes instead of
double quotes. They'd have worked the same, but consistency.
Added h1 title in FAQ page.
Make text for no JS warning a bit bigger, and improved the phrasing
a little bit.
2020-06-03 03:44:24 +00:00
|
|
|
return res.render('album-notice', {
|
|
|
|
config,
|
|
|
|
versions: utils.versionStrings,
|
|
|
|
album,
|
|
|
|
notice: 'This album\'s public page is still being generated. Please try again later.'
|
2020-04-18 19:52:11 +00:00
|
|
|
})
|
2020-11-02 11:39:28 +00:00
|
|
|
} else if (utils.albumsCache[cacheid].cache) {
|
2020-04-18 19:52:11 +00:00
|
|
|
return res.send(utils.albumsCache[cacheid].cache)
|
2020-11-02 11:39:28 +00:00
|
|
|
}
|
2020-04-18 19:52:11 +00:00
|
|
|
|
|
|
|
utils.albumsCache[cacheid].generating = true
|
|
|
|
}
|
2019-09-17 04:13:41 +00:00
|
|
|
|
2018-04-26 18:33:11 +00:00
|
|
|
const files = await db.table('files')
|
|
|
|
.select('name', 'size')
|
|
|
|
.where('albumid', album.id)
|
2020-04-04 16:36:43 +00:00
|
|
|
.orderBy('id', 'desc')
|
2018-04-26 18:33:11 +00:00
|
|
|
|
2019-09-17 04:13:41 +00:00
|
|
|
album.thumb = ''
|
|
|
|
album.totalSize = 0
|
2018-01-23 20:06:30 +00:00
|
|
|
|
2018-04-05 10:52:57 +00:00
|
|
|
for (const file of files) {
|
2019-09-17 04:13:41 +00:00
|
|
|
album.totalSize += parseInt(file.size)
|
|
|
|
|
|
|
|
file.extname = path.extname(file.name)
|
2018-05-12 14:01:14 +00:00
|
|
|
if (utils.mayGenerateThumb(file.extname)) {
|
2019-09-17 04:13:41 +00:00
|
|
|
file.thumb = `thumbs/${file.name.slice(0, -file.extname.length)}.png`
|
|
|
|
// If thumbnail for album is still not set, set it to current file's full URL.
|
|
|
|
// A potential improvement would be to let the user set a specific image as an album cover.
|
|
|
|
if (!album.thumb) album.thumb = file.name
|
2018-05-12 14:01:14 +00:00
|
|
|
}
|
2018-01-23 20:06:30 +00:00
|
|
|
}
|
|
|
|
|
2019-09-17 04:13:41 +00:00
|
|
|
album.downloadLink = album.download === 0
|
|
|
|
? null
|
|
|
|
: `api/album/zip/${album.identifier}?v=${album.editedAt}`
|
|
|
|
|
|
|
|
album.url = `a/${album.identifier}`
|
|
|
|
|
2019-09-19 12:10:37 +00:00
|
|
|
return res.render('album', {
|
|
|
|
config,
|
|
|
|
versions: utils.versionStrings,
|
|
|
|
album,
|
|
|
|
files,
|
|
|
|
nojs
|
|
|
|
}, (error, html) => {
|
2020-04-18 19:52:11 +00:00
|
|
|
const data = error ? null : html
|
|
|
|
if (cacheid) {
|
|
|
|
utils.albumsCache[cacheid].cache = data
|
|
|
|
utils.albumsCache[cacheid].generating = false
|
|
|
|
}
|
2019-09-17 04:13:41 +00:00
|
|
|
|
|
|
|
// Express should already send error to the next handler
|
|
|
|
if (error) return
|
2020-04-18 19:52:11 +00:00
|
|
|
return res.send(data)
|
2018-01-23 20:06:30 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
module.exports = routes
|