From 33b36d63c696627d6f56da6b3e83b595ad7b777f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=8C=E8=90=8C=E5=93=92=E8=B5=AB=E8=90=9D?= Date: Sun, 6 Aug 2023 02:06:37 -0700 Subject: [PATCH] :sparkles: Feature: add webPath for webdav picBed manage --- package.json | 2 +- public/i18n/en.yml | 3 +++ public/i18n/zh-CN.yml | 3 +++ public/i18n/zh-TW.yml | 3 +++ src/main/manage/apis/local.ts | 0 src/main/manage/apis/webdavplist.ts | 23 +++++++++++------ src/renderer/manage/pages/bucketPage.vue | 6 ++++- src/renderer/manage/pages/logIn.vue | 30 +++++++++++------------ src/renderer/manage/pages/manageMain.vue | 11 ++++++--- src/renderer/manage/store/bucketFileDb.ts | 10 +++++--- src/renderer/manage/utils/constants.ts | 9 +++++++ src/universal/types/i18n.d.ts | 3 +++ yarn.lock | 8 +++--- 13 files changed, 75 insertions(+), 36 deletions(-) create mode 100644 src/main/manage/apis/local.ts diff --git a/package.json b/package.json index f2ff8d61..cf7b140f 100644 --- a/package.json +++ b/package.json @@ -67,7 +67,7 @@ "mitt": "^3.0.0", "node-ssh-no-cpu-features": "^1.0.1", "nodejs-file-downloader": "^4.12.1", - "piclist": "^0.8.10", + "piclist": "^0.8.11", "pinia": "^2.1.4", "pinia-plugin-persistedstate": "^3.1.0", "qiniu": "^7.9.0", diff --git a/public/i18n/en.yml b/public/i18n/en.yml index d998e81d..9c8f0fb6 100644 --- a/public/i18n/en.yml +++ b/public/i18n/en.yml @@ -624,6 +624,9 @@ MANAGE_CONSTANT_LOCAL_WEB_PATH_TOOLTIP: 'Used to generate URL' MANAGE_CONSTANT_LOCAL_EXPLAIN: 'Local Configuration' MANAGE_CONSTANT_LOCAL_REFER_TEXT: 'Refer to:' MANAGE_CONSTANT_LOCAL_BASE_DIR_RULE_MESSAGE: baseDir cannot be empty +MANAGE_CONSTANT_LOCAL_BUCKET_DESC: Special Configuration +MANAGE_CONSTANT_LOCAL_BUCKET_PLACEHOLDER: 'bucket1' +MANAGE_CONSTANT_LOCAL_BUCKET_TOOLTIP: This cannot be modified, only for software compatibility consideration MANAGE_LOGIN_PAGE_PANE_NAME: Saved Config MANAGE_LOGIN_PAGE_PANE_DESC: Click on the icon or alias to view details, Enter to view the file page, Delete to remove the configuration diff --git a/public/i18n/zh-CN.yml b/public/i18n/zh-CN.yml index 6be6ce08..6d034378 100644 --- a/public/i18n/zh-CN.yml +++ b/public/i18n/zh-CN.yml @@ -627,6 +627,9 @@ MANAGE_CONSTANT_LOCAL_WEB_PATH_TOOLTIP: '用于拼接网址' MANAGE_CONSTANT_LOCAL_EXPLAIN: '本地存储配置' MANAGE_CONSTANT_LOCAL_REFER_TEXT: '配置教程请参考: ' MANAGE_CONSTANT_LOCAL_BASE_DIR_RULE_MESSAGE: 起始目录不能为空 +MANAGE_CONSTANT_LOCAL_BUCKET_DESC: 特殊配置 +MANAGE_CONSTANT_LOCAL_BUCKET_PLACEHOLDER: '例如:bucket1' +MANAGE_CONSTANT_LOCAL_BUCKET_TOOLTIP: 此处不可修改,仅为软件兼容性考虑 MANAGE_LOGIN_PAGE_PANE_NAME: 已保存配置 MANAGE_LOGIN_PAGE_PANE_DESC: 点击图标和别名可查看详情,点击进入可查看文件页面,点击删除可删除配置 diff --git a/public/i18n/zh-TW.yml b/public/i18n/zh-TW.yml index 67a4ba34..c49c84db 100644 --- a/public/i18n/zh-TW.yml +++ b/public/i18n/zh-TW.yml @@ -624,6 +624,9 @@ MANAGE_CONSTANT_LOCAL_WEB_PATH_TOOLTIP: '用於拼接網址' MANAGE_CONSTANT_LOCAL_EXPLAIN: '本地配置' MANAGE_CONSTANT_LOCAL_REFER_TEXT: '配置教程請參考: ' MANAGE_CONSTANT_LOCAL_BASE_DIR_RULE_MESSAGE: 起始目錄不能為空 +MANAGE_CONSTANT_LOCAL_BUCKET_DESC: 特殊配置 +MANAGE_CONSTANT_LOCAL_BUCKET_PLACEHOLDER: '例如:bucket1' +MANAGE_CONSTANT_LOCAL_BUCKET_TOOLTIP: 此處不可修改,僅為軟體相容性考量 MANAGE_LOGIN_PAGE_PANE_NAME: 已保存配置 MANAGE_LOGIN_PAGE_PANE_DESC: 點擊圖標和別名可查看詳情,點擊進入可查看檔案頁面,點擊刪除可刪除配置 diff --git a/src/main/manage/apis/local.ts b/src/main/manage/apis/local.ts new file mode 100644 index 00000000..e69de29b diff --git a/src/main/manage/apis/webdavplist.ts b/src/main/manage/apis/webdavplist.ts index 3da8426e..6a786579 100644 --- a/src/main/manage/apis/webdavplist.ts +++ b/src/main/manage/apis/webdavplist.ts @@ -52,7 +52,7 @@ class WebdavplistApi { logParam = (error:any, method: string) => this.logger.error(formatError(error, { class: 'WebdavplistApi', method })) - formatFolder (item: FileStat, urlPrefix: string) { + formatFolder (item: FileStat, urlPrefix: string, isWebPath = false) { return { ...item, key: item.filename.replace(/^\/+/, ''), @@ -64,11 +64,11 @@ class WebdavplistApi { checked: false, isImage: false, match: false, - url: `${urlPrefix}${item.filename}` + url: isWebPath ? urlPrefix : `${urlPrefix}${item.filename}` } } - formatFile (item: FileStat, urlPrefix: string) { + formatFile (item: FileStat, urlPrefix: string, isWebPath = false) { return { ...item, key: item.filename.replace(/^\/+/, ''), @@ -80,7 +80,7 @@ class WebdavplistApi { checked: false, match: false, isImage: isImage(item.basename), - url: `${urlPrefix}${item.filename}` + url: isWebPath ? urlPrefix : `${urlPrefix}${item.filename}` } } @@ -137,8 +137,13 @@ class WebdavplistApi { async getBucketListBackstage (configMap: IStringKeyMap): Promise { const window = windowManager.get(IWindowList.SETTING_WINDOW)! - const { prefix, customUrl, cancelToken } = configMap - const urlPrefix = customUrl || this.endpoint + const { prefix, customUrl, cancelToken, baseDir } = configMap + let urlPrefix = customUrl || this.endpoint + urlPrefix = urlPrefix.replace(/\/+$/, '') + let webPath = configMap.webPath || '' + if (webPath && customUrl && webPath !== '/') { + webPath = webPath.replace(/^\/+/, '').replace(/\/+$/, '') + } const cancelTask = [false] ipcMain.on('cancelLoadingFileList', (_evt: IpcMainEvent, token: string) => { if (token === cancelToken) { @@ -160,10 +165,12 @@ class WebdavplistApi { if (this.isRequestSuccess(res.status)) { if (res.data && res.data.length) { res.data.forEach((item: FileStat) => { + const relativePath = path.relative(baseDir, item.filename) + const relative = webPath && urlPrefix + `/${path.join(webPath, relativePath)}`.replace(/\\/g, '/').replace(/\/+/g, '/') if (item.type === 'directory') { - result.fullList.push(this.formatFolder(item, urlPrefix)) + result.fullList.push(this.formatFolder(item, webPath ? relative : urlPrefix, !!webPath)) } else { - result.fullList.push(this.formatFile(item, urlPrefix)) + result.fullList.push(this.formatFile(item, webPath ? relative : urlPrefix, !!webPath)) } }) } diff --git a/src/renderer/manage/pages/bucketPage.vue b/src/renderer/manage/pages/bucketPage.vue index 7e08629a..7bf59857 100644 --- a/src/renderer/manage/pages/bucketPage.vue +++ b/src/renderer/manage/pages/bucketPage.vue @@ -2792,10 +2792,14 @@ async function getBucketFileListBackStage () { currentPage: currentPage.value, cancelToken: cancelToken.value, cdnUrl: configMap.cdnUrl - } + } as IStringKeyMap isLoadingData.value = true const fileTransferStore = useFileTransferStore() fileTransferStore.resetFileTransferList() + if (currentPicBedName.value === 'webdavplist') { + param.baseDir = configMap.baseDir + param.webPath = configMap.webPath + } ipcRenderer.send('getBucketListBackstage', configMap.alias, param) ipcRenderer.on('refreshFileTransferList', (evt: IpcRendererEvent, data) => { fileTransferStore.refreshFileTransferList(data) diff --git a/src/renderer/manage/pages/logIn.vue b/src/renderer/manage/pages/logIn.vue index 628c337d..d90b2312 100644 --- a/src/renderer/manage/pages/logIn.vue +++ b/src/renderer/manage/pages/logIn.vue @@ -61,24 +61,24 @@ /> + - {{ item.alias.length > 15 ? item.alias.slice(0, 8) + '...' + item.alias.slice(-6) : item.alias }} - - + +
diff --git a/src/renderer/manage/pages/manageMain.vue b/src/renderer/manage/pages/manageMain.vue index a4e127dd..d4fe6ff0 100644 --- a/src/renderer/manage/pages/manageMain.vue +++ b/src/renderer/manage/pages/manageMain.vue @@ -319,7 +319,8 @@ const urlMap : IStringKeyMap = { tcyun: 'https://console.cloud.tencent.com/cos', upyun: 'https://console.upyun.com', s3plist: 'https://aws.amazon.com/cn/s3/', - webdavplist: 'https://baike.baidu.com/item/WebDAV/4610909' + webdavplist: 'https://baike.baidu.com/item/WebDAV/4610909', + local: 'https://piclist.cn' } const openPicBedUrl = () => shell.openExternal(urlMap[currentPagePicBedConfig.picBedName]) @@ -417,6 +418,7 @@ const handleSelectMenu = (bucketName: string) => { const alias = currentAlias.value const cdnUrl = manageStore.config.picBed[currentAlias.value].customUrl const bucketConfig = bucketList.value[bucketName] + const webPath = manageStore.config.picBed[currentAlias.value].webPath || '' const configMap = { prefix, bucketName, @@ -424,7 +426,9 @@ const handleSelectMenu = (bucketName: string) => { picBedName, alias, bucketConfig, - cdnUrl + cdnUrl, + baseDir: prefix, + webPath } currentSelectedBucket.value = bucketName router.push({ @@ -450,7 +454,8 @@ const menuTitleMap:IStringKeyMap = { smms: galleryT, imgur: galleryT, github: repositoryT, - webdavplist: '' + webdavplist: '', + local: '' } const showNewIconList = ['aliyun', 'qiniu', 'tcyun'] diff --git a/src/renderer/manage/store/bucketFileDb.ts b/src/renderer/manage/store/bucketFileDb.ts index 69de4060..865c6bef 100644 --- a/src/renderer/manage/store/bucketFileDb.ts +++ b/src/renderer/manage/store/bucketFileDb.ts @@ -28,16 +28,17 @@ export class FileCacheDb extends Dexie { imgur: Table s3plist: Table webdavplist: Table - localplist: Table + local: Table + sftpplist: Table constructor () { super('bucketFileDb') - const tableNames = ['tcyun', 'aliyun', 'qiniu', 'github', 'smms', 'upyun', 'imgur', 's3plist', 'webdavplist', 'localplist'] + const tableNames = ['tcyun', 'aliyun', 'qiniu', 'github', 'smms', 'upyun', 'imgur', 's3plist', 'webdavplist', 'local', 'sftpplist'] const tableNamesMap = tableNames.reduce((acc, cur) => { acc[cur] = '&key, value' return acc }, {} as IStringKeyMap) - this.version(3).stores(tableNamesMap) + this.version(4).stores(tableNamesMap) this.tcyun = this.table('tcyun') this.aliyun = this.table('aliyun') this.qiniu = this.table('qiniu') @@ -47,7 +48,8 @@ export class FileCacheDb extends Dexie { this.imgur = this.table('imgur') this.s3plist = this.table('s3plist') this.webdavplist = this.table('webdavplist') - this.localplist = this.table('localplist') + this.local = this.table('local') + this.sftpplist = this.table('sftpplist') } } diff --git a/src/renderer/manage/utils/constants.ts b/src/renderer/manage/utils/constants.ts index 8d34c4c0..a25215fc 100644 --- a/src/renderer/manage/utils/constants.ts +++ b/src/renderer/manage/utils/constants.ts @@ -819,6 +819,15 @@ export const supportedPicBedList: IStringKeyMap = { } ] }, + bucketName: { + required: true, + description: $T('MANAGE_CONSTANT_LOCAL_BUCKET_DESC'), + placeholder: $T('MANAGE_CONSTANT_LOCAL_BUCKET_PLACEHOLDER'), + type: 'string', + default: 'local', + disabled: true, + tooltip: $T('MANAGE_CONSTANT_LOCAL_BUCKET_TOOLTIP') + }, webPath: { required: false, description: $T('MANAGE_CONSTANT_LOCAL_WEB_PATH'), diff --git a/src/universal/types/i18n.d.ts b/src/universal/types/i18n.d.ts index feca625b..1f664b1f 100644 --- a/src/universal/types/i18n.d.ts +++ b/src/universal/types/i18n.d.ts @@ -585,6 +585,9 @@ interface ILocales { MANAGE_CONSTANT_LOCAL_EXPLAIN: string MANAGE_CONSTANT_LOCAL_REFER_TEXT: string MANAGE_CONSTANT_LOCAL_BASE_DIR_RULE_MESSAGE: string + MANAGE_CONSTANT_LOCAL_BUCKET_DESC: string + MANAGE_CONSTANT_LOCAL_BUCKET_PLACEHOLDER: string + MANAGE_CONSTANT_LOCAL_BUCKET_TOOLTIP: string MANAGE_LOGIN_PAGE_PANE_NAME: string MANAGE_LOGIN_PAGE_PANE_DESC: string MANAGE_LOGIN_PAGE_PANE_LOADING: string diff --git a/yarn.lock b/yarn.lock index 2339837b..5d22c49f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11048,10 +11048,10 @@ performance-now@^2.1.0: resolved "https://registry.npmmirror.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b" integrity sha512-7EAHlyLHI56VEIdK57uwHdHKIaAGbnXPiw0yWbarQZOKaKpvUIgW0jWRVLiatnM+XXlSwsanIBH/hzGMJulMow== -piclist@^0.8.10: - version "0.8.10" - resolved "https://registry.npmjs.org/piclist/-/piclist-0.8.10.tgz#efd7eddbe66023f375a7d687d4466a9031999aea" - integrity sha512-VLoLZywOoV6lGJN8u8Llr6B63OzT8k8yE5QF40JV3nwNK1jyGRLRZ/57/HIXsGFojWgoDerj3hmVuJOX556NFA== +piclist@^0.8.11: + version "0.8.11" + resolved "https://registry.npmjs.org/piclist/-/piclist-0.8.11.tgz#0fd6d690f9eb9099cea161d0d38d24d81df3a7cc" + integrity sha512-rgUw4x7gk3IpfzG8kONW7oQddWhylkWNSSucavQqlZeR6/XDPXZj+BBy0enzyi8GM/em0U456HHhP3ncJJjxnQ== dependencies: "@picgo/i18n" "^1.0.0" "@picgo/store" "^2.0.4"