mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-05-18 02:27:35 +08:00
✨ Feature(custom): add new config field temp dir path
ISSUES CLOSED: #112
This commit is contained in:
@@ -67,6 +67,13 @@ export const manageIpcList = {
|
||||
return res
|
||||
})
|
||||
|
||||
ipcMain.handle('openDirectorySelectDialog', async () => {
|
||||
const res = await dialog.showOpenDialog({
|
||||
properties: ['openDirectory']
|
||||
})
|
||||
return res.filePaths[0]
|
||||
})
|
||||
|
||||
ipcMain.handle('openFileSelectDialog', async () => {
|
||||
const res = await dialog.showOpenDialog({
|
||||
properties: ['openFile', 'multiSelections']
|
||||
|
||||
@@ -48,8 +48,18 @@ export function isInputConfigValid (config: any): boolean {
|
||||
|
||||
export const getFileMimeType = (filePath: string): string => mime.lookup(filePath) || 'application/octet-stream'
|
||||
|
||||
const checkTempFolderExist = async () => {
|
||||
const tempPath = path.join(app.getPath('downloads'), 'piclistTemp')
|
||||
const getTempDirPath = () => {
|
||||
const defaultPath = path.join(app.getPath('downloads'), 'piclistTemp')
|
||||
try {
|
||||
const configFilePath = path.join(app.getPath('userData'), 'data.json')
|
||||
const { settings: { tempDirPath = '' } = {} } = fs.readJSONSync(configFilePath) || {}
|
||||
return tempDirPath ? path.join(tempDirPath, 'piclistTemp') : defaultPath
|
||||
} catch (e) {
|
||||
return defaultPath
|
||||
}
|
||||
}
|
||||
|
||||
const checkTempFolderExist = async (tempPath: string) => {
|
||||
try {
|
||||
await fs.access(tempPath)
|
||||
} catch (e) {
|
||||
@@ -58,8 +68,8 @@ const checkTempFolderExist = async () => {
|
||||
}
|
||||
|
||||
export const downloadFileFromUrl = async (urls: string[]) => {
|
||||
const tempPath = path.join(app.getPath('downloads'), 'piclistTemp')
|
||||
await checkTempFolderExist()
|
||||
const tempPath = getTempDirPath()
|
||||
await checkTempFolderExist(tempPath)
|
||||
const result = [] as string[]
|
||||
for (let i = 0; i < urls.length; i++) {
|
||||
const finishDownload = promisify(Stream.finished)
|
||||
@@ -78,7 +88,7 @@ export const downloadFileFromUrl = async (urls: string[]) => {
|
||||
return result
|
||||
}
|
||||
|
||||
export const clearTempFolder = () => fs.emptyDirSync(path.join(app.getPath('downloads'), 'piclistTemp'))
|
||||
export const clearTempFolder = () => fs.emptyDirSync(getTempDirPath())
|
||||
|
||||
export const md5 = (str: string, code: 'hex' | 'base64'): string => crypto.createHash('md5').update(str).digest(code)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user