fix: files with "\" in the name didn't work in zip
Massimo Melina committed
Jan 21, 2025 at 18:58 UTC
91bb387b5fbd21641e30367b4e1a54683188657c
1 file changed
+4
-2
src/zip.ts
+4
-2
@@ -9,7 +9,7 @@ import fs from 'fs/promises'
9
import { defineConfig } from './config'
10
import { basename, dirname } from 'path'
11
import { applyRange, forceDownload, monitorAsDownload } from './serveFile'
12
-import { HTTP_OK } from './const'
12
+import { HTTP_OK, IS_WINDOWS } from './const'
13
import { paramsToFilter } from './api.get_file_list'
14
import { getCommentFor } from './comments'
15
@@ -46,7 +46,9 @@ export async function zipStreamFromFolder(node: VfsNode, ctx: Koa.Context) {
46
if (nodeIsLink(el)) return
47
if (!hasPermission(el, 'can_archive', ctx)) return // the fact you see it doesn't mean you can get it
48
const { source } = el
49
- const name = getNodeName(el)
49
+ let name = getNodeName(el)
50
+ if (!IS_WINDOWS) // posix supports \ in file names, but zip tools don't
51
+ name = name.replaceAll('\\', '_')
52
if (filterName && !filterName(name)
53
|| filterComment && !filterComment(await getCommentFor(source) || ''))
54
return