feat: add hostname retrieval for backup webdav (#5004)
fix #4705 Signed-off-by: ysicing <i@ysicing.me>
This commit is contained in:
parent
4fa04a801a
commit
53f74725ed
@ -129,6 +129,7 @@ export enum IpcChannel {
|
|||||||
|
|
||||||
// system
|
// system
|
||||||
System_GetDeviceType = 'system:getDeviceType',
|
System_GetDeviceType = 'system:getDeviceType',
|
||||||
|
System_GetHostname = 'system:getHostname',
|
||||||
|
|
||||||
// events
|
// events
|
||||||
SelectionAction = 'selection-action',
|
SelectionAction = 'selection-action',
|
||||||
|
|||||||
@ -58,6 +58,10 @@ if (!app.requestSingleInstanceLock()) {
|
|||||||
ipcMain.handle(IpcChannel.System_GetDeviceType, () => {
|
ipcMain.handle(IpcChannel.System_GetDeviceType, () => {
|
||||||
return process.platform === 'darwin' ? 'mac' : process.platform === 'win32' ? 'windows' : 'linux'
|
return process.platform === 'darwin' ? 'mac' : process.platform === 'win32' ? 'windows' : 'linux'
|
||||||
})
|
})
|
||||||
|
|
||||||
|
ipcMain.handle(IpcChannel.System_GetHostname, () => {
|
||||||
|
return require('os').hostname()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
registerProtocolClient(app)
|
registerProtocolClient(app)
|
||||||
|
|||||||
1
src/preload/index.d.ts
vendored
1
src/preload/index.d.ts
vendored
@ -34,6 +34,7 @@ declare global {
|
|||||||
clearCache: () => Promise<{ success: boolean; error?: string }>
|
clearCache: () => Promise<{ success: boolean; error?: string }>
|
||||||
system: {
|
system: {
|
||||||
getDeviceType: () => Promise<'mac' | 'windows' | 'linux'>
|
getDeviceType: () => Promise<'mac' | 'windows' | 'linux'>
|
||||||
|
getHostname: () => Promise<string>
|
||||||
}
|
}
|
||||||
zip: {
|
zip: {
|
||||||
compress: (text: string) => Promise<Buffer>
|
compress: (text: string) => Promise<Buffer>
|
||||||
|
|||||||
@ -23,7 +23,8 @@ const api = {
|
|||||||
openWebsite: (url: string) => ipcRenderer.invoke(IpcChannel.Open_Website, url),
|
openWebsite: (url: string) => ipcRenderer.invoke(IpcChannel.Open_Website, url),
|
||||||
clearCache: () => ipcRenderer.invoke(IpcChannel.App_ClearCache),
|
clearCache: () => ipcRenderer.invoke(IpcChannel.App_ClearCache),
|
||||||
system: {
|
system: {
|
||||||
getDeviceType: () => ipcRenderer.invoke(IpcChannel.System_GetDeviceType)
|
getDeviceType: () => ipcRenderer.invoke(IpcChannel.System_GetDeviceType),
|
||||||
|
getHostname: () => ipcRenderer.invoke(IpcChannel.System_GetHostname)
|
||||||
},
|
},
|
||||||
zip: {
|
zip: {
|
||||||
compress: (text: string) => ipcRenderer.invoke(IpcChannel.Zip_Compress, text),
|
compress: (text: string) => ipcRenderer.invoke(IpcChannel.Zip_Compress, text),
|
||||||
|
|||||||
@ -42,8 +42,9 @@ export function useWebdavBackupModal({ backupMethod }: { backupMethod?: typeof b
|
|||||||
const showBackupModal = useCallback(async () => {
|
const showBackupModal = useCallback(async () => {
|
||||||
// 获取默认文件名
|
// 获取默认文件名
|
||||||
const deviceType = await window.api.system.getDeviceType()
|
const deviceType = await window.api.system.getDeviceType()
|
||||||
|
const hostname = await window.api.system.getHostname()
|
||||||
const timestamp = dayjs().format('YYYYMMDDHHmmss')
|
const timestamp = dayjs().format('YYYYMMDDHHmmss')
|
||||||
const defaultFileName = `cherry-studio.${timestamp}.${deviceType}.zip`
|
const defaultFileName = `cherry-studio.${timestamp}.${hostname}.${deviceType}.zip`
|
||||||
setCustomFileName(defaultFileName)
|
setCustomFileName(defaultFileName)
|
||||||
setIsModalVisible(true)
|
setIsModalVisible(true)
|
||||||
}, [])
|
}, [])
|
||||||
|
|||||||
@ -84,13 +84,15 @@ export async function backupToWebdav({
|
|||||||
|
|
||||||
const { webdavHost, webdavUser, webdavPass, webdavPath } = store.getState().settings
|
const { webdavHost, webdavUser, webdavPass, webdavPath } = store.getState().settings
|
||||||
let deviceType = 'unknown'
|
let deviceType = 'unknown'
|
||||||
|
let hostname = 'unknown'
|
||||||
try {
|
try {
|
||||||
deviceType = (await window.api.system.getDeviceType()) || 'unknown'
|
deviceType = (await window.api.system.getDeviceType()) || 'unknown'
|
||||||
|
hostname = (await window.api.system.getHostname()) || 'unknown'
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
Logger.error('[Backup] Failed to get device type:', error)
|
Logger.error('[Backup] Failed to get device type or hostname:', error)
|
||||||
}
|
}
|
||||||
const timestamp = dayjs().format('YYYYMMDDHHmmss')
|
const timestamp = dayjs().format('YYYYMMDDHHmmss')
|
||||||
const backupFileName = customFileName || `cherry-studio.${timestamp}.${deviceType}.zip`
|
const backupFileName = customFileName || `cherry-studio.${timestamp}.${deviceType}.${hostname}.zip`
|
||||||
const finalFileName = backupFileName.endsWith('.zip') ? backupFileName : `${backupFileName}.zip`
|
const finalFileName = backupFileName.endsWith('.zip') ? backupFileName : `${backupFileName}.zip`
|
||||||
const backupData = await getBackupData()
|
const backupData = await getBackupData()
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user