@samitouri / QOSami-HFS / commits / aa23f8d4

fix: webdav was not supporting "roots" feature

Massimo Melina committed Mar 9, 2026 at 20:28 UTC aa23f8d4152844848dc3938451645a58818a29f3
2 files changed +3 -3
src/roots.ts
+1 -1
@@ -11,7 +11,7 @@ import _ from 'lodash'
11 export const roots = defineConfig(CFG.roots, {} as { [hostMask: string]: string }, map => {
12 const list = Object.keys(map)
13 const matchers = list.map(hostMask => makeMatcher(hostMask))
14 - const values = Object.values(map).map(x => enforceFinal('/', enforceStarting('/', x)))
14 + const values = Object.values(map).map(x => enforceFinal('/', enforceStarting('/', x.replace(/\/{2,}/g, '/'))))
15 return (host: string) => values[matchers.findIndex(m => m(host))]
16 })
17 const forceAddress = defineConfig(CFG.force_address, false)
src/webdav.ts
+2 -2
@@ -240,7 +240,7 @@ export async function handledWebdav(ctx: Koa.Context) {
240 }
241 ctx.type = 'xml'
242 ctx.status = 207
243 - const pathSlash = enforceFinal('/', path)
243 + const outPath = enforceFinal('/', path.slice(Math.max(0, (ctx.state.root?.length ?? 0) - 1)), true)
244 const res = ctx.body = new PassThrough({ encoding: 'utf8' })
245 res.write(`<?xml version="1.0" encoding="utf-8" ?><multistatus xmlns="DAV:">`)
246 await sendEntry(node)
@@ -259,7 +259,7 @@ export async function handledWebdav(ctx: Koa.Context) {
259 const isDir = await nodeIsFolder(node)
260 const st = await nodeStats(node)
261 res.write(`<response>
262 - <href>${pathSlash + (append ? pathEncode(name, true) + (isDir ? '/' : '') : '')}</href>
262 + <href>${outPath + (append ? pathEncode(name, true) + (isDir ? '/' : '') : '')}</href>
263 <propstat>
264 <status>HTTP/1.1 200 OK</status>
265 <prop>