From 4e60f4fcca8fbd546591446e98927ac8e6d992ab Mon Sep 17 00:00:00 2001 From: clown145 Date: Thu, 18 Jun 2026 15:59:37 +0800 Subject: [PATCH] fix(webdav): return 404 in handlePropfind for non-existent paths to prevent FileAlreadyExistsException in clients --- functions/dav/[[path]].js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/functions/dav/[[path]].js b/functions/dav/[[path]].js index 350fc84a..f4c00329 100644 --- a/functions/dav/[[path]].js +++ b/functions/dav/[[path]].js @@ -273,6 +273,25 @@ async function handlePropfind(request, env) { } } + // 检查请求路径是否为目录 + let isDir = false; + if (path === '/') { + isDir = true; + } else { + const dir = path.startsWith('/') ? path.substring(1) : path; + const cleanDir = dir.endsWith('/') ? dir : dir + '/'; + // 如果数据库中存在以当前路径为前缀的键,说明目录存在 + const listResponse = await db.list({ prefix: cleanDir, limit: 1 }); + if (listResponse.keys && listResponse.keys.length > 0) { + isDir = true; + } + } + + // 如果路径既不是文件也不是目录,直接返回 404 + if (!isFile && !isDir) { + return new Response('Not Found', { status: 404 }); + } + let xml; if (isFile) { xml = `${createFileXml(fileInfo)}`;