fix: "get list" wasn't producing encoded URLs #436
Massimo Melina committed
Jan 8, 2024 at 09:41 UTC
0f94ccf5bbf62cab8f851a9eb80ca6423d74ef32
4 files changed
+12
-10
frontend/src/fileMenu.ts
+3
-2
@@ -1,9 +1,10 @@
1
import { t, useI18N } from './i18n'
2
-import { dontBotherWithKeys, formatBytes, getHFS, hfsEvent, hIcon, newDialog, prefix, with_, working } from './misc'
2
+import { dontBotherWithKeys, formatBytes, getHFS, hfsEvent, hIcon, newDialog, prefix, with_, working,
3
+ pathEncode } from './misc'
4
import { createElement as h, Fragment, isValidElement, MouseEvent, ReactNode } from 'react'
5
import _ from 'lodash'
6
import { getEntryIcon, MISSING_PERM } from './BrowseFiles'
6
-import { DirEntry, pathEncode, state } from './state'
7
+import { DirEntry, state } from './state'
8
import { deleteFiles } from './menu'
9
import { Link } from 'react-router-dom'
10
import { fileShow, getShowType } from './show'
frontend/src/state.ts
+1
-6
@@ -3,7 +3,7 @@
3
import _ from 'lodash'
4
import { proxy, useSnapshot } from 'valtio'
5
import { subscribeKey } from 'valtio/utils'
6
-import { FRONTEND_OPTIONS, getHFS, hIcon, objSameKeys, typedKeys } from './misc'
6
+import { FRONTEND_OPTIONS, getHFS, hIcon, objSameKeys, pathEncode, typedKeys } from './misc'
7
8
export const state = proxy<typeof FRONTEND_OPTIONS & {
9
stopSearch?: ()=>void,
@@ -137,11 +137,6 @@ export class DirEntry {
137
}
138
export type DirList = DirEntry[]
139
140
-export function pathEncode(s: string) {
141
- return encodeURI(s).replace(/#/g, encodeURIComponent)
142
-}
143
-//unused function pathDecode(s: string) { return decodeURI(s).replace(/%23/g, '#') }
144
-
140
const exts = {
141
image: ['jpeg','jpg','gif','png','webp','svg'],
142
audio: ['mp3','wav','m4a','ogg'],
src/cross.ts
+6
@@ -379,6 +379,12 @@ export async function promiseBestEffort<T>(promises: Promise<T>[]) {
379
return res.filter(x => x.status === 'fulfilled').map((x: any) => x.value as T)
380
}
381
382
+export function pathEncode(s: string) {
383
+ return encodeURI(s).replace(/#/g, encodeURIComponent)
384
+}
385
+//unused function pathDecode(s: string) { return decodeURI(s).replace(/%23/g, '#') }
386
+
387
+
388
// run at a specific point in time, also solving the limit of setTimeout, which doesn't work with +32bit delays
389
export function runAt(ts: number, cb: Callback) {
390
let cancel = false
src/serveGuiAndSharedFiles.ts
+2
-2
@@ -15,7 +15,7 @@ import { allowAdmin, favicon } from './adminApis'
15
import { serveGuiFiles } from './serveGuiFiles'
16
import mount from 'koa-mount'
17
import { baseUrl } from './listen'
18
-import { asyncGeneratorToReadable, filterMapGenerator } from './misc'
18
+import { asyncGeneratorToReadable, filterMapGenerator, pathEncode } from './misc'
19
20
const serveFrontendFiles = serveGuiFiles(process.env.FRONTEND_PROXY, FRONTEND_URI)
21
const serveFrontendPrefixed = mount(FRONTEND_URI.slice(0,-1), serveFrontendFiles)
@@ -115,7 +115,7 @@ async function sendFolderList(node: VfsNode, ctx: Koa.Context) {
115
ctx.body = asyncGeneratorToReadable(filterMapGenerator(walker, async el => {
116
const isFolder = await nodeIsDirectory(el)
117
return !folders && isFolder ? undefined
118
- : prepend + getNodeName(el) + (isFolder ? '/' : '') + '\n'
118
+ : prepend + pathEncode(getNodeName(el)) + (isFolder ? '/' : '') + '\n'
119
}))
120
}
121