fix: force download of unsafe extensions

This commit is contained in:
NGPixel
2021-12-24 20:18:12 -05:00
parent 57b56d3a5b
commit 79bdd44093
6 changed files with 33 additions and 2 deletions

View File

@@ -168,8 +168,15 @@ module.exports = class Asset extends Model {
static async getAsset(assetPath, res) {
try {
const fileInfo = assetHelper.getPathInfo(assetPath)
const fileHash = assetHelper.generateHash(assetPath)
const cachePath = path.resolve(WIKI.ROOTPATH, WIKI.config.dataPath, `cache/${fileHash}.dat`)
// Force unsafe extensions to download
if (WIKI.config.uploads.forceDownload && !['.png', '.apng', '.jpg', '.jpeg', '.gif', '.bmp', '.webp', '.svg'].includes(fileInfo.ext)) {
res.set('Content-disposition', 'attachment; filename=' + fileInfo.base)
}
if (await WIKI.models.assets.getAssetFromCache(assetPath, cachePath, res)) {
return
}