diff --git a/changelog.md b/changelog.md index 115a116..102d774 100644 --- a/changelog.md +++ b/changelog.md @@ -1,4 +1,9 @@ +### New Features + +- 支持自定义 WebDAV 备份目录名称 + ### Bug Fixes - 修复 macOS 自动更新失败的问题 +- 修复订阅点击无法切换的问题 - 修复某些 Windows 管理员权限依然无法启动的问题 diff --git a/src/main/resolve/backup.ts b/src/main/resolve/backup.ts index f0119c4..c0a7973 100644 --- a/src/main/resolve/backup.ts +++ b/src/main/resolve/backup.ts @@ -15,7 +15,12 @@ import { export async function webdavBackup(): Promise { const { createClient } = await import('webdav/dist/node/index.js') - const { webdavUrl = '', webdavUsername = '', webdavPassword = '' } = await getAppConfig() + const { + webdavUrl = '', + webdavUsername = '', + webdavPassword = '', + webdavDir = 'mihomo-party' + } = await getAppConfig() const zip = new AdmZip() zip.addLocalFile(appConfigPath()) @@ -34,36 +39,46 @@ export async function webdavBackup(): Promise { password: webdavPassword }) try { - await client.createDirectory('mihomo-party') + await client.createDirectory(webdavDir) } catch { // ignore } - return await client.putFileContents(`mihomo-party/${zipFileName}`, zip.toBuffer()) + return await client.putFileContents(`${webdavDir}/${zipFileName}`, zip.toBuffer()) } export async function webdavRestore(filename: string): Promise { const { createClient } = await import('webdav/dist/node/index.js') - const { webdavUrl = '', webdavUsername = '', webdavPassword = '' } = await getAppConfig() + const { + webdavUrl = '', + webdavUsername = '', + webdavPassword = '', + webdavDir = 'mihomo-party' + } = await getAppConfig() const client = createClient(webdavUrl, { username: webdavUsername, password: webdavPassword }) - const zipData = await client.getFileContents(`mihomo-party/${filename}`) + const zipData = await client.getFileContents(`${webdavDir}/${filename}`) const zip = new AdmZip(zipData as Buffer) zip.extractAllTo(dataDir(), true) } export async function listWebdavBackups(): Promise { const { createClient } = await import('webdav/dist/node/index.js') - const { webdavUrl = '', webdavUsername = '', webdavPassword = '' } = await getAppConfig() + const { + webdavUrl = '', + webdavUsername = '', + webdavPassword = '', + webdavDir = 'mihomo-party' + } = await getAppConfig() const client = createClient(webdavUrl, { username: webdavUsername, password: webdavPassword }) - const files = await client.getDirectoryContents('mihomo-party', { glob: '*.zip' }) + const files = await client.getDirectoryContents(webdavDir, { glob: '*.zip' }) if (Array.isArray(files)) { return files.map((file) => file.basename) } else { @@ -73,11 +88,16 @@ export async function listWebdavBackups(): Promise { export async function webdavDelete(filename: string): Promise { const { createClient } = await import('webdav/dist/node/index.js') - const { webdavUrl = '', webdavUsername = '', webdavPassword = '' } = await getAppConfig() + const { + webdavUrl = '', + webdavUsername = '', + webdavPassword = '', + webdavDir = 'mihomo-party' + } = await getAppConfig() const client = createClient(webdavUrl, { username: webdavUsername, password: webdavPassword }) - await client.deleteFile(`mihomo-party/${filename}`) + await client.deleteFile(`${webdavDir}/${filename}`) } diff --git a/src/renderer/src/components/settings/webdav-config.tsx b/src/renderer/src/components/settings/webdav-config.tsx index bf29663..c419794 100644 --- a/src/renderer/src/components/settings/webdav-config.tsx +++ b/src/renderer/src/components/settings/webdav-config.tsx @@ -9,15 +9,15 @@ import { useAppConfig } from '@renderer/hooks/use-app-config' const WebdavConfig: React.FC = () => { const { appConfig, patchAppConfig } = useAppConfig() - const { webdavUrl, webdavUsername, webdavPassword } = appConfig || {} + const { webdavUrl, webdavUsername, webdavPassword, webdavDir = 'mihomo-party' } = appConfig || {} const [backuping, setBackuping] = useState(false) const [restoring, setRestoring] = useState(false) const [filenames, setFilenames] = useState([]) const [restoreOpen, setRestoreOpen] = useState(false) - const [webdav, setWebdav] = useState({ webdavUrl, webdavUsername, webdavPassword }) - const setWebdavDebounce = debounce(({ webdavUrl, webdavUsername, webdavPassword }) => { - patchAppConfig({ webdavUrl, webdavUsername, webdavPassword }) + const [webdav, setWebdav] = useState({ webdavUrl, webdavUsername, webdavPassword, webdavDir }) + const setWebdavDebounce = debounce(({ webdavUrl, webdavUsername, webdavPassword, webdavDir }) => { + patchAppConfig({ webdavUrl, webdavUsername, webdavPassword, webdavDir }) }, 500) const handleBackup = async (): Promise => { setBackuping(true) @@ -60,6 +60,17 @@ const WebdavConfig: React.FC = () => { }} /> + + { + setWebdav({ ...webdav, webdavDir: v }) + setWebdavDebounce({ ...webdav, webdavDir: v }) + }} + /> +