diff --git a/src/main/manage/apis/aliyun.ts b/src/main/manage/apis/aliyun.ts index 18bc61c..caac669 100644 --- a/src/main/manage/apis/aliyun.ts +++ b/src/main/manage/apis/aliyun.ts @@ -6,14 +6,13 @@ import path from 'path' import windowManager from 'apis/app/window/windowManager' -import UpDownTaskQueue, { uploadTaskSpecialStatus, commonTaskStatus } from '~/manage/datastore/upDownTaskQueue' +import UpDownTaskQueue from '~/manage/datastore/upDownTaskQueue' import { ManageLogger } from '~/manage/utils/logger' import { hmacSha1Base64, getFileMimeType, formatError, NewDownloader, ConcurrencyPromisePool } from '~/manage/utils/common' -import { isImage } from '@/manage/utils/common' -import { cancelDownloadLoadingFileList, refreshDownloadFileTransferList } from '@/manage/utils/static' - -import { IWindowList } from '#/types/enum' +import { commonTaskStatus, IWindowList, uploadTaskSpecialStatus } from '#/types/enum' +import { isImage } from '#/utils/common' +import { cancelDownloadLoadingFileList, refreshDownloadFileTransferList } from '#/utils/static' // 坑爹阿里云 返回数据类型标注和实际各种不一致 class AliyunApi { diff --git a/src/main/manage/apis/github.ts b/src/main/manage/apis/github.ts index 687add1..54d4140 100644 --- a/src/main/manage/apis/github.ts +++ b/src/main/manage/apis/github.ts @@ -5,14 +5,13 @@ import path from 'path' import windowManager from 'apis/app/window/windowManager' -import UpDownTaskQueue, { commonTaskStatus } from '~/manage/datastore/upDownTaskQueue' -import { gotUpload, trimPath, NewDownloader, getAgent, getOptions, ConcurrencyPromisePool, formatError } from '~/manage/utils/common' +import UpDownTaskQueue from '~/manage/datastore/upDownTaskQueue' +import { gotUpload, NewDownloader, getAgent, getOptions, ConcurrencyPromisePool, formatError } from '~/manage/utils/common' import { ManageLogger } from '~/manage/utils/logger' -import { formatHttpProxy, isImage } from '@/manage/utils/common' -import { cancelDownloadLoadingFileList, refreshDownloadFileTransferList } from '@/manage/utils/static' - -import { IWindowList } from '#/types/enum' +import { commonTaskStatus, IWindowList } from '#/types/enum' +import { formatHttpProxy, isImage, trimPath } from '#/utils/common' +import { cancelDownloadLoadingFileList, refreshDownloadFileTransferList } from '#/utils/static' class GithubApi { token: string diff --git a/src/main/manage/apis/imgur.ts b/src/main/manage/apis/imgur.ts index 1298c51..377254e 100644 --- a/src/main/manage/apis/imgur.ts +++ b/src/main/manage/apis/imgur.ts @@ -6,7 +6,7 @@ import path from 'path' import windowManager from 'apis/app/window/windowManager' -import UpDownTaskQueue, { commonTaskStatus } from '~/manage/datastore/upDownTaskQueue' +import UpDownTaskQueue from '~/manage/datastore/upDownTaskQueue' import { ConcurrencyPromisePool, formatError, @@ -18,9 +18,8 @@ import { } from '~/manage/utils/common' import ManageLogger from '~/manage/utils/logger' -import { formatHttpProxy, isImage } from '@/manage/utils/common' - -import { IWindowList } from '#/types/enum' +import { commonTaskStatus, IWindowList } from '#/types/enum' +import { formatHttpProxy, isImage } from '#/utils/common' class ImgurApi { userName: string diff --git a/src/main/manage/apis/local.ts b/src/main/manage/apis/local.ts index 6624ccf..37d22d5 100644 --- a/src/main/manage/apis/local.ts +++ b/src/main/manage/apis/local.ts @@ -4,14 +4,13 @@ import path from 'path' import * as fsWalk from '@nodelib/fs.walk' import windowManager from 'apis/app/window/windowManager' -import UpDownTaskQueue, { uploadTaskSpecialStatus, commonTaskStatus, downloadTaskSpecialStatus } from '~/manage/datastore/upDownTaskQueue' +import UpDownTaskQueue from '~/manage/datastore/upDownTaskQueue' import { formatError } from '~/manage/utils/common' import ManageLogger from '~/manage/utils/logger' -import { isImage } from '@/manage/utils/common' -import { cancelDownloadLoadingFileList, refreshDownloadFileTransferList } from '@/manage/utils/static' - -import { IWindowList } from '#/types/enum' +import { commonTaskStatus, downloadTaskSpecialStatus, IWindowList, uploadTaskSpecialStatus } from '#/types/enum' +import { isImage } from '#/utils/common' +import { cancelDownloadLoadingFileList, refreshDownloadFileTransferList } from '#/utils/static' class LocalApi { logger: ManageLogger diff --git a/src/main/manage/apis/qiniu.ts b/src/main/manage/apis/qiniu.ts index 4724e05..eaaea40 100644 --- a/src/main/manage/apis/qiniu.ts +++ b/src/main/manage/apis/qiniu.ts @@ -6,14 +6,13 @@ import qiniu from 'qiniu/index' import windowManager from 'apis/app/window/windowManager' -import UpDownTaskQueue, { uploadTaskSpecialStatus, commonTaskStatus } from '~/manage/datastore/upDownTaskQueue' +import UpDownTaskQueue from '~/manage/datastore/upDownTaskQueue' import { hmacSha1Base64, getFileMimeType, NewDownloader, formatError, ConcurrencyPromisePool } from '~/manage/utils/common' import { ManageLogger } from '~/manage/utils/logger' -import { isImage } from '@/manage/utils/common' -import { cancelDownloadLoadingFileList, refreshDownloadFileTransferList } from '@/manage/utils/static' - -import { IWindowList } from '#/types/enum' +import { commonTaskStatus, IWindowList, uploadTaskSpecialStatus } from '#/types/enum' +import { isImage } from '#/utils/common' +import { cancelDownloadLoadingFileList, refreshDownloadFileTransferList } from '#/utils/static' class QiniuApi { mac: qiniu.auth.digest.Mac diff --git a/src/main/manage/apis/s3plist.ts b/src/main/manage/apis/s3plist.ts index c471799..ca69f41 100644 --- a/src/main/manage/apis/s3plist.ts +++ b/src/main/manage/apis/s3plist.ts @@ -27,15 +27,14 @@ import path from 'path' import windowManager from 'apis/app/window/windowManager' -import UpDownTaskQueue, { uploadTaskSpecialStatus, commonTaskStatus } from '~/manage/datastore/upDownTaskQueue' -import { formatEndpoint, formatError, getAgent, getFileMimeType, NewDownloader, ConcurrencyPromisePool } from '~/manage/utils/common' +import UpDownTaskQueue from '~/manage/datastore/upDownTaskQueue' +import { formatError, getAgent, getFileMimeType, NewDownloader, ConcurrencyPromisePool } from '~/manage/utils/common' import { dogecloudApi, DogecloudToken, getTempToken } from '~/manage/utils/dogeAPI' import { ManageLogger } from '~/manage/utils/logger' -import { isImage, formatHttpProxy } from '@/manage/utils/common' -import { cancelDownloadLoadingFileList, refreshDownloadFileTransferList } from '@/manage/utils/static' - -import { IWindowList } from '#/types/enum' +import { commonTaskStatus, IWindowList, uploadTaskSpecialStatus } from '#/types/enum' +import { isImage, formatEndpoint, formatHttpProxy } from '#/utils/common' +import { cancelDownloadLoadingFileList, refreshDownloadFileTransferList } from '#/utils/static' class S3plistApi { baseOptions: S3ClientConfig diff --git a/src/main/manage/apis/sftp.ts b/src/main/manage/apis/sftp.ts index 52ba3d0..2f2177d 100644 --- a/src/main/manage/apis/sftp.ts +++ b/src/main/manage/apis/sftp.ts @@ -5,15 +5,14 @@ import windowManager from 'apis/app/window/windowManager' import SSHClient from '~/utils/sshClient' -import UpDownTaskQueue, { commonTaskStatus, downloadTaskSpecialStatus, uploadTaskSpecialStatus } from '~/manage/datastore/upDownTaskQueue' +import UpDownTaskQueue from '~/manage/datastore/upDownTaskQueue' import { formatError } from '~/manage/utils/common' import ManageLogger from '~/manage/utils/logger' -import { isImage } from '@/manage/utils/common' -import { cancelDownloadLoadingFileList, refreshDownloadFileTransferList } from '@/manage/utils/static' - -import { IWindowList } from '#/types/enum' +import { commonTaskStatus, downloadTaskSpecialStatus, IWindowList, uploadTaskSpecialStatus } from '#/types/enum' import { Undefinable } from '#/types/manage' +import { isImage } from '#/utils/common' +import { cancelDownloadLoadingFileList, refreshDownloadFileTransferList } from '#/utils/static' interface listDirResult { permissions: string diff --git a/src/main/manage/apis/smms.ts b/src/main/manage/apis/smms.ts index b972623..06b533b 100644 --- a/src/main/manage/apis/smms.ts +++ b/src/main/manage/apis/smms.ts @@ -8,10 +8,10 @@ import windowManager from 'apis/app/window/windowManager' import { getFileMimeType, gotUpload, NewDownloader, ConcurrencyPromisePool, formatError } from '~/manage/utils/common' import { ManageLogger } from '~/manage/utils/logger' -import UpDownTaskQueue, { commonTaskStatus } from '~/manage/datastore/upDownTaskQueue' +import UpDownTaskQueue from '~/manage/datastore/upDownTaskQueue' -import { isImage } from '@/manage/utils/common' -import { IWindowList } from '#/types/enum' +import { commonTaskStatus, IWindowList } from '#/types/enum' +import { isImage } from '#/utils/common' class SmmsApi { baseUrl = 'https://smms.app/api/v2' diff --git a/src/main/manage/apis/tcyun.ts b/src/main/manage/apis/tcyun.ts index 66fdbe7..08509b1 100644 --- a/src/main/manage/apis/tcyun.ts +++ b/src/main/manage/apis/tcyun.ts @@ -8,13 +8,11 @@ import windowManager from 'apis/app/window/windowManager' import { formatError, getFileMimeType } from '~/manage/utils/common' import { ManageLogger } from '~/manage/utils/logger' -import UpDownTaskQueue, { uploadTaskSpecialStatus, commonTaskStatus, downloadTaskSpecialStatus } from '~/manage/datastore/upDownTaskQueue' +import UpDownTaskQueue from '~/manage/datastore/upDownTaskQueue' -import { isImage } from '@/manage/utils/common' -import { cancelDownloadLoadingFileList, refreshDownloadFileTransferList } from '@/manage/utils/static' - -import { handleUrlEncode } from '#/utils/common' -import { IWindowList } from '#/types/enum' +import { handleUrlEncode, isImage } from '#/utils/common' +import { commonTaskStatus, downloadTaskSpecialStatus, IWindowList, uploadTaskSpecialStatus } from '#/types/enum' +import { cancelDownloadLoadingFileList, refreshDownloadFileTransferList } from '#/utils/static' class TcyunApi { ctx: COS diff --git a/src/main/manage/apis/upyun.ts b/src/main/manage/apis/upyun.ts index db67af9..1b09fcf 100644 --- a/src/main/manage/apis/upyun.ts +++ b/src/main/manage/apis/upyun.ts @@ -9,12 +9,11 @@ import windowManager from 'apis/app/window/windowManager' import { md5, hmacSha1Base64, getFileMimeType, NewDownloader, gotUpload, ConcurrencyPromisePool, formatError } from '~/manage/utils/common' import { ManageLogger } from '~/manage/utils/logger' -import UpDownTaskQueue, { commonTaskStatus } from '~/manage/datastore/upDownTaskQueue' +import UpDownTaskQueue from '~/manage/datastore/upDownTaskQueue' -import { isImage } from '@/manage/utils/common' -import { cancelDownloadLoadingFileList, refreshDownloadFileTransferList } from '@/manage/utils/static' - -import { IWindowList } from '#/types/enum' +import { commonTaskStatus, IWindowList } from '#/types/enum' +import { isImage } from '#/utils/common' +import { cancelDownloadLoadingFileList, refreshDownloadFileTransferList } from '#/utils/static' class UpyunApi { ser: Upyun.Service diff --git a/src/main/manage/apis/webdavplist.ts b/src/main/manage/apis/webdavplist.ts index 4f107c1..9959e71 100644 --- a/src/main/manage/apis/webdavplist.ts +++ b/src/main/manage/apis/webdavplist.ts @@ -7,15 +7,15 @@ import { createClient, WebDAVClient, FileStat, ProgressEvent, AuthType, WebDAVCl import windowManager from 'apis/app/window/windowManager' -import UpDownTaskQueue, { uploadTaskSpecialStatus, commonTaskStatus } from '~/manage/datastore/upDownTaskQueue' -import { formatError, formatEndpoint, getInnerAgent, NewDownloader, ConcurrencyPromisePool } from '~/manage/utils/common' +import UpDownTaskQueue from '~/manage/datastore/upDownTaskQueue' +import { formatError, getInnerAgent, NewDownloader, ConcurrencyPromisePool } from '~/manage/utils/common' import ManageLogger from '~/manage/utils/logger' -import { formatHttpProxy, isImage } from '@/manage/utils/common' import { getAuthHeader } from '@/manage/utils/digestAuth' -import { cancelDownloadLoadingFileList, refreshDownloadFileTransferList } from '@/manage/utils/static' -import { IWindowList } from '#/types/enum' +import { commonTaskStatus, IWindowList, uploadTaskSpecialStatus } from '#/types/enum' +import { isImage, formatEndpoint, formatHttpProxy } from '#/utils/common' +import { cancelDownloadLoadingFileList, refreshDownloadFileTransferList } from '#/utils/static' class WebdavplistApi { endpoint: string diff --git a/src/main/manage/datastore/db.ts b/src/main/manage/datastore/db.ts index 25e1f66..7c65eef 100644 --- a/src/main/manage/datastore/db.ts +++ b/src/main/manage/datastore/db.ts @@ -1,12 +1,12 @@ import { JSONStore } from '@picgo/store' import { IJSON } from '@picgo/store/dist/types' -import { ManageApiType, ManageConfigType } from '#/types/manage' +import { IManageApiType, IManageConfigType } from '#/types/manage' class ManageDB { - readonly #ctx: ManageApiType + readonly #ctx: IManageApiType readonly #db: JSONStore - constructor (ctx: ManageApiType) { + constructor (ctx: IManageApiType) { this.#ctx = ctx this.#db = new JSONStore(this.#ctx.configPath) const initParams: IStringKeyMap = { @@ -49,13 +49,13 @@ class ManageDB { return this.#db.unset(key, value) } - saveConfig (config: Partial): void { + saveConfig (config: Partial): void { Object.keys(config).forEach((name: string) => { this.set(name, config[name]) }) } - removeConfig (config: ManageConfigType): void { + removeConfig (config: IManageConfigType): void { Object.keys(config).forEach((name: string) => { this.unset(name, config[name]) }) diff --git a/src/main/manage/datastore/upDownTaskQueue.ts b/src/main/manage/datastore/upDownTaskQueue.ts index 6486deb..d00e552 100644 --- a/src/main/manage/datastore/upDownTaskQueue.ts +++ b/src/main/manage/datastore/upDownTaskQueue.ts @@ -5,56 +5,8 @@ import { app } from 'electron' import fs from 'fs-extra' import path from 'path' -export enum commonTaskStatus { - queuing = 'queuing', - failed = 'failed', - canceled = 'canceled', - paused = 'paused' -} - -export enum uploadTaskSpecialStatus { - uploading = 'uploading', - uploaded = 'uploaded' -} - -export enum downloadTaskSpecialStatus { - downloading = 'downloading', - downloaded = 'downloaded', -} - -export type uploadTaskStatus = commonTaskStatus | uploadTaskSpecialStatus -type downloadTaskStatus = commonTaskStatus | downloadTaskSpecialStatus - -export interface IUploadTask { - id: string - progress: number - status: uploadTaskStatus - sourceFilePath: string - sourceFileName: string - targetFilePath: string - targetFileBucket?: string - response?: any - cancelToken?: string - timeConsuming?: number - alias?: string - [other: string]: any -} - -export interface IDownloadTask { - id: string - progress: number - status: downloadTaskStatus - sourceFileUrl?: string - sourceFileName?: string - sourceConfig?: IStringKeyMap - targetFilePath?: string - response?: any - cancelToken?: string - timeConsuming?: number - reseumConfig?: IStringKeyMap - alias?: string - [other: string]: any -} +import { commonTaskStatus, downloadTaskSpecialStatus, uploadTaskSpecialStatus } from '#/types/enum' +import { IDownloadTask, IUploadTask } from '#/types/manage' class UpDownTaskQueue { /* eslint-disable */ diff --git a/src/main/manage/events/ipcList.ts b/src/main/manage/events/ipcList.ts index befbbee..dfadd01 100644 --- a/src/main/manage/events/ipcList.ts +++ b/src/main/manage/events/ipcList.ts @@ -7,7 +7,7 @@ import manageCoreIPC from '~/manage/events/manageCoreIPC' import { ManageApi } from '~/manage/manageApi' import { downloadFileFromUrl } from '~/manage/utils/common' -import { selectDownloadFolder } from '@/manage/utils/static' +import { selectDownloadFolder } from '#/utils/static' export const manageIpcList = { listen () { diff --git a/src/main/manage/manageApi.ts b/src/main/manage/manageApi.ts index 340778c..e614b9e 100644 --- a/src/main/manage/manageApi.ts +++ b/src/main/manage/manageApi.ts @@ -14,24 +14,23 @@ import { managePathChecker } from '~/manage/datastore/dbChecker' import { isInputConfigValid, formatError } from '~/manage/utils/common' import { ManageLogger } from '~/manage/utils/logger' -import { cancelDownloadLoadingFileList, refreshDownloadFileTransferList } from '@/manage/utils/static' - import { IWindowList } from '#/types/enum' import { - ManageApiType, - ManageConfigType, - ManageError, - PicBedMangeConfig + IManageApiType, + IManageConfigType, + IManageError, + IPicBedMangeConfig } from '#/types/manage' +import { cancelDownloadLoadingFileList, refreshDownloadFileTransferList } from '#/utils/static' -export class ManageApi extends EventEmitter implements ManageApiType { - private _config!: Partial +export class ManageApi extends EventEmitter implements IManageApiType { + private _config!: Partial private db!: ManageDB currentPicBed: string configPath: string baseDir!: string logger: ManageLogger - currentPicBedConfig: PicBedMangeConfig + currentPicBedConfig: IPicBedMangeConfig constructor (currentPicBed: string = '') { super() @@ -85,8 +84,8 @@ export class ManageApi extends EventEmitter implements ManageApiType { } } - private getPicBedConfig (picBedName: string): PicBedMangeConfig { - return this.getConfig(`picBed.${picBedName}`) + private getPicBedConfig (picBedName: string): IPicBedMangeConfig { + return this.getConfig(`picBed.${picBedName}`) } private initConfigPath (): void { @@ -106,7 +105,7 @@ export class ManageApi extends EventEmitter implements ManageApiType { private initconfig (): void { this.db = new ManageDB(this) - this._config = this.db.read(true) as ManageConfigType + this._config = this.db.read(true) as IManageConfigType } getConfig (name?: string): T { @@ -194,14 +193,14 @@ export class ManageApi extends EventEmitter implements ManageApiType { async getBucketInfo ( param?: IStringKeyMap | undefined - ): Promise { + ): Promise { console.log(param) return {} } async getBucketDomain ( param: IStringKeyMap - ): Promise { + ): Promise { let client switch (this.currentPicBedConfig.picBedName) { case 'tcyun': @@ -256,7 +255,7 @@ export class ManageApi extends EventEmitter implements ManageApiType { async getOperatorList ( param?: IStringKeyMap - ): Promise { + ): Promise { console.log(param) return [] } @@ -277,7 +276,7 @@ export class ManageApi extends EventEmitter implements ManageApiType { async getBucketAclPolicy ( param?: IStringKeyMap - ): Promise { + ): Promise { console.log(param) return {} } @@ -302,7 +301,7 @@ export class ManageApi extends EventEmitter implements ManageApiType { async getBucketListRecursively ( param?: IStringKeyMap - ): Promise { + ): Promise { let client let window const defaultResult = { @@ -347,7 +346,7 @@ export class ManageApi extends EventEmitter implements ManageApiType { */ async getBucketListBackstage ( param?: IStringKeyMap - ): Promise { + ): Promise { let client let window const defaultResult = { @@ -396,7 +395,7 @@ export class ManageApi extends EventEmitter implements ManageApiType { **/ async getBucketFileList ( param?: IStringKeyMap - ): Promise { + ): Promise { const defaultResponse = { fullList: [], isTruncated: false, diff --git a/src/main/manage/utils/common.ts b/src/main/manage/utils/common.ts index fd6b5d9..16182fb 100644 --- a/src/main/manage/utils/common.ts +++ b/src/main/manage/utils/common.ts @@ -12,15 +12,11 @@ import path from 'path' import { Stream } from 'stream' import { promisify } from 'util' -import UpDownTaskQueue, -{ - uploadTaskSpecialStatus, - commonTaskStatus, - downloadTaskSpecialStatus -} from '~/manage/datastore/upDownTaskQueue' +import UpDownTaskQueue from '~/manage/datastore/upDownTaskQueue' import { ManageLogger } from '~/manage/utils/logger' -import { formatHttpProxy, IHTTPProxy } from '@/manage/utils/common' +import { commonTaskStatus, downloadTaskSpecialStatus, uploadTaskSpecialStatus } from '#/types/enum' +import { formatHttpProxy } from '#/utils/common' export const getFSFile = async ( filePath: string, @@ -218,8 +214,6 @@ export const formatError = (err: any, params:IStringKeyMap) => { return `${String(err)}${JSON.stringify(params)}` } -export const trimPath = (path: string) => path.replace(/^\/+|\/+$/g, '').replace(/\/+/g, '/') - const commonOptions = { keepAlive: true, keepAliveMsecs: 1000, @@ -309,13 +303,6 @@ export function getOptions ( } } -export const formatEndpoint = (endpoint: string, sslEnabled: boolean): string => - !/^https?:\/\//.test(endpoint) - ? `${sslEnabled ? 'https' : 'http'}://${endpoint}` - : sslEnabled - ? endpoint.replace('http://', 'https://') - : endpoint.replace('https://', 'http://') - export class ConcurrencyPromisePool { limit: number queue: any[] diff --git a/src/main/manage/utils/logger.ts b/src/main/manage/utils/logger.ts index 8b1e799..98bc223 100644 --- a/src/main/manage/utils/logger.ts +++ b/src/main/manage/utils/logger.ts @@ -6,7 +6,7 @@ import { ILogColor, ILogger } from 'piclist/dist/types' import util from 'util' import { ILogType } from '#/types/enum' -import { ManageApiType, Undefinable } from '#/types/manage' +import { IManageApiType, Undefinable } from '#/types/manage' import { enforceNumber, isDev } from '#/utils/common' import { configPaths } from '#/utils/configPaths' @@ -18,11 +18,11 @@ export class ManageLogger implements ILogger { [ILogType.error]: 'red' } - readonly #ctx: ManageApiType + readonly #ctx: IManageApiType #logLevel!: string #logPath!: string - constructor (ctx: ManageApiType) { + constructor (ctx: IManageApiType) { this.#ctx = ctx } diff --git a/src/renderer/apis/webdav.ts b/src/renderer/apis/webdav.ts index 43ef950..1afbd4e 100644 --- a/src/renderer/apis/webdav.ts +++ b/src/renderer/apis/webdav.ts @@ -2,7 +2,7 @@ import { AuthType, WebDAVClientOptions, createClient } from 'webdav' import { deleteFailedLog, deleteLog } from '@/utils/common' -import { formatEndpoint } from '~/manage/utils/common' +import { formatEndpoint } from '#/utils/common' interface IConfigMap { fileName: string diff --git a/src/renderer/components/ImageWebdav.vue b/src/renderer/components/ImageWebdav.vue index 99d0c02..477f98e 100644 --- a/src/renderer/components/ImageWebdav.vue +++ b/src/renderer/components/ImageWebdav.vue @@ -26,7 +26,7 @@ import { Loading } from '@element-plus/icons-vue' import { getAuthHeader } from '@/manage/utils/digestAuth' import { getFileIconPath } from '@/manage/utils/common' -import { formatEndpoint } from '~/manage/utils/common' +import { formatEndpoint } from '#/utils/common' const base64Url = ref('') const success = ref(false) diff --git a/src/renderer/components/ImageWebdavTsx.tsx b/src/renderer/components/ImageWebdavTsx.tsx index ade55b8..97bbdff 100644 --- a/src/renderer/components/ImageWebdavTsx.tsx +++ b/src/renderer/components/ImageWebdavTsx.tsx @@ -5,7 +5,7 @@ import { Loading } from '@element-plus/icons-vue' import { getFileIconPath } from '@/manage/utils/common' import { getAuthHeader } from '@/manage/utils/digestAuth' -import { formatEndpoint } from '~/manage/utils/common' +import { formatEndpoint } from '#/utils/common' export default defineComponent({ props: { diff --git a/src/renderer/manage/pages/bucketPage.vue b/src/renderer/manage/pages/bucketPage.vue index 012f4ce..754defd 100644 --- a/src/renderer/manage/pages/bucketPage.vue +++ b/src/renderer/manage/pages/bucketPage.vue @@ -1467,9 +1467,8 @@ import { useRoute } from 'vue-router' import { fileCacheDbInstance } from '@/manage/store/bucketFileDb' import { useFileTransferStore, useDownloadFileTransferStore, useManageStore } from '@/manage/store/manageStore' -import { customRenameFormatTable, customStrMatch, customStrReplace, renameFile, formatLink, formatFileName, getFileIconPath, formatFileSize, getExtension, isValidUrl, svg } from '@/manage/utils/common' +import { customRenameFormatTable, customStrMatch, customStrReplace, renameFile, formatLink, formatFileName, getFileIconPath, formatFileSize, isValidUrl, svg } from '@/manage/utils/common' import { getConfig, saveConfig } from '@/manage/utils/dataSender' -import { cancelDownloadLoadingFileList, refreshDownloadFileTransferList } from '@/manage/utils/static' import { textFileExt } from '@/manage/utils/textfile' import { videoExt } from '@/manage/utils/videofile' @@ -1479,8 +1478,10 @@ import ImageWebdavTsx from '@/components/ImageWebdavTsx' import { T as $T } from '@/i18n' -import { IUploadTask, IDownloadTask } from '~/manage/datastore/upDownTaskQueue' -import { trimPath } from '~/manage/utils/common' +import { getExtension, trimPath } from '#/utils/common' +import { cancelDownloadLoadingFileList, refreshDownloadFileTransferList } from '#/utils/static' +import { IUploadTask, IDownloadTask } from '#/types/manage' + /* configMap:{ prefix: string, -> baseDir diff --git a/src/renderer/manage/pages/logIn.vue b/src/renderer/manage/pages/logIn.vue index d38fce0..9fb5850 100644 --- a/src/renderer/manage/pages/logIn.vue +++ b/src/renderer/manage/pages/logIn.vue @@ -281,8 +281,7 @@ import { formObjToTableData, svg } from '@/manage/utils/common' import { getConfig as getPicBedsConfig } from '@/utils/dataSender' import { T as $T } from '@/i18n' -import { formatEndpoint } from '~/manage/utils/common' -import { isNeedToShorten, safeSliceF } from '#/utils/common' +import { formatEndpoint, isNeedToShorten, safeSliceF } from '#/utils/common' const manageStore = useManageStore() const router = useRouter() diff --git a/src/renderer/manage/pages/manageSetting.vue b/src/renderer/manage/pages/manageSetting.vue index 890b92b..b00a8ea 100644 --- a/src/renderer/manage/pages/manageSetting.vue +++ b/src/renderer/manage/pages/manageSetting.vue @@ -249,10 +249,11 @@ import DynamicSwitch from '@/manage/components/DynamicSwitch.vue' import { fileCacheDbInstance } from '@/manage/store/bucketFileDb' import { formatFileSize, customRenameFormatTable } from '@/manage/utils/common' import { getConfig, saveConfig, invokeToMain } from '@/manage/utils/dataSender' -import { selectDownloadFolder } from '@/manage/utils/static' import { T as $T } from '@/i18n' +import { selectDownloadFolder } from '#/utils/static' + const form = ref({ timestampRename: false, randomStringRename: false, diff --git a/src/renderer/manage/utils/common.ts b/src/renderer/manage/utils/common.ts index bd8b730..d413685 100644 --- a/src/renderer/manage/utils/common.ts +++ b/src/renderer/manage/utils/common.ts @@ -118,11 +118,6 @@ export function formatFileName (fileName: string, length: number = 20) { return isNeedToShorten(fileName, length) ? `${safeSliceF(name, length - 3 - ext.length)}...${ext}` : fileName } -export const getExtension = (fileName: string) => path.extname(fileName).slice(1) - -export const isImage = (fileName: string) => - ['jpg', 'jpeg', 'png', 'gif', 'webp', 'bmp', 'ico', 'svg'].includes(getExtension(fileName)) - export function formObjToTableData (obj: any) { const exclude = [undefined, null, '', 'transformedConfig'] return Object.keys(obj).filter(key => !exclude.includes(obj[key])).map(key => ({ @@ -139,34 +134,6 @@ export function isValidUrl (str: string) { } } -export interface IHTTPProxy { - host: string - port: number - protocol: string -} - -export const formatHttpProxy = (proxy: string | undefined, type: 'object' | 'string'): IHTTPProxy | undefined | string => { - if (!proxy) return undefined - if (/^https?:\/\//.test(proxy)) { - const { protocol, hostname, port } = new URL(proxy) - return type === 'string' - ? `${protocol}//${hostname}:${port}` - : { - host: hostname, - port: Number(port), - protocol: protocol.slice(0, -1) - } - } - const [host, port] = proxy.split(':') - return type === 'string' - ? `http://${host}:${port}` - : { - host, - port: port ? Number(port) : 80, - protocol: 'http' - } -} - export const svg = ` = T | undefined; +export type Undefinable = T | undefined; -declare interface ManageError extends Error { +export interface IManageError extends Error { code?: number param?: string stack?: string picbed?: string } -type PicBedMangeConfig = IStringKeyMap; +export type IPicBedMangeConfig = IStringKeyMap; -interface PicBedManageConfigMap { - [key: string]: PicBedMangeConfig -} - -interface ManageApiType { +export interface IManageApiType { /** * logger */ @@ -36,7 +33,7 @@ interface ManageApiType { /** * current picBed config */ - currentPicBedConfig: PicBedMangeConfig + currentPicBedConfig: IPicBedMangeConfig /** * get manage config */ @@ -62,19 +59,19 @@ interface ManageApiType { */ getBucketListRecursively: ( param?: IStringKeyMap - ) => Promise + ) => Promise /** * get bucket list */ getBucketListBackstage: ( param?: IStringKeyMap - ) => Promise + ) => Promise /** * get bucket list */ getBucketList: ( param?: IStringKeyMap - ) => Promise + ) => Promise getBucketDomain: ( param: IStringKeyMap ) => Promise @@ -83,7 +80,7 @@ interface ManageApiType { */ getBucketInfo: ( param?: IStringKeyMap - ) => Promise + ) => Promise /** * create bucket */ @@ -102,7 +99,7 @@ interface ManageApiType { */ getOperatorList: ( param?: IStringKeyMap - ) => Promise + ) => Promise /** * add Operator * specific for upyun @@ -122,7 +119,7 @@ interface ManageApiType { */ getBucketAclPolicy: ( param?: IStringKeyMap - ) => Promise + ) => Promise /** * set bucket ACL policy */ @@ -134,7 +131,7 @@ interface ManageApiType { */ getBucketFileList: ( param?: IStringKeyMap - ) => Promise + ) => Promise /** * delete bucket file */ @@ -177,7 +174,7 @@ interface ManageApiType { uploadBucketFile: ( param?: IStringKeyMap ) => Promise - /** + /** * get presigned url */ getPreSignedUrl: ( @@ -186,7 +183,7 @@ interface ManageApiType { } /** PicList 存储管理功能配置文件类型定义 */ -interface ManageConfigType { +export interface IManageConfigType { picBed: { [others: string]: any } @@ -195,3 +192,37 @@ interface ManageConfigType { } [others: string]: any } + +type uploadTaskStatus = commonTaskStatus | uploadTaskSpecialStatus +type downloadTaskStatus = commonTaskStatus | downloadTaskSpecialStatus + +export interface IUploadTask { + id: string + progress: number + status: uploadTaskStatus + sourceFilePath: string + sourceFileName: string + targetFilePath: string + targetFileBucket?: string + response?: any + cancelToken?: string + timeConsuming?: number + alias?: string + [other: string]: any +} + +export interface IDownloadTask { + id: string + progress: number + status: downloadTaskStatus + sourceFileUrl?: string + sourceFileName?: string + sourceConfig?: IStringKeyMap + targetFilePath?: string + response?: any + cancelToken?: string + timeConsuming?: number + reseumConfig?: IStringKeyMap + alias?: string + [other: string]: any +} diff --git a/src/universal/types/types.d.ts b/src/universal/types/types.d.ts index 070fa6c..59962d6 100644 --- a/src/universal/types/types.d.ts +++ b/src/universal/types/types.d.ts @@ -35,6 +35,8 @@ interface IServerConfig { enable: boolean } +// Sync + interface ISyncConfig { type: string file?: string @@ -528,3 +530,9 @@ interface IUploaderConfigItem { type IUploaderConfigListItem = IStringKeyMap & IUploaderListItemMetaInfo type ICheckBoxValueType = boolean | string | number + +interface IHTTPProxy { + host: string + port: number + protocol: string +} \ No newline at end of file diff --git a/src/universal/utils/common.ts b/src/universal/utils/common.ts index 3d75060..eeea365 100644 --- a/src/universal/utils/common.ts +++ b/src/universal/utils/common.ts @@ -1,3 +1,5 @@ +import path from 'path' + export const isUrl = (url: string): boolean => { try { return Boolean(new URL(url)) @@ -68,3 +70,39 @@ export function encodeFilePath (filePath: string) { .map(encodeURIComponent) .join('/') } + +export const getExtension = (fileName: string) => path.extname(fileName).slice(1) + +export const isImage = (fileName: string) => + ['jpg', 'jpeg', 'png', 'gif', 'webp', 'bmp', 'ico', 'svg'].includes(getExtension(fileName)) + +export const formatEndpoint = (endpoint: string, sslEnabled: boolean): string => + !/^https?:\/\//.test(endpoint) + ? `${sslEnabled ? 'https' : 'http'}://${endpoint}` + : sslEnabled + ? endpoint.replace('http://', 'https://') + : endpoint.replace('https://', 'http://') + +export const trimPath = (path: string) => path.replace(/^\/+|\/+$/g, '').replace(/\/+/g, '/') + +export const formatHttpProxy = (proxy: string | undefined, type: 'object' | 'string'): IHTTPProxy | undefined | string => { + if (!proxy) return undefined + if (/^https?:\/\//.test(proxy)) { + const { protocol, hostname, port } = new URL(proxy) + return type === 'string' + ? `${protocol}//${hostname}:${port}` + : { + host: hostname, + port: Number(port), + protocol: protocol.slice(0, -1) + } + } + const [host, port] = proxy.split(':') + return type === 'string' + ? `http://${host}:${port}` + : { + host, + port: port ? Number(port) : 80, + protocol: 'http' + } +} diff --git a/src/universal/utils/static.ts b/src/universal/utils/static.ts index ae3e647..3cdd5f9 100644 --- a/src/universal/utils/static.ts +++ b/src/universal/utils/static.ts @@ -3,6 +3,12 @@ export const RELEASE_URL = 'https://api.github.com/repos/Kuingsmile/PicList/rele export const RELEASE_URL_BACKUP = 'https://release.piclist.cn' export const STABLE_RELEASE_URL = 'https://github.com/Kuingsmile/PicList/releases/latest' +export const DEFAULT_AES_PASSWORD = 'aesPassword' + +export const cancelDownloadLoadingFileList = 'cancelDownloadLoadingFileList' +export const refreshDownloadFileTransferList = 'refreshDownloadFileTransferList' +export const selectDownloadFolder = 'selectDownloadFolder' + export const picBedsCanbeDeleted = [ 'aliyun', 'alist', @@ -63,5 +69,3 @@ export const picBedManualUrlList: IStringKeyMap = { webdavplist: 'https://piclist.cn/en/configure.html#webdav' } } - -export const DEFAULT_AES_PASSWORD = 'aesPassword'