mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-05-28 19:50:22 +08:00
🔨 Refactor(custom): refactored manage page ipc
This commit is contained in:
@@ -10,6 +10,7 @@ import { systemRouter } from '~/events/rpc/routes/system'
|
||||
import { toolboxRouter } from '~/events/rpc/routes/toolbox'
|
||||
import { trayRouter } from '~/events/rpc/routes/tray'
|
||||
import { uploadRouter } from '~/events/rpc/routes/upload'
|
||||
import { manageRouter } from '~/events/rpc/routes/manage'
|
||||
|
||||
import { IRPCActionType, IRPCType } from '#/types/enum'
|
||||
import { RPC_ACTIONS, RPC_ACTIONS_INVOKE } from '#/events/constants'
|
||||
@@ -75,7 +76,8 @@ const routes = [
|
||||
systemRouter.routes(),
|
||||
toolboxRouter.routes(),
|
||||
trayRouter.routes(),
|
||||
uploadRouter.routes()
|
||||
uploadRouter.routes(),
|
||||
manageRouter.routes()
|
||||
]
|
||||
|
||||
for (const route of routes) {
|
||||
|
||||
100
src/main/events/rpc/routes/manage/bucket.ts
Normal file
100
src/main/events/rpc/routes/manage/bucket.ts
Normal file
@@ -0,0 +1,100 @@
|
||||
import { ManageApi } from '~/manage/manageApi'
|
||||
|
||||
import { IRPCActionType, IRPCType } from '#/types/enum'
|
||||
|
||||
export default [
|
||||
{
|
||||
action: IRPCActionType.MANAGE_GET_BUCKET_LIST,
|
||||
handler: async (_: IIPCEvent, args: [currentPicBed: string]) => {
|
||||
return new ManageApi(args[0]).getBucketList()
|
||||
},
|
||||
type: IRPCType.INVOKE
|
||||
},
|
||||
{
|
||||
action: IRPCActionType.MANAGE_GET_BUCKET_LIST_BACKSTAGE,
|
||||
handler: async (_: IIPCEvent, args: [currentPicBed: string, param: IStringKeyMap]) => {
|
||||
return new ManageApi(args[0]).getBucketListBackstage(args[1])
|
||||
}
|
||||
},
|
||||
{
|
||||
action: IRPCActionType.MANAGE_GET_BUCKET_LIST_RECURSIVELY,
|
||||
handler: async (_: IIPCEvent, args: [currentPicBed: string, param: IStringKeyMap]) => {
|
||||
return new ManageApi(args[0]).getBucketListRecursively(args[1])
|
||||
}
|
||||
},
|
||||
{
|
||||
action: IRPCActionType.MANAGE_CREATE_BUCKET,
|
||||
handler: async (_: IIPCEvent, args: [currentPicBed: string, param: IStringKeyMap]) => {
|
||||
return new ManageApi(args[0]).createBucket(args[1])
|
||||
},
|
||||
type: IRPCType.INVOKE
|
||||
},
|
||||
{
|
||||
action: IRPCActionType.MANAGE_GET_BUCKET_FILE_LIST,
|
||||
handler: async (_: IIPCEvent, args: [currentPicBed: string, param: IStringKeyMap]) => {
|
||||
return new ManageApi(args[0]).getBucketFileList(args[1])
|
||||
},
|
||||
type: IRPCType.INVOKE
|
||||
},
|
||||
{
|
||||
action: IRPCActionType.MANAGE_GET_BUCKET_DOMAIN,
|
||||
handler: async (_: IIPCEvent, args: [currentPicBed: string, param: IStringKeyMap]) => {
|
||||
return new ManageApi(args[0]).getBucketDomain(args[1])
|
||||
},
|
||||
type: IRPCType.INVOKE
|
||||
},
|
||||
{
|
||||
action: IRPCActionType.MANAGE_SET_BUCKET_ACL_POLICY,
|
||||
handler: async (_: IIPCEvent, args: [currentPicBed: string, param: IStringKeyMap]) => {
|
||||
return new ManageApi(args[0]).setBucketAclPolicy(args[1])
|
||||
},
|
||||
type: IRPCType.INVOKE
|
||||
},
|
||||
{
|
||||
action: IRPCActionType.MANAGE_RENAME_BUCKET_FILE,
|
||||
handler: async (_: IIPCEvent, args: [currentPicBed: string, param: IStringKeyMap]) => {
|
||||
return new ManageApi(args[0]).renameBucketFile(args[1])
|
||||
},
|
||||
type: IRPCType.INVOKE
|
||||
},
|
||||
{
|
||||
action: IRPCActionType.MANAGE_DELETE_BUCKET_FILE,
|
||||
handler: async (_: IIPCEvent, args: [currentPicBed: string, param: IStringKeyMap]) => {
|
||||
return new ManageApi(args[0]).deleteBucketFile(args[1])
|
||||
},
|
||||
type: IRPCType.INVOKE
|
||||
},
|
||||
{
|
||||
action: IRPCActionType.MANAGE_DELETE_BUCKET_FOLDER,
|
||||
handler: async (_: IIPCEvent, args: [currentPicBed: string, param: IStringKeyMap]) => {
|
||||
return new ManageApi(args[0]).deleteBucketFolder(args[1])
|
||||
},
|
||||
type: IRPCType.INVOKE
|
||||
},
|
||||
{
|
||||
action: IRPCActionType.MANAGE_GET_PRE_SIGNED_URL,
|
||||
handler: async (_: IIPCEvent, args: [currentPicBed: string, param: IStringKeyMap]) => {
|
||||
return new ManageApi(args[0]).getPreSignedUrl(args[1])
|
||||
},
|
||||
type: IRPCType.INVOKE
|
||||
},
|
||||
{
|
||||
action: IRPCActionType.MANAGE_UPLOAD_BUCKET_FILE,
|
||||
handler: async (_: IIPCEvent, args: [currentPicBed: string, param: IStringKeyMap]) => {
|
||||
return new ManageApi(args[0]).uploadBucketFile(args[1])
|
||||
}
|
||||
},
|
||||
{
|
||||
action: IRPCActionType.MANAGE_DOWNLOAD_BUCKET_FILE,
|
||||
handler: async (_: IIPCEvent, args: [currentPicBed: string, param: IStringKeyMap]) => {
|
||||
return new ManageApi(args[0]).downloadBucketFile(args[1])
|
||||
}
|
||||
},
|
||||
{
|
||||
action: IRPCActionType.MANAGE_CREATE_BUCKET_FOLDER,
|
||||
handler: async (_: IIPCEvent, args: [currentPicBed: string, param: IStringKeyMap]) => {
|
||||
return new ManageApi(args[0]).createBucketFolder(args[1])
|
||||
},
|
||||
type: IRPCType.INVOKE
|
||||
}
|
||||
]
|
||||
26
src/main/events/rpc/routes/manage/config.ts
Normal file
26
src/main/events/rpc/routes/manage/config.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { IRPCActionType, IRPCType } from '#/types/enum'
|
||||
import getManageApi from '~/manage/Main'
|
||||
|
||||
const manageApi = getManageApi()
|
||||
|
||||
export default [
|
||||
{
|
||||
action: IRPCActionType.MANAGE_GET_CONFIG,
|
||||
handler: async (_: IIPCEvent, args: [key?: string]) => {
|
||||
return manageApi.getConfig(args[0])
|
||||
},
|
||||
type: IRPCType.INVOKE
|
||||
},
|
||||
{
|
||||
action: IRPCActionType.MANAGE_SAVE_CONFIG,
|
||||
handler: async (_: IIPCEvent, args: [data: IObj]) => {
|
||||
manageApi.saveConfig(args[0])
|
||||
}
|
||||
},
|
||||
{
|
||||
action: IRPCActionType.MANAGE_REMOVE_CONFIG,
|
||||
handler: async (_: IIPCEvent, args: [key: string, propName: string]) => {
|
||||
manageApi.removeConfig(args[0], args[1])
|
||||
}
|
||||
}
|
||||
]
|
||||
13
src/main/events/rpc/routes/manage/index.ts
Normal file
13
src/main/events/rpc/routes/manage/index.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { RPCRouter } from '~/events/rpc/router'
|
||||
|
||||
import configRoutes from '~/events/rpc/routes/manage/config'
|
||||
import bucketRoutes from '~/events/rpc/routes/manage/bucket'
|
||||
import upDownLoadRoutes from '~/events/rpc/routes/manage/upDownload'
|
||||
|
||||
const manageRouter = new RPCRouter()
|
||||
|
||||
const manageRoutes = [...configRoutes, ...bucketRoutes, ...upDownLoadRoutes]
|
||||
|
||||
manageRouter.addBatch(manageRoutes)
|
||||
|
||||
export { manageRouter }
|
||||
108
src/main/events/rpc/routes/manage/upDownload.ts
Normal file
108
src/main/events/rpc/routes/manage/upDownload.ts
Normal file
@@ -0,0 +1,108 @@
|
||||
import { app, dialog, shell } from 'electron'
|
||||
import fs from 'fs-extra'
|
||||
import path from 'path'
|
||||
|
||||
import { IRPCActionType, IRPCType } from '#/types/enum'
|
||||
|
||||
import UpDownTaskQueue from '~/manage/datastore/upDownTaskQueue'
|
||||
import { downloadFileFromUrl } from '~/manage/utils/common'
|
||||
|
||||
export default [
|
||||
{
|
||||
action: IRPCActionType.MANAGE_OPEN_FILE_SELECT_DIALOG,
|
||||
handler: async () => {
|
||||
const res = await dialog.showOpenDialog({
|
||||
properties: ['openFile', 'multiSelections']
|
||||
})
|
||||
return res.canceled ? [] : res.filePaths
|
||||
},
|
||||
type: IRPCType.INVOKE
|
||||
},
|
||||
{
|
||||
action: IRPCActionType.MANAGE_GET_UPLOAD_TASK_LIST,
|
||||
handler: async () => {
|
||||
return UpDownTaskQueue.getInstance().getAllUploadTask()
|
||||
},
|
||||
type: IRPCType.INVOKE
|
||||
},
|
||||
{
|
||||
action: IRPCActionType.MANAGE_GET_DOWNLOAD_TASK_LIST,
|
||||
handler: async () => {
|
||||
return UpDownTaskQueue.getInstance().getAllDownloadTask()
|
||||
},
|
||||
type: IRPCType.INVOKE
|
||||
},
|
||||
{
|
||||
action: IRPCActionType.MANAGE_DELETE_UPLOADED_TASK,
|
||||
handler: async () => {
|
||||
UpDownTaskQueue.getInstance().removeUploadedTask()
|
||||
}
|
||||
},
|
||||
{
|
||||
action: IRPCActionType.MANAGE_DELETE_ALL_UPLOADED_TASK,
|
||||
handler: async () => {
|
||||
UpDownTaskQueue.getInstance().clearUploadTaskQueue()
|
||||
}
|
||||
},
|
||||
{
|
||||
action: IRPCActionType.MANAGE_DELETE_DOWNLOADED_TASK,
|
||||
handler: async () => {
|
||||
UpDownTaskQueue.getInstance().removeDownloadedTask()
|
||||
}
|
||||
},
|
||||
{
|
||||
action: IRPCActionType.MANAGE_DELETE_ALL_DOWNLOADED_TASK,
|
||||
handler: async () => {
|
||||
UpDownTaskQueue.getInstance().clearDownloadTaskQueue()
|
||||
}
|
||||
},
|
||||
{
|
||||
action: IRPCActionType.MANAGE_SELECT_DOWNLOAD_FOLDER,
|
||||
handler: async () => {
|
||||
const res = await dialog.showOpenDialog({
|
||||
properties: ['openDirectory']
|
||||
})
|
||||
return res.filePaths[0]
|
||||
},
|
||||
type: IRPCType.INVOKE
|
||||
},
|
||||
{
|
||||
action: IRPCActionType.MANAGE_GET_DEFAULT_DOWNLOAD_FOLDER,
|
||||
handler: async () => {
|
||||
return app.getPath('downloads')
|
||||
},
|
||||
type: IRPCType.INVOKE
|
||||
},
|
||||
{
|
||||
action: IRPCActionType.MANAGE_OPEN_DOWNLOADED_FOLDER,
|
||||
handler: async (_: IIPCEvent, args: [path?: string]) => {
|
||||
const path = args[0]
|
||||
if (path) {
|
||||
shell.showItemInFolder(path)
|
||||
} else {
|
||||
shell.openPath(app.getPath('downloads'))
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
action: IRPCActionType.MANAGE_OPEN_LOCAL_FILE,
|
||||
handler: async (_: IIPCEvent, args: [fullPath: string]) => {
|
||||
const fullPath = args[0]
|
||||
fs.existsSync(fullPath) ? shell.showItemInFolder(fullPath) : shell.openPath(path.dirname(fullPath))
|
||||
}
|
||||
},
|
||||
{
|
||||
action: IRPCActionType.MANAGE_DOWNLOAD_FILE_FROM_URL,
|
||||
handler: async (_: IIPCEvent, args: [urls: string[]]) => {
|
||||
return await downloadFileFromUrl(args[0])
|
||||
},
|
||||
type: IRPCType.INVOKE
|
||||
},
|
||||
{
|
||||
action: IRPCActionType.MANAGE_CONVERT_PATH_TO_BASE64,
|
||||
handler: async (_: IIPCEvent, args: [filePath: string]) => {
|
||||
return fs.readFileSync(args[0], 'base64')
|
||||
},
|
||||
type: IRPCType.INVOKE
|
||||
}
|
||||
]
|
||||
@@ -22,7 +22,6 @@ import { T } from '~/i18n'
|
||||
import '~/lifeCycle/errorHandler'
|
||||
import fixPath from '~/lifeCycle/fixPath'
|
||||
import UpDownTaskQueue from '~/manage/datastore/upDownTaskQueue'
|
||||
import { manageIpcList } from '~/manage/events/ipcList'
|
||||
import getManageApi from '~/manage/Main'
|
||||
import { clearTempFolder } from '~/manage/utils/common'
|
||||
import server from '~/server/index'
|
||||
@@ -143,11 +142,10 @@ class LifeCycle {
|
||||
// fix the $PATH in macOS & linux
|
||||
fixPath()
|
||||
beforeOpen()
|
||||
initI18n()
|
||||
rpcServer.start()
|
||||
getManageApi()
|
||||
UpDownTaskQueue.getInstance()
|
||||
manageIpcList.listen()
|
||||
initI18n()
|
||||
rpcServer.start()
|
||||
busEventList.listen()
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
export const PICLIST_MANAGE_GET_CONFIG = 'PICLIST_MANAGE_GET_CONFIG'
|
||||
export const PICLIST_MANAGE_REMOVE_CONFIG = 'PICLIST_MANAGE_REMOVE_CONFIG'
|
||||
export const PICLIST_MANAGE_SAVE_CONFIG = 'PICLIST_MANAGE_SAVE_CONFIG'
|
||||
@@ -1,158 +0,0 @@
|
||||
import { ipcMain, IpcMainInvokeEvent, dialog, app, shell } from 'electron'
|
||||
import fs from 'fs-extra'
|
||||
import path from 'path'
|
||||
|
||||
import UpDownTaskQueue from '~/manage/datastore/upDownTaskQueue'
|
||||
import manageCoreIPC from '~/manage/events/manageCoreIPC'
|
||||
import { ManageApi } from '~/manage/manageApi'
|
||||
import { downloadFileFromUrl } from '~/manage/utils/common'
|
||||
|
||||
import { selectDownloadFolder } from '#/utils/static'
|
||||
|
||||
export const manageIpcList = {
|
||||
listen() {
|
||||
manageCoreIPC.listen()
|
||||
|
||||
ipcMain.handle('getBucketList', async (_: IpcMainInvokeEvent, currentPicBed: string) => {
|
||||
const manage = new ManageApi(currentPicBed)
|
||||
return manage.getBucketList()
|
||||
})
|
||||
|
||||
ipcMain.handle('createBucket', async (_: IpcMainInvokeEvent, currentPicBed: string, param: IStringKeyMap) => {
|
||||
const manage = new ManageApi(currentPicBed)
|
||||
return manage.createBucket(param)
|
||||
})
|
||||
|
||||
ipcMain.handle('getBucketFileList', async (_: IpcMainInvokeEvent, currentPicBed: string, param: IStringKeyMap) => {
|
||||
const manage = new ManageApi(currentPicBed)
|
||||
return manage.getBucketFileList(param)
|
||||
})
|
||||
|
||||
ipcMain.handle('getBucketDomain', async (_: IpcMainInvokeEvent, currentPicBed: string, param: IStringKeyMap) => {
|
||||
const manage = new ManageApi(currentPicBed)
|
||||
const result = await manage.getBucketDomain(param)
|
||||
return result
|
||||
})
|
||||
|
||||
ipcMain.handle('setBucketAclPolicy', async (_: IpcMainInvokeEvent, currentPicBed: string, param: IStringKeyMap) => {
|
||||
const manage = new ManageApi(currentPicBed)
|
||||
return manage.setBucketAclPolicy(param)
|
||||
})
|
||||
|
||||
ipcMain.handle('renameBucketFile', async (_: IpcMainInvokeEvent, currentPicBed: string, param: IStringKeyMap) => {
|
||||
const manage = new ManageApi(currentPicBed)
|
||||
return manage.renameBucketFile(param)
|
||||
})
|
||||
|
||||
ipcMain.handle('deleteBucketFile', async (_: IpcMainInvokeEvent, currentPicBed: string, param: IStringKeyMap) => {
|
||||
const manage = new ManageApi(currentPicBed)
|
||||
return manage.deleteBucketFile(param)
|
||||
})
|
||||
|
||||
ipcMain.handle('deleteBucketFolder', async (_: IpcMainInvokeEvent, currentPicBed: string, param: IStringKeyMap) => {
|
||||
const manage = new ManageApi(currentPicBed)
|
||||
return manage.deleteBucketFolder(param)
|
||||
})
|
||||
|
||||
ipcMain.on('getBucketListBackstage', async (_: IpcMainInvokeEvent, currentPicBed: string, param: IStringKeyMap) => {
|
||||
const manage = new ManageApi(currentPicBed)
|
||||
return manage.getBucketListBackstage(param)
|
||||
})
|
||||
|
||||
ipcMain.on(
|
||||
'getBucketListRecursively',
|
||||
async (_: IpcMainInvokeEvent, currentPicBed: string, param: IStringKeyMap) => {
|
||||
const manage = new ManageApi(currentPicBed)
|
||||
return manage.getBucketListRecursively(param)
|
||||
}
|
||||
)
|
||||
|
||||
ipcMain.handle('convertPathToBase64', async (_: IpcMainInvokeEvent, filePath: string) => {
|
||||
const res = fs.readFileSync(filePath, 'base64')
|
||||
return res
|
||||
})
|
||||
|
||||
ipcMain.handle('openFileSelectDialog', async () => {
|
||||
const res = await dialog.showOpenDialog({
|
||||
properties: ['openFile', 'multiSelections']
|
||||
})
|
||||
if (res.canceled) {
|
||||
return []
|
||||
} else {
|
||||
return res.filePaths
|
||||
}
|
||||
})
|
||||
|
||||
ipcMain.handle('getPreSignedUrl', async (_: IpcMainInvokeEvent, currentPicBed: string, param: IStringKeyMap) => {
|
||||
const manage = new ManageApi(currentPicBed)
|
||||
return manage.getPreSignedUrl(param)
|
||||
})
|
||||
|
||||
ipcMain.handle('getUploadTaskList', async () => {
|
||||
return UpDownTaskQueue.getInstance().getAllUploadTask()
|
||||
})
|
||||
|
||||
ipcMain.handle('getDownloadTaskList', async () => {
|
||||
return UpDownTaskQueue.getInstance().getAllDownloadTask()
|
||||
})
|
||||
|
||||
ipcMain.on('uploadBucketFile', async (_: IpcMainInvokeEvent, currentPicBed: string, param: IStringKeyMap) => {
|
||||
const manage = new ManageApi(currentPicBed)
|
||||
return manage.uploadBucketFile(param)
|
||||
})
|
||||
|
||||
ipcMain.on('downloadBucketFile', async (_: IpcMainInvokeEvent, currentPicBed: string, param: IStringKeyMap) => {
|
||||
const manage = new ManageApi(currentPicBed)
|
||||
return manage.downloadBucketFile(param)
|
||||
})
|
||||
|
||||
ipcMain.handle('createBucketFolder', async (_: IpcMainInvokeEvent, currentPicBed: string, param: IStringKeyMap) => {
|
||||
const manage = new ManageApi(currentPicBed)
|
||||
return manage.createBucketFolder(param)
|
||||
})
|
||||
|
||||
ipcMain.on('deleteUploadedTask', async () => {
|
||||
UpDownTaskQueue.getInstance().removeUploadedTask()
|
||||
})
|
||||
|
||||
ipcMain.on('deleteAllUploadedTask', async () => {
|
||||
UpDownTaskQueue.getInstance().clearUploadTaskQueue()
|
||||
})
|
||||
|
||||
ipcMain.on('deleteDownloadedTask', async () => {
|
||||
UpDownTaskQueue.getInstance().removeDownloadedTask()
|
||||
})
|
||||
|
||||
ipcMain.on('deleteAllDownloadedTask', async () => {
|
||||
UpDownTaskQueue.getInstance().clearDownloadTaskQueue()
|
||||
})
|
||||
|
||||
ipcMain.handle(selectDownloadFolder, async () => {
|
||||
const res = await dialog.showOpenDialog({
|
||||
properties: ['openDirectory']
|
||||
})
|
||||
return res.filePaths[0]
|
||||
})
|
||||
|
||||
ipcMain.handle('getDefaultDownloadFolder', async () => {
|
||||
return app.getPath('downloads')
|
||||
})
|
||||
|
||||
ipcMain.on('OpenDownloadedFolder', async (_: IpcMainInvokeEvent, path: string | undefined) => {
|
||||
if (path) {
|
||||
shell.showItemInFolder(path)
|
||||
} else {
|
||||
shell.openPath(app.getPath('downloads'))
|
||||
}
|
||||
})
|
||||
|
||||
ipcMain.on('OpenLocalFile', async (_: IpcMainInvokeEvent, fullPath: string) => {
|
||||
fs.existsSync(fullPath) ? shell.showItemInFolder(fullPath) : shell.openPath(path.dirname(fullPath))
|
||||
})
|
||||
|
||||
ipcMain.handle('downloadFileFromUrl', async (_: IpcMainInvokeEvent, urls: string[]) => {
|
||||
const res = await downloadFileFromUrl(urls)
|
||||
return res
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
import { IpcMainEvent, IpcMainInvokeEvent, ipcMain } from 'electron'
|
||||
|
||||
import getManageApi from '~/manage/Main'
|
||||
import {
|
||||
PICLIST_MANAGE_GET_CONFIG,
|
||||
PICLIST_MANAGE_SAVE_CONFIG,
|
||||
PICLIST_MANAGE_REMOVE_CONFIG
|
||||
} from '~/manage/events/constants'
|
||||
|
||||
const manageApi = getManageApi()
|
||||
|
||||
const handleManageGetConfig = () => {
|
||||
ipcMain.handle(PICLIST_MANAGE_GET_CONFIG, (_: IpcMainInvokeEvent, key: string | undefined) => {
|
||||
return manageApi.getConfig(key)
|
||||
})
|
||||
}
|
||||
|
||||
const handleManageSaveConfig = () => {
|
||||
ipcMain.on(PICLIST_MANAGE_SAVE_CONFIG, (_: IpcMainEvent, data: any) => {
|
||||
manageApi.saveConfig(data)
|
||||
})
|
||||
}
|
||||
|
||||
const handleManageRemoveConfig = () => {
|
||||
ipcMain.on(PICLIST_MANAGE_REMOVE_CONFIG, (_: IpcMainEvent, key: string, propName: string) => {
|
||||
manageApi.removeConfig(key, propName)
|
||||
})
|
||||
}
|
||||
|
||||
export default {
|
||||
listen() {
|
||||
handleManageGetConfig()
|
||||
handleManageSaveConfig()
|
||||
handleManageRemoveConfig()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user