Skip to content

Commit d2c1fdc

Browse files
committed
fix: 添加safari兼容性和详细日志用于调试webdav问题
1 parent a25572b commit d2c1fdc

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

api/webdav-proxy.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ module.exports = async (req, res) => {
2121
try {
2222
const { url, method, username, password, data } = req.body;
2323

24+
console.log(`[WebDAV] ${method} request to ${url}`);
25+
2426
if (!url || !method || !username || !password) {
27+
console.error('[WebDAV] Missing required parameters');
2528
return res.writeHead(400).end(JSON.stringify({ error: '缺少必要参数' }));
2629
}
2730

@@ -65,15 +68,18 @@ module.exports = async (req, res) => {
6568
const statusCode = proxyRes.statusCode;
6669
const isSuccess = (statusCode >= 200 && statusCode < 300) || statusCode === 207;
6770

71+
console.log(`[WebDAV] Response ${statusCode}, Success: ${isSuccess}`);
72+
6873
let errorMsg = null;
6974
if (!isSuccess) {
7075
errorMsg = `HTTP ${statusCode} - ${url}`;
7176
if (responseData) {
77+
console.error(`[WebDAV] Error response: ${responseData.substring(0, 500)}`);
7278
errorMsg += ` | Response: ${responseData.substring(0, 200)}`;
7379
}
7480
}
7581

76-
res.writeHead(200).end(JSON.stringify({
82+
res.writeHead(200, { 'Content-Type': 'application/json' }).end(JSON.stringify({
7783
success: isSuccess,
7884
status: statusCode,
7985
data: responseData,

src/utils/webdav.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,36 @@ export function saveWebDAVConfig(config: WebDAVConfig): void {
1919

2020
async function webdavRequest(config: WebDAVConfig, method: string, data?: string) {
2121
const url = `${config.url.replace(/\/$/, '')}/${WEBDAV_FILE_NAME}`
22+
23+
console.log(`[WebDAV Client] Sending ${method} request to ${url}`)
24+
2225
const res = await fetch('/api/webdav-proxy', {
2326
method: 'POST',
2427
headers: { 'Content-Type': 'application/json' },
2528
body: JSON.stringify({ url, method, username: config.username, password: config.password, data }),
29+
credentials: 'same-origin', // Safari 兼容性
2630
})
31+
32+
console.log(`[WebDAV Client] Proxy response status: ${res.status}`)
33+
34+
if (!res.ok) {
35+
const text = await res.text()
36+
console.error(`[WebDAV Client] Proxy error response: ${text}`)
37+
throw new Error(`代理服务器错误: ${res.status}`)
38+
}
39+
2740
const result = await res.json()
28-
if (!result.success)
29-
throw new Error(result.error || '请求失败')
41+
console.log(`[WebDAV Client] Result:`, result)
42+
43+
if (!result.success) {
44+
const error = result.error || '请求失败'
45+
console.error(`[WebDAV Client] Request failed:`, error)
46+
if (error.includes('quota') || error.includes('exceeded'))
47+
throw new Error('存储配额已满,请清理空间或升级账户')
48+
if (error.includes('509'))
49+
throw new Error('流量配额已用完,请等待下月重置或升级账户')
50+
throw new Error(error)
51+
}
3052
return result
3153
}
3254

0 commit comments

Comments
 (0)