🔨 Refactor(custom): refactored imports

This commit is contained in:
Kuingsmile 2024-06-09 18:39:12 +08:00
parent e87e3999b4
commit 19c12b6b02
30 changed files with 207 additions and 216 deletions

View File

@ -6,14 +6,13 @@ import path from 'path'
import windowManager from 'apis/app/window/windowManager' 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 { ManageLogger } from '~/manage/utils/logger'
import { hmacSha1Base64, getFileMimeType, formatError, NewDownloader, ConcurrencyPromisePool } from '~/manage/utils/common' import { hmacSha1Base64, getFileMimeType, formatError, NewDownloader, ConcurrencyPromisePool } from '~/manage/utils/common'
import { isImage } from '@/manage/utils/common' import { commonTaskStatus, IWindowList, uploadTaskSpecialStatus } from '#/types/enum'
import { cancelDownloadLoadingFileList, refreshDownloadFileTransferList } from '@/manage/utils/static' import { isImage } from '#/utils/common'
import { cancelDownloadLoadingFileList, refreshDownloadFileTransferList } from '#/utils/static'
import { IWindowList } from '#/types/enum'
// 坑爹阿里云 返回数据类型标注和实际各种不一致 // 坑爹阿里云 返回数据类型标注和实际各种不一致
class AliyunApi { class AliyunApi {

View File

@ -5,14 +5,13 @@ import path from 'path'
import windowManager from 'apis/app/window/windowManager' import windowManager from 'apis/app/window/windowManager'
import UpDownTaskQueue, { commonTaskStatus } from '~/manage/datastore/upDownTaskQueue' import UpDownTaskQueue from '~/manage/datastore/upDownTaskQueue'
import { gotUpload, trimPath, NewDownloader, getAgent, getOptions, ConcurrencyPromisePool, formatError } from '~/manage/utils/common' import { gotUpload, NewDownloader, getAgent, getOptions, ConcurrencyPromisePool, formatError } from '~/manage/utils/common'
import { ManageLogger } from '~/manage/utils/logger' import { ManageLogger } from '~/manage/utils/logger'
import { formatHttpProxy, isImage } from '@/manage/utils/common' import { commonTaskStatus, IWindowList } from '#/types/enum'
import { cancelDownloadLoadingFileList, refreshDownloadFileTransferList } from '@/manage/utils/static' import { formatHttpProxy, isImage, trimPath } from '#/utils/common'
import { cancelDownloadLoadingFileList, refreshDownloadFileTransferList } from '#/utils/static'
import { IWindowList } from '#/types/enum'
class GithubApi { class GithubApi {
token: string token: string

View File

@ -6,7 +6,7 @@ import path from 'path'
import windowManager from 'apis/app/window/windowManager' import windowManager from 'apis/app/window/windowManager'
import UpDownTaskQueue, { commonTaskStatus } from '~/manage/datastore/upDownTaskQueue' import UpDownTaskQueue from '~/manage/datastore/upDownTaskQueue'
import { import {
ConcurrencyPromisePool, ConcurrencyPromisePool,
formatError, formatError,
@ -18,9 +18,8 @@ import {
} from '~/manage/utils/common' } from '~/manage/utils/common'
import ManageLogger from '~/manage/utils/logger' import ManageLogger from '~/manage/utils/logger'
import { formatHttpProxy, isImage } from '@/manage/utils/common' import { commonTaskStatus, IWindowList } from '#/types/enum'
import { formatHttpProxy, isImage } from '#/utils/common'
import { IWindowList } from '#/types/enum'
class ImgurApi { class ImgurApi {
userName: string userName: string

View File

@ -4,14 +4,13 @@ import path from 'path'
import * as fsWalk from '@nodelib/fs.walk' import * as fsWalk from '@nodelib/fs.walk'
import windowManager from 'apis/app/window/windowManager' 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 { formatError } from '~/manage/utils/common'
import ManageLogger from '~/manage/utils/logger' import ManageLogger from '~/manage/utils/logger'
import { isImage } from '@/manage/utils/common' import { commonTaskStatus, downloadTaskSpecialStatus, IWindowList, uploadTaskSpecialStatus } from '#/types/enum'
import { cancelDownloadLoadingFileList, refreshDownloadFileTransferList } from '@/manage/utils/static' import { isImage } from '#/utils/common'
import { cancelDownloadLoadingFileList, refreshDownloadFileTransferList } from '#/utils/static'
import { IWindowList } from '#/types/enum'
class LocalApi { class LocalApi {
logger: ManageLogger logger: ManageLogger

View File

@ -6,14 +6,13 @@ import qiniu from 'qiniu/index'
import windowManager from 'apis/app/window/windowManager' 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 { hmacSha1Base64, getFileMimeType, NewDownloader, formatError, ConcurrencyPromisePool } from '~/manage/utils/common'
import { ManageLogger } from '~/manage/utils/logger' import { ManageLogger } from '~/manage/utils/logger'
import { isImage } from '@/manage/utils/common' import { commonTaskStatus, IWindowList, uploadTaskSpecialStatus } from '#/types/enum'
import { cancelDownloadLoadingFileList, refreshDownloadFileTransferList } from '@/manage/utils/static' import { isImage } from '#/utils/common'
import { cancelDownloadLoadingFileList, refreshDownloadFileTransferList } from '#/utils/static'
import { IWindowList } from '#/types/enum'
class QiniuApi { class QiniuApi {
mac: qiniu.auth.digest.Mac mac: qiniu.auth.digest.Mac

View File

@ -27,15 +27,14 @@ import path from 'path'
import windowManager from 'apis/app/window/windowManager' import windowManager from 'apis/app/window/windowManager'
import UpDownTaskQueue, { uploadTaskSpecialStatus, commonTaskStatus } from '~/manage/datastore/upDownTaskQueue' import UpDownTaskQueue from '~/manage/datastore/upDownTaskQueue'
import { formatEndpoint, formatError, getAgent, getFileMimeType, NewDownloader, ConcurrencyPromisePool } from '~/manage/utils/common' import { formatError, getAgent, getFileMimeType, NewDownloader, ConcurrencyPromisePool } from '~/manage/utils/common'
import { dogecloudApi, DogecloudToken, getTempToken } from '~/manage/utils/dogeAPI' import { dogecloudApi, DogecloudToken, getTempToken } from '~/manage/utils/dogeAPI'
import { ManageLogger } from '~/manage/utils/logger' import { ManageLogger } from '~/manage/utils/logger'
import { isImage, formatHttpProxy } from '@/manage/utils/common' import { commonTaskStatus, IWindowList, uploadTaskSpecialStatus } from '#/types/enum'
import { cancelDownloadLoadingFileList, refreshDownloadFileTransferList } from '@/manage/utils/static' import { isImage, formatEndpoint, formatHttpProxy } from '#/utils/common'
import { cancelDownloadLoadingFileList, refreshDownloadFileTransferList } from '#/utils/static'
import { IWindowList } from '#/types/enum'
class S3plistApi { class S3plistApi {
baseOptions: S3ClientConfig baseOptions: S3ClientConfig

View File

@ -5,15 +5,14 @@ import windowManager from 'apis/app/window/windowManager'
import SSHClient from '~/utils/sshClient' 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 { formatError } from '~/manage/utils/common'
import ManageLogger from '~/manage/utils/logger' import ManageLogger from '~/manage/utils/logger'
import { isImage } from '@/manage/utils/common' import { commonTaskStatus, downloadTaskSpecialStatus, IWindowList, uploadTaskSpecialStatus } from '#/types/enum'
import { cancelDownloadLoadingFileList, refreshDownloadFileTransferList } from '@/manage/utils/static'
import { IWindowList } from '#/types/enum'
import { Undefinable } from '#/types/manage' import { Undefinable } from '#/types/manage'
import { isImage } from '#/utils/common'
import { cancelDownloadLoadingFileList, refreshDownloadFileTransferList } from '#/utils/static'
interface listDirResult { interface listDirResult {
permissions: string permissions: string

View File

@ -8,10 +8,10 @@ import windowManager from 'apis/app/window/windowManager'
import { getFileMimeType, gotUpload, NewDownloader, ConcurrencyPromisePool, formatError } from '~/manage/utils/common' import { getFileMimeType, gotUpload, NewDownloader, ConcurrencyPromisePool, formatError } from '~/manage/utils/common'
import { ManageLogger } from '~/manage/utils/logger' 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 { commonTaskStatus, IWindowList } from '#/types/enum'
import { IWindowList } from '#/types/enum' import { isImage } from '#/utils/common'
class SmmsApi { class SmmsApi {
baseUrl = 'https://smms.app/api/v2' baseUrl = 'https://smms.app/api/v2'

View File

@ -8,13 +8,11 @@ import windowManager from 'apis/app/window/windowManager'
import { formatError, getFileMimeType } from '~/manage/utils/common' import { formatError, getFileMimeType } from '~/manage/utils/common'
import { ManageLogger } from '~/manage/utils/logger' 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 { handleUrlEncode, isImage } from '#/utils/common'
import { cancelDownloadLoadingFileList, refreshDownloadFileTransferList } from '@/manage/utils/static' import { commonTaskStatus, downloadTaskSpecialStatus, IWindowList, uploadTaskSpecialStatus } from '#/types/enum'
import { cancelDownloadLoadingFileList, refreshDownloadFileTransferList } from '#/utils/static'
import { handleUrlEncode } from '#/utils/common'
import { IWindowList } from '#/types/enum'
class TcyunApi { class TcyunApi {
ctx: COS ctx: COS

View File

@ -9,12 +9,11 @@ import windowManager from 'apis/app/window/windowManager'
import { md5, hmacSha1Base64, getFileMimeType, NewDownloader, gotUpload, ConcurrencyPromisePool, formatError } from '~/manage/utils/common' import { md5, hmacSha1Base64, getFileMimeType, NewDownloader, gotUpload, ConcurrencyPromisePool, formatError } from '~/manage/utils/common'
import { ManageLogger } from '~/manage/utils/logger' 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 { commonTaskStatus, IWindowList } from '#/types/enum'
import { cancelDownloadLoadingFileList, refreshDownloadFileTransferList } from '@/manage/utils/static' import { isImage } from '#/utils/common'
import { cancelDownloadLoadingFileList, refreshDownloadFileTransferList } from '#/utils/static'
import { IWindowList } from '#/types/enum'
class UpyunApi { class UpyunApi {
ser: Upyun.Service ser: Upyun.Service

View File

@ -7,15 +7,15 @@ import { createClient, WebDAVClient, FileStat, ProgressEvent, AuthType, WebDAVCl
import windowManager from 'apis/app/window/windowManager' import windowManager from 'apis/app/window/windowManager'
import UpDownTaskQueue, { uploadTaskSpecialStatus, commonTaskStatus } from '~/manage/datastore/upDownTaskQueue' import UpDownTaskQueue from '~/manage/datastore/upDownTaskQueue'
import { formatError, formatEndpoint, getInnerAgent, NewDownloader, ConcurrencyPromisePool } from '~/manage/utils/common' import { formatError, getInnerAgent, NewDownloader, ConcurrencyPromisePool } from '~/manage/utils/common'
import ManageLogger from '~/manage/utils/logger' import ManageLogger from '~/manage/utils/logger'
import { formatHttpProxy, isImage } from '@/manage/utils/common'
import { getAuthHeader } from '@/manage/utils/digestAuth' 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 { class WebdavplistApi {
endpoint: string endpoint: string

View File

@ -1,12 +1,12 @@
import { JSONStore } from '@picgo/store' import { JSONStore } from '@picgo/store'
import { IJSON } from '@picgo/store/dist/types' import { IJSON } from '@picgo/store/dist/types'
import { ManageApiType, ManageConfigType } from '#/types/manage' import { IManageApiType, IManageConfigType } from '#/types/manage'
class ManageDB { class ManageDB {
readonly #ctx: ManageApiType readonly #ctx: IManageApiType
readonly #db: JSONStore readonly #db: JSONStore
constructor (ctx: ManageApiType) { constructor (ctx: IManageApiType) {
this.#ctx = ctx this.#ctx = ctx
this.#db = new JSONStore(this.#ctx.configPath) this.#db = new JSONStore(this.#ctx.configPath)
const initParams: IStringKeyMap = { const initParams: IStringKeyMap = {
@ -49,13 +49,13 @@ class ManageDB {
return this.#db.unset(key, value) return this.#db.unset(key, value)
} }
saveConfig (config: Partial<ManageConfigType>): void { saveConfig (config: Partial<IManageConfigType>): void {
Object.keys(config).forEach((name: string) => { Object.keys(config).forEach((name: string) => {
this.set(name, config[name]) this.set(name, config[name])
}) })
} }
removeConfig (config: ManageConfigType): void { removeConfig (config: IManageConfigType): void {
Object.keys(config).forEach((name: string) => { Object.keys(config).forEach((name: string) => {
this.unset(name, config[name]) this.unset(name, config[name])
}) })

View File

@ -5,56 +5,8 @@ import { app } from 'electron'
import fs from 'fs-extra' import fs from 'fs-extra'
import path from 'path' import path from 'path'
export enum commonTaskStatus { import { commonTaskStatus, downloadTaskSpecialStatus, uploadTaskSpecialStatus } from '#/types/enum'
queuing = 'queuing', import { IDownloadTask, IUploadTask } from '#/types/manage'
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
}
class UpDownTaskQueue { class UpDownTaskQueue {
/* eslint-disable */ /* eslint-disable */

View File

@ -7,7 +7,7 @@ import manageCoreIPC from '~/manage/events/manageCoreIPC'
import { ManageApi } from '~/manage/manageApi' import { ManageApi } from '~/manage/manageApi'
import { downloadFileFromUrl } from '~/manage/utils/common' import { downloadFileFromUrl } from '~/manage/utils/common'
import { selectDownloadFolder } from '@/manage/utils/static' import { selectDownloadFolder } from '#/utils/static'
export const manageIpcList = { export const manageIpcList = {
listen () { listen () {

View File

@ -14,24 +14,23 @@ import { managePathChecker } from '~/manage/datastore/dbChecker'
import { isInputConfigValid, formatError } from '~/manage/utils/common' import { isInputConfigValid, formatError } from '~/manage/utils/common'
import { ManageLogger } from '~/manage/utils/logger' import { ManageLogger } from '~/manage/utils/logger'
import { cancelDownloadLoadingFileList, refreshDownloadFileTransferList } from '@/manage/utils/static'
import { IWindowList } from '#/types/enum' import { IWindowList } from '#/types/enum'
import { import {
ManageApiType, IManageApiType,
ManageConfigType, IManageConfigType,
ManageError, IManageError,
PicBedMangeConfig IPicBedMangeConfig
} from '#/types/manage' } from '#/types/manage'
import { cancelDownloadLoadingFileList, refreshDownloadFileTransferList } from '#/utils/static'
export class ManageApi extends EventEmitter implements ManageApiType { export class ManageApi extends EventEmitter implements IManageApiType {
private _config!: Partial<ManageConfigType> private _config!: Partial<IManageConfigType>
private db!: ManageDB private db!: ManageDB
currentPicBed: string currentPicBed: string
configPath: string configPath: string
baseDir!: string baseDir!: string
logger: ManageLogger logger: ManageLogger
currentPicBedConfig: PicBedMangeConfig currentPicBedConfig: IPicBedMangeConfig
constructor (currentPicBed: string = '') { constructor (currentPicBed: string = '') {
super() super()
@ -85,8 +84,8 @@ export class ManageApi extends EventEmitter implements ManageApiType {
} }
} }
private getPicBedConfig (picBedName: string): PicBedMangeConfig { private getPicBedConfig (picBedName: string): IPicBedMangeConfig {
return this.getConfig<PicBedMangeConfig>(`picBed.${picBedName}`) return this.getConfig<IPicBedMangeConfig>(`picBed.${picBedName}`)
} }
private initConfigPath (): void { private initConfigPath (): void {
@ -106,7 +105,7 @@ export class ManageApi extends EventEmitter implements ManageApiType {
private initconfig (): void { private initconfig (): void {
this.db = new ManageDB(this) this.db = new ManageDB(this)
this._config = this.db.read(true) as ManageConfigType this._config = this.db.read(true) as IManageConfigType
} }
getConfig<T> (name?: string): T { getConfig<T> (name?: string): T {
@ -194,14 +193,14 @@ export class ManageApi extends EventEmitter implements ManageApiType {
async getBucketInfo ( async getBucketInfo (
param?: IStringKeyMap | undefined param?: IStringKeyMap | undefined
): Promise<IStringKeyMap | ManageError> { ): Promise<IStringKeyMap | IManageError> {
console.log(param) console.log(param)
return {} return {}
} }
async getBucketDomain ( async getBucketDomain (
param: IStringKeyMap param: IStringKeyMap
): Promise<IStringKeyMap | ManageError> { ): Promise<IStringKeyMap | IManageError> {
let client let client
switch (this.currentPicBedConfig.picBedName) { switch (this.currentPicBedConfig.picBedName) {
case 'tcyun': case 'tcyun':
@ -256,7 +255,7 @@ export class ManageApi extends EventEmitter implements ManageApiType {
async getOperatorList ( async getOperatorList (
param?: IStringKeyMap param?: IStringKeyMap
): Promise<string[] | ManageError> { ): Promise<string[] | IManageError> {
console.log(param) console.log(param)
return [] return []
} }
@ -277,7 +276,7 @@ export class ManageApi extends EventEmitter implements ManageApiType {
async getBucketAclPolicy ( async getBucketAclPolicy (
param?: IStringKeyMap param?: IStringKeyMap
): Promise<IStringKeyMap | ManageError> { ): Promise<IStringKeyMap | IManageError> {
console.log(param) console.log(param)
return {} return {}
} }
@ -302,7 +301,7 @@ export class ManageApi extends EventEmitter implements ManageApiType {
async getBucketListRecursively ( async getBucketListRecursively (
param?: IStringKeyMap param?: IStringKeyMap
): Promise<IStringKeyMap | ManageError> { ): Promise<IStringKeyMap | IManageError> {
let client let client
let window let window
const defaultResult = { const defaultResult = {
@ -347,7 +346,7 @@ export class ManageApi extends EventEmitter implements ManageApiType {
*/ */
async getBucketListBackstage ( async getBucketListBackstage (
param?: IStringKeyMap param?: IStringKeyMap
): Promise<IStringKeyMap | ManageError> { ): Promise<IStringKeyMap | IManageError> {
let client let client
let window let window
const defaultResult = { const defaultResult = {
@ -396,7 +395,7 @@ export class ManageApi extends EventEmitter implements ManageApiType {
**/ **/
async getBucketFileList ( async getBucketFileList (
param?: IStringKeyMap param?: IStringKeyMap
): Promise<IStringKeyMap | ManageError> { ): Promise<IStringKeyMap | IManageError> {
const defaultResponse = { const defaultResponse = {
fullList: <any>[], fullList: <any>[],
isTruncated: false, isTruncated: false,

View File

@ -12,15 +12,11 @@ import path from 'path'
import { Stream } from 'stream' import { Stream } from 'stream'
import { promisify } from 'util' import { promisify } from 'util'
import UpDownTaskQueue, import UpDownTaskQueue from '~/manage/datastore/upDownTaskQueue'
{
uploadTaskSpecialStatus,
commonTaskStatus,
downloadTaskSpecialStatus
} from '~/manage/datastore/upDownTaskQueue'
import { ManageLogger } from '~/manage/utils/logger' 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 ( export const getFSFile = async (
filePath: string, filePath: string,
@ -218,8 +214,6 @@ export const formatError = (err: any, params:IStringKeyMap) => {
return `${String(err)}${JSON.stringify(params)}` return `${String(err)}${JSON.stringify(params)}`
} }
export const trimPath = (path: string) => path.replace(/^\/+|\/+$/g, '').replace(/\/+/g, '/')
const commonOptions = { const commonOptions = {
keepAlive: true, keepAlive: true,
keepAliveMsecs: 1000, 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 { export class ConcurrencyPromisePool {
limit: number limit: number
queue: any[] queue: any[]

View File

@ -6,7 +6,7 @@ import { ILogColor, ILogger } from 'piclist/dist/types'
import util from 'util' import util from 'util'
import { ILogType } from '#/types/enum' import { ILogType } from '#/types/enum'
import { ManageApiType, Undefinable } from '#/types/manage' import { IManageApiType, Undefinable } from '#/types/manage'
import { enforceNumber, isDev } from '#/utils/common' import { enforceNumber, isDev } from '#/utils/common'
import { configPaths } from '#/utils/configPaths' import { configPaths } from '#/utils/configPaths'
@ -18,11 +18,11 @@ export class ManageLogger implements ILogger {
[ILogType.error]: 'red' [ILogType.error]: 'red'
} }
readonly #ctx: ManageApiType readonly #ctx: IManageApiType
#logLevel!: string #logLevel!: string
#logPath!: string #logPath!: string
constructor (ctx: ManageApiType) { constructor (ctx: IManageApiType) {
this.#ctx = ctx this.#ctx = ctx
} }

View File

@ -2,7 +2,7 @@ import { AuthType, WebDAVClientOptions, createClient } from 'webdav'
import { deleteFailedLog, deleteLog } from '@/utils/common' import { deleteFailedLog, deleteLog } from '@/utils/common'
import { formatEndpoint } from '~/manage/utils/common' import { formatEndpoint } from '#/utils/common'
interface IConfigMap { interface IConfigMap {
fileName: string fileName: string

View File

@ -26,7 +26,7 @@ import { Loading } from '@element-plus/icons-vue'
import { getAuthHeader } from '@/manage/utils/digestAuth' import { getAuthHeader } from '@/manage/utils/digestAuth'
import { getFileIconPath } from '@/manage/utils/common' import { getFileIconPath } from '@/manage/utils/common'
import { formatEndpoint } from '~/manage/utils/common' import { formatEndpoint } from '#/utils/common'
const base64Url = ref('') const base64Url = ref('')
const success = ref(false) const success = ref(false)

View File

@ -5,7 +5,7 @@ import { Loading } from '@element-plus/icons-vue'
import { getFileIconPath } from '@/manage/utils/common' import { getFileIconPath } from '@/manage/utils/common'
import { getAuthHeader } from '@/manage/utils/digestAuth' import { getAuthHeader } from '@/manage/utils/digestAuth'
import { formatEndpoint } from '~/manage/utils/common' import { formatEndpoint } from '#/utils/common'
export default defineComponent({ export default defineComponent({
props: { props: {

View File

@ -1467,9 +1467,8 @@ import { useRoute } from 'vue-router'
import { fileCacheDbInstance } from '@/manage/store/bucketFileDb' import { fileCacheDbInstance } from '@/manage/store/bucketFileDb'
import { useFileTransferStore, useDownloadFileTransferStore, useManageStore } from '@/manage/store/manageStore' 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 { getConfig, saveConfig } from '@/manage/utils/dataSender'
import { cancelDownloadLoadingFileList, refreshDownloadFileTransferList } from '@/manage/utils/static'
import { textFileExt } from '@/manage/utils/textfile' import { textFileExt } from '@/manage/utils/textfile'
import { videoExt } from '@/manage/utils/videofile' import { videoExt } from '@/manage/utils/videofile'
@ -1479,8 +1478,10 @@ import ImageWebdavTsx from '@/components/ImageWebdavTsx'
import { T as $T } from '@/i18n' import { T as $T } from '@/i18n'
import { IUploadTask, IDownloadTask } from '~/manage/datastore/upDownTaskQueue' import { getExtension, trimPath } from '#/utils/common'
import { trimPath } from '~/manage/utils/common' import { cancelDownloadLoadingFileList, refreshDownloadFileTransferList } from '#/utils/static'
import { IUploadTask, IDownloadTask } from '#/types/manage'
/* /*
configMap:{ configMap:{
prefix: string, -> baseDir prefix: string, -> baseDir

View File

@ -281,8 +281,7 @@ import { formObjToTableData, svg } from '@/manage/utils/common'
import { getConfig as getPicBedsConfig } from '@/utils/dataSender' import { getConfig as getPicBedsConfig } from '@/utils/dataSender'
import { T as $T } from '@/i18n' import { T as $T } from '@/i18n'
import { formatEndpoint } from '~/manage/utils/common' import { formatEndpoint, isNeedToShorten, safeSliceF } from '#/utils/common'
import { isNeedToShorten, safeSliceF } from '#/utils/common'
const manageStore = useManageStore() const manageStore = useManageStore()
const router = useRouter() const router = useRouter()

View File

@ -249,10 +249,11 @@ import DynamicSwitch from '@/manage/components/DynamicSwitch.vue'
import { fileCacheDbInstance } from '@/manage/store/bucketFileDb' import { fileCacheDbInstance } from '@/manage/store/bucketFileDb'
import { formatFileSize, customRenameFormatTable } from '@/manage/utils/common' import { formatFileSize, customRenameFormatTable } from '@/manage/utils/common'
import { getConfig, saveConfig, invokeToMain } from '@/manage/utils/dataSender' import { getConfig, saveConfig, invokeToMain } from '@/manage/utils/dataSender'
import { selectDownloadFolder } from '@/manage/utils/static'
import { T as $T } from '@/i18n' import { T as $T } from '@/i18n'
import { selectDownloadFolder } from '#/utils/static'
const form = ref<IStringKeyMap>({ const form = ref<IStringKeyMap>({
timestampRename: false, timestampRename: false,
randomStringRename: false, randomStringRename: false,

View File

@ -118,11 +118,6 @@ export function formatFileName (fileName: string, length: number = 20) {
return isNeedToShorten(fileName, length) ? `${safeSliceF(name, length - 3 - ext.length)}...${ext}` : fileName 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) { export function formObjToTableData (obj: any) {
const exclude = [undefined, null, '', 'transformedConfig'] const exclude = [undefined, null, '', 'transformedConfig']
return Object.keys(obj).filter(key => !exclude.includes(obj[key])).map(key => ({ 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 = ` export const svg = `
<path class="path" d=" <path class="path" d="
M 30 15 M 30 15

View File

@ -1,3 +0,0 @@
export const cancelDownloadLoadingFileList = 'cancelDownloadLoadingFileList'
export const refreshDownloadFileTransferList = 'refreshDownloadFileTransferList'
export const selectDownloadFolder = 'selectDownloadFolder'

View File

@ -115,3 +115,20 @@ export enum IShortUrlServer {
YOURLS = 'yourls', YOURLS = 'yourls',
CFWORKER = 'cf_worker' CFWORKER = 'cf_worker'
} }
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',
}

View File

@ -1,22 +1,19 @@
import { ILogger } from "piclist/dist/types"; import { ILogger } from 'piclist/dist/types'
import { commonTaskStatus, downloadTaskSpecialStatus, uploadTaskSpecialStatus } from './enum'
// common type // common type
type Undefinable<T> = T | undefined; export type Undefinable<T> = T | undefined;
declare interface ManageError extends Error { export interface IManageError extends Error {
code?: number code?: number
param?: string param?: string
stack?: string stack?: string
picbed?: string picbed?: string
} }
type PicBedMangeConfig = IStringKeyMap; export type IPicBedMangeConfig = IStringKeyMap;
interface PicBedManageConfigMap { export interface IManageApiType {
[key: string]: PicBedMangeConfig
}
interface ManageApiType {
/** /**
* logger * logger
*/ */
@ -36,7 +33,7 @@ interface ManageApiType {
/** /**
* current picBed config * current picBed config
*/ */
currentPicBedConfig: PicBedMangeConfig currentPicBedConfig: IPicBedMangeConfig
/** /**
* get manage config * get manage config
*/ */
@ -62,19 +59,19 @@ interface ManageApiType {
*/ */
getBucketListRecursively: ( getBucketListRecursively: (
param?: IStringKeyMap param?: IStringKeyMap
) => Promise<any | ManageError> ) => Promise<any | IManageError>
/** /**
* get bucket list * get bucket list
*/ */
getBucketListBackstage: ( getBucketListBackstage: (
param?: IStringKeyMap param?: IStringKeyMap
) => Promise<any | ManageError> ) => Promise<any | IManageError>
/** /**
* get bucket list * get bucket list
*/ */
getBucketList: ( getBucketList: (
param?: IStringKeyMap param?: IStringKeyMap
) => Promise<any | ManageError> ) => Promise<any | IManageError>
getBucketDomain: ( getBucketDomain: (
param: IStringKeyMap param: IStringKeyMap
) => Promise<any> ) => Promise<any>
@ -83,7 +80,7 @@ interface ManageApiType {
*/ */
getBucketInfo: ( getBucketInfo: (
param?: IStringKeyMap param?: IStringKeyMap
) => Promise<IStringKeyMap | ManageError> ) => Promise<IStringKeyMap | IManageError>
/** /**
* create bucket * create bucket
*/ */
@ -102,7 +99,7 @@ interface ManageApiType {
*/ */
getOperatorList: ( getOperatorList: (
param?: IStringKeyMap param?: IStringKeyMap
) => Promise<string[] | ManageError> ) => Promise<string[] | IManageError>
/** /**
* add Operator * add Operator
* specific for upyun * specific for upyun
@ -122,7 +119,7 @@ interface ManageApiType {
*/ */
getBucketAclPolicy: ( getBucketAclPolicy: (
param?: IStringKeyMap param?: IStringKeyMap
) => Promise<IStringKeyMap | ManageError> ) => Promise<IStringKeyMap | IManageError>
/** /**
* set bucket ACL policy * set bucket ACL policy
*/ */
@ -134,7 +131,7 @@ interface ManageApiType {
*/ */
getBucketFileList: ( getBucketFileList: (
param?: IStringKeyMap param?: IStringKeyMap
) => Promise<IStringKeyMap | ManageError> ) => Promise<IStringKeyMap | IManageError>
/** /**
* delete bucket file * delete bucket file
*/ */
@ -177,7 +174,7 @@ interface ManageApiType {
uploadBucketFile: ( uploadBucketFile: (
param?: IStringKeyMap param?: IStringKeyMap
) => Promise<boolean> ) => Promise<boolean>
/** /**
* get presigned url * get presigned url
*/ */
getPreSignedUrl: ( getPreSignedUrl: (
@ -186,7 +183,7 @@ interface ManageApiType {
} }
/** PicList 存储管理功能配置文件类型定义 */ /** PicList 存储管理功能配置文件类型定义 */
interface ManageConfigType { export interface IManageConfigType {
picBed: { picBed: {
[others: string]: any [others: string]: any
} }
@ -195,3 +192,37 @@ interface ManageConfigType {
} }
[others: string]: any [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
}

View File

@ -35,6 +35,8 @@ interface IServerConfig {
enable: boolean enable: boolean
} }
// Sync
interface ISyncConfig { interface ISyncConfig {
type: string type: string
file?: string file?: string
@ -528,3 +530,9 @@ interface IUploaderConfigItem {
type IUploaderConfigListItem = IStringKeyMap & IUploaderListItemMetaInfo type IUploaderConfigListItem = IStringKeyMap & IUploaderListItemMetaInfo
type ICheckBoxValueType = boolean | string | number type ICheckBoxValueType = boolean | string | number
interface IHTTPProxy {
host: string
port: number
protocol: string
}

View File

@ -1,3 +1,5 @@
import path from 'path'
export const isUrl = (url: string): boolean => { export const isUrl = (url: string): boolean => {
try { try {
return Boolean(new URL(url)) return Boolean(new URL(url))
@ -68,3 +70,39 @@ export function encodeFilePath (filePath: string) {
.map(encodeURIComponent) .map(encodeURIComponent)
.join('/') .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'
}
}

View File

@ -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 RELEASE_URL_BACKUP = 'https://release.piclist.cn'
export const STABLE_RELEASE_URL = 'https://github.com/Kuingsmile/PicList/releases/latest' 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 = [ export const picBedsCanbeDeleted = [
'aliyun', 'aliyun',
'alist', 'alist',
@ -63,5 +69,3 @@ export const picBedManualUrlList: IStringKeyMap = {
webdavplist: 'https://piclist.cn/en/configure.html#webdav' webdavplist: 'https://piclist.cn/en/configure.html#webdav'
} }
} }
export const DEFAULT_AES_PASSWORD = 'aesPassword'