🐛 Fix(custom): fix webdav backup bug for custom path close #347

This commit is contained in:
Kuingsmile
2025-07-18 17:00:58 +08:00
parent 2b23890a21
commit 64747887e1
5 changed files with 32 additions and 2 deletions

View File

@@ -141,7 +141,15 @@ async function uploadLocalToRemote(syncConfig: ISyncConfig, fileName: string) {
}
const client = createClient(webdavEndpointF, options)
const fileContent = fs.readFileSync(localFilePath)
const remoteFilePath = webdavSavePath ? path.join(webdavSavePath, fileName) : fileName
const remoteFilePath = webdavSavePath
? `${webdavSavePath}/${fileName}`.replace(/^\/+|\/+$/g, '').replace(/\/\/+/g, '/')
: fileName
console.log('remoteFilePath', remoteFilePath)
const remoteDir = path.dirname(remoteFilePath)
console.log('remoteDir', remoteDir)
if (remoteDir !== '/') {
await client.createDirectory(remoteDir, { recursive: true })
}
await client.putFileContents(remoteFilePath, fileContent, { overwrite: true })
return true
}
@@ -255,7 +263,13 @@ async function updateLocalToRemote(syncConfig: ISyncConfig, fileName: string) {
}
const client = createClient(webdavEndpointF, options)
const fileContent = fs.readFileSync(localFilePath)
const remoteFilePath = webdavSavePath ? path.join(webdavSavePath, fileName) : fileName
const remoteFilePath = webdavSavePath
? `${webdavSavePath}/${fileName}`.replace(/^\/+|\/+$/g, '').replace(/\/\/+/g, '/')
: fileName
const remoteDir = path.dirname(remoteFilePath)
if (remoteDir !== '/') {
await client.createDirectory(remoteDir, { recursive: true })
}
await client.putFileContents(remoteFilePath, fileContent, { overwrite: true })
return true
}