Fix #140 allow non-English characters in downloaded zip filename
This commit is contained in:
Generated
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "immich-public-proxy",
|
"name": "immich-public-proxy",
|
||||||
"version": "1.13.2",
|
"version": "1.13.3",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "immich-public-proxy",
|
"name": "immich-public-proxy",
|
||||||
"version": "1.13.2",
|
"version": "1.13.3",
|
||||||
"license": "AGPL-3.0",
|
"license": "AGPL-3.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"archiver": "^7.0.1",
|
"archiver": "^7.0.1",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "immich-public-proxy",
|
"name": "immich-public-proxy",
|
||||||
"version": "1.13.2",
|
"version": "1.13.3",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "ts-node src/index.ts",
|
"dev": "ts-node src/index.ts",
|
||||||
"build": "npx tsc",
|
"build": "npx tsc",
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
/**
|
||||||
|
* From https://github.com/parshap/node-sanitize-filename
|
||||||
|
*
|
||||||
|
* Replaces characters in strings that are illegal/unsafe for filenames.
|
||||||
|
* Unsafe characters are either removed or replaced by a substitute set
|
||||||
|
* in the optional `options` object.
|
||||||
|
*
|
||||||
|
* Illegal Characters on Various Operating Systems
|
||||||
|
* / ? < > \ : * | "
|
||||||
|
* https://kb.acronis.com/content/39790
|
||||||
|
*
|
||||||
|
* Unicode Control codes
|
||||||
|
* C0 0x00-0x1f & C1 (0x80-0x9f)
|
||||||
|
* http://en.wikipedia.org/wiki/C0_and_C1_control_codes
|
||||||
|
*
|
||||||
|
* Reserved filenames on Unix-based systems (".", "..")
|
||||||
|
* Reserved filenames in Windows ("CON", "PRN", "AUX", "NUL", "COM1",
|
||||||
|
* "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9",
|
||||||
|
* "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", and
|
||||||
|
* "LPT9") case-insesitively and with or without filename extensions.
|
||||||
|
*
|
||||||
|
* Capped at 255 characters in length.
|
||||||
|
* http://unix.stackexchange.com/questions/32795/what-is-the-maximum-allowed-filename-and-folder-size-with-ecryptfs
|
||||||
|
*
|
||||||
|
* @param {String} input Original filename
|
||||||
|
* @param {Object} options {replacement: String | Function }
|
||||||
|
* @return {String} Sanitized filename
|
||||||
|
*/
|
||||||
|
|
||||||
|
const illegalRe = /[/?<>\\:*|"]/g
|
||||||
|
// eslint-disable-next-line no-control-regex
|
||||||
|
const controlRe = /[\x00-\x1f\x80-\x9f]/g
|
||||||
|
const reservedRe = /^\.+$/
|
||||||
|
const windowsReservedRe = /^(con|prn|aux|nul|com[0-9]|lpt[0-9])(\..*)?$/i
|
||||||
|
const windowsTrailingRe = /[. ]+$/
|
||||||
|
|
||||||
|
export function sanitize (input, replacement = '') {
|
||||||
|
if (typeof input !== 'string') {
|
||||||
|
throw new Error('Input must be string')
|
||||||
|
}
|
||||||
|
return input
|
||||||
|
.replace(illegalRe, replacement)
|
||||||
|
.replace(controlRe, replacement)
|
||||||
|
.replace(reservedRe, replacement)
|
||||||
|
.replace(windowsReservedRe, replacement)
|
||||||
|
.replace(windowsTrailingRe, replacement)
|
||||||
|
.slice(0, 254)
|
||||||
|
}
|
||||||
+2
-1
@@ -4,6 +4,7 @@ import { Asset, AssetType, ImageSize, IncomingShareRequest, SharedLink } from '.
|
|||||||
import { canDownload, getConfigOption } from './functions'
|
import { canDownload, getConfigOption } from './functions'
|
||||||
import archiver from 'archiver'
|
import archiver from 'archiver'
|
||||||
import { respondToInvalidRequest } from './invalidRequestHandler'
|
import { respondToInvalidRequest } from './invalidRequestHandler'
|
||||||
|
import { sanitize } from './includes/sanitize'
|
||||||
|
|
||||||
class Render {
|
class Render {
|
||||||
lgConfig
|
lgConfig
|
||||||
@@ -170,7 +171,7 @@ class Render {
|
|||||||
*/
|
*/
|
||||||
async downloadAll (res: Response, share: SharedLink) {
|
async downloadAll (res: Response, share: SharedLink) {
|
||||||
res.setHeader('Content-Type', 'application/zip')
|
res.setHeader('Content-Type', 'application/zip')
|
||||||
const title = this.title(share).replace(/[^\w .-]/g, '') + '.zip'
|
const title = sanitize(this.title(share)) + '.zip'
|
||||||
res.setHeader('Content-Disposition', `attachment; filename="${title}"`)
|
res.setHeader('Content-Disposition', `attachment; filename="${title}"`)
|
||||||
const archive = archiver('zip', { zlib: { level: 6 } })
|
const archive = archiver('zip', { zlib: { level: 6 } })
|
||||||
archive.pipe(res)
|
archive.pipe(res)
|
||||||
|
|||||||
Reference in New Issue
Block a user