get=list auto detection mode

Massimo Melina committed May 9, 2023 at 10:22 UTC 9d9ff741727b20c43de4f55bcf5ba51480b9b651
2 files changed +10 -2
frontend/src/fileMenu.ts
+1 -1
@@ -17,7 +17,7 @@ export function openFileMenu(entry: DirEntry, ev: MouseEvent, addToMenu: FileMen
17 const menu = [
18 !cantDownload && { label: t`Download`, href: uri + (isFolder ? '?get=zip' : '?dl'), icon: 'download' },
19 ...addToMenu,
20 - isFolder && { label: t`Get list`, href: uri + '?get=list&folders=*&prepend=' + encodeURIComponent(location.href + uri), icon: 'menu' }
20 + isFolder && { label: t`Get list`, href: uri + '?get=list&folders=*', icon: 'menu' }
21 ]
22 const props = [
23 [t(`Name`), entry.name]
src/middlewares.ts
+9 -1
@@ -149,9 +149,17 @@ export const serveGuiAndSharedFiles: Koa.Middleware = async (ctx, next) => {
149 : serveFrontendFiles(ctx, next)
150 }
151
152 +const baseUrl = defineConfig('base_url', '')
153 +
154 async function sendFolderList(node: VfsNode, ctx: Koa.Context) {
153 - const { depth=0, folders, prepend='' } = ctx.query
155 + let { depth=0, folders, prepend } = ctx.query
156 ctx.type = 'text'
157 + if (prepend === undefined || prepend === '*') { // * = force auto-detection even if we have baseUrl set
158 + const { URL } = ctx
159 + const base = prepend === undefined && baseUrl.get()
160 + || URL.protocol + '//' + URL.host + ctx.state.revProxyPath
161 + prepend = base + ctx.originalUrl.split('?')[0]! as string
162 + }
163 const walker = walkNode(node, ctx, depth === '*' ? Infinity : Number(depth))
164 ctx.body = asyncGeneratorToReadable(filterMapGenerator(walker, async el => {
165 const isFolder = await nodeIsDirectory(el)