()
| 284 | } |
| 285 | |
| 286 | async function addOpenlistInRclone() { |
| 287 | const webdavUrl = openlistInfo.endpoint.url + '/dav' |
| 288 | const username = nmConfig.framework.openlist.user |
| 289 | const password = nmConfig.framework.openlist.password |
| 290 | const storageName = openlistInfo.markInRclone |
| 291 | |
| 292 | console.log('=== OpenList WebDAV Configuration ===') |
| 293 | console.log('Storage name:', storageName) |
| 294 | console.log('WebDAV URL:', webdavUrl) |
| 295 | console.log('WebDAV Username:', username) |
| 296 | console.log('Note: WebDAV password is the same as Web UI login password') |
| 297 | |
| 298 | // 可选:探测 WebDAV 端点以提供诊断信息 |
| 299 | try { |
| 300 | const probeRes = await fetch(webdavUrl, { |
| 301 | method: 'OPTIONS', |
| 302 | headers: { |
| 303 | Authorization: 'Basic ' + btoa(username + ':' + password), |
| 304 | }, |
| 305 | }) |
| 306 | console.log('WebDAV probe HTTP status:', probeRes.status) |
| 307 | if (probeRes.status === 401) { |
| 308 | console.warn( |
| 309 | 'WebDAV returned 401 - Please check if user has WebDAV Read/Management permissions enabled' |
| 310 | ) |
| 311 | } else if (probeRes.status === 403) { |
| 312 | console.warn('WebDAV returned 403 - Please check if user has necessary file permissions') |
| 313 | } else if (probeRes.ok || probeRes.status === 207) { |
| 314 | console.log('WebDAV endpoint appears to be accessible') |
| 315 | } |
| 316 | } catch (probeError) { |
| 317 | console.warn('WebDAV probe failed (this is normal if server is still starting):', probeError) |
| 318 | } |
| 319 | console.log('=====================================') |
| 320 | |
| 321 | // 先删除可能存在的旧配置(避免端口不一致问题) |
| 322 | console.log('Deleting old rclone storage config if exists...') |
| 323 | try { |
| 324 | await rclone_api_post('/config/delete', { name: storageName }, true) |
| 325 | console.log('Old storage config deleted (or did not exist)') |
| 326 | } catch (e) { |
| 327 | // 配置可能不存在,忽略错误 |
| 328 | console.log('No old config to delete or delete failed:', e) |
| 329 | } |
| 330 | |
| 331 | // 短暂延迟确保删除生效 |
| 332 | await new Promise(resolve => setTimeout(resolve, 500)) |
| 333 | |
| 334 | console.log('Creating new rclone storage with updated WebDAV URL...') |
| 335 | // 使用 opt.obscure = true 告诉 rclone 密码是明文需要混淆 |
| 336 | await createStorage( |
| 337 | storageName, |
| 338 | 'webdav', |
| 339 | { |
| 340 | url: webdavUrl, |
| 341 | vendor: 'other', |
| 342 | user: username, |
| 343 | pass: password, |
no test coverage detected