mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2025-02-20 20:29:04 +00:00
Fixed setContentDisposition throwing errors
This commit is contained in:
parent
b589e070d8
commit
57207493a2
@ -33,6 +33,8 @@ module.exports = {
|
||||
/*
|
||||
If you serve files with node, you can optionally choose to set Content-Disposition header
|
||||
into their original file names. This allows users to save files into their original file names.
|
||||
|
||||
This will query the DB every time users access uploaded files as there's no caching mechanism.
|
||||
*/
|
||||
setContentDisposition: false,
|
||||
|
||||
|
17
lolisafe.js
17
lolisafe.js
@ -69,20 +69,21 @@ let setHeaders = res => {
|
||||
|
||||
const initServeStaticUploads = (opts = {}) => {
|
||||
if (config.setContentDisposition) {
|
||||
opts.preSetHeaders = async (res, path) => {
|
||||
// Do only if accessing files from uploads' root directory (i.e. not thumbs, etc.)
|
||||
// and only if they're GET requests
|
||||
if (path.indexOf('/', 1) === -1 && res.req.method === 'GET') {
|
||||
const name = path.substring(1)
|
||||
try {
|
||||
opts.preSetHeaders = async (res, req, path, stat) => {
|
||||
try {
|
||||
// Do only if accessing files from uploads' root directory (i.e. not thumbs, etc.)
|
||||
// and only if they are GET requests
|
||||
const relpath = path.replace(paths.uploads, '')
|
||||
if (relpath.indexOf('/', 1) === -1 && req.method === 'GET') {
|
||||
const name = relpath.substring(1)
|
||||
const file = await db.table('files')
|
||||
.where('name', name)
|
||||
.select('original')
|
||||
.first()
|
||||
res.set('Content-Disposition', contentDisposition(file.original, { type: 'inline' }))
|
||||
} catch (error) {
|
||||
logger.error(error)
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error(error)
|
||||
}
|
||||
}
|
||||
// serveStatic is just a modified express/serve-static module that allows specifying
|
||||
|
@ -49,7 +49,7 @@
|
||||
"randomstring": "~1.1.5",
|
||||
"readline": "~1.3.0",
|
||||
"search-query-parser": "~1.5.5",
|
||||
"serve-static": "git+https://git@github.com/BobbyWibowo/serve-static#60049dec396615ab738d29576a65432e4f9d7d4a",
|
||||
"serve-static": "git+https://git@github.com/BobbyWibowo/serve-static#02c26587b25a7156a89dc05b617fce0aa90cefb9",
|
||||
"sharp": "~0.26.1",
|
||||
"sqlite3": "~5.0.0",
|
||||
"systeminformation": "~4.27.5"
|
||||
|
Loading…
Reference in New Issue
Block a user