mirror of
https://github.com/Kuingsmile/PicList.git
synced 2025-01-23 06:38:13 -05:00
🔨 Refactor(custom): refactored imports
This commit is contained in:
parent
e87e3999b4
commit
19c12b6b02
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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'
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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<ManageConfigType>): void {
|
||||
saveConfig (config: Partial<IManageConfigType>): 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])
|
||||
})
|
||||
|
@ -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 */
|
||||
|
@ -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 () {
|
||||
|
@ -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<ManageConfigType>
|
||||
export class ManageApi extends EventEmitter implements IManageApiType {
|
||||
private _config!: Partial<IManageConfigType>
|
||||
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<PicBedMangeConfig>(`picBed.${picBedName}`)
|
||||
private getPicBedConfig (picBedName: string): IPicBedMangeConfig {
|
||||
return this.getConfig<IPicBedMangeConfig>(`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<T> (name?: string): T {
|
||||
@ -194,14 +193,14 @@ export class ManageApi extends EventEmitter implements ManageApiType {
|
||||
|
||||
async getBucketInfo (
|
||||
param?: IStringKeyMap | undefined
|
||||
): Promise<IStringKeyMap | ManageError> {
|
||||
): Promise<IStringKeyMap | IManageError> {
|
||||
console.log(param)
|
||||
return {}
|
||||
}
|
||||
|
||||
async getBucketDomain (
|
||||
param: IStringKeyMap
|
||||
): Promise<IStringKeyMap | ManageError> {
|
||||
): Promise<IStringKeyMap | IManageError> {
|
||||
let client
|
||||
switch (this.currentPicBedConfig.picBedName) {
|
||||
case 'tcyun':
|
||||
@ -256,7 +255,7 @@ export class ManageApi extends EventEmitter implements ManageApiType {
|
||||
|
||||
async getOperatorList (
|
||||
param?: IStringKeyMap
|
||||
): Promise<string[] | ManageError> {
|
||||
): Promise<string[] | IManageError> {
|
||||
console.log(param)
|
||||
return []
|
||||
}
|
||||
@ -277,7 +276,7 @@ export class ManageApi extends EventEmitter implements ManageApiType {
|
||||
|
||||
async getBucketAclPolicy (
|
||||
param?: IStringKeyMap
|
||||
): Promise<IStringKeyMap | ManageError> {
|
||||
): Promise<IStringKeyMap | IManageError> {
|
||||
console.log(param)
|
||||
return {}
|
||||
}
|
||||
@ -302,7 +301,7 @@ export class ManageApi extends EventEmitter implements ManageApiType {
|
||||
|
||||
async getBucketListRecursively (
|
||||
param?: IStringKeyMap
|
||||
): Promise<IStringKeyMap | ManageError> {
|
||||
): Promise<IStringKeyMap | IManageError> {
|
||||
let client
|
||||
let window
|
||||
const defaultResult = {
|
||||
@ -347,7 +346,7 @@ export class ManageApi extends EventEmitter implements ManageApiType {
|
||||
*/
|
||||
async getBucketListBackstage (
|
||||
param?: IStringKeyMap
|
||||
): Promise<IStringKeyMap | ManageError> {
|
||||
): Promise<IStringKeyMap | IManageError> {
|
||||
let client
|
||||
let window
|
||||
const defaultResult = {
|
||||
@ -396,7 +395,7 @@ export class ManageApi extends EventEmitter implements ManageApiType {
|
||||
**/
|
||||
async getBucketFileList (
|
||||
param?: IStringKeyMap
|
||||
): Promise<IStringKeyMap | ManageError> {
|
||||
): Promise<IStringKeyMap | IManageError> {
|
||||
const defaultResponse = {
|
||||
fullList: <any>[],
|
||||
isTruncated: false,
|
||||
|
@ -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[]
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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: {
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
|
@ -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<IStringKeyMap>({
|
||||
timestampRename: false,
|
||||
randomStringRename: false,
|
||||
|
@ -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 = `
|
||||
<path class="path" d="
|
||||
M 30 15
|
||||
|
@ -1,3 +0,0 @@
|
||||
export const cancelDownloadLoadingFileList = 'cancelDownloadLoadingFileList'
|
||||
export const refreshDownloadFileTransferList = 'refreshDownloadFileTransferList'
|
||||
export const selectDownloadFolder = 'selectDownloadFolder'
|
@ -115,3 +115,20 @@ export enum IShortUrlServer {
|
||||
YOURLS = 'yourls',
|
||||
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',
|
||||
}
|
||||
|
@ -1,22 +1,19 @@
|
||||
import { ILogger } from "piclist/dist/types";
|
||||
import { ILogger } from 'piclist/dist/types'
|
||||
import { commonTaskStatus, downloadTaskSpecialStatus, uploadTaskSpecialStatus } from './enum'
|
||||
|
||||
// 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
|
||||
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<any | ManageError>
|
||||
) => Promise<any | IManageError>
|
||||
/**
|
||||
* get bucket list
|
||||
*/
|
||||
getBucketListBackstage: (
|
||||
param?: IStringKeyMap
|
||||
) => Promise<any | ManageError>
|
||||
) => Promise<any | IManageError>
|
||||
/**
|
||||
* get bucket list
|
||||
*/
|
||||
getBucketList: (
|
||||
param?: IStringKeyMap
|
||||
) => Promise<any | ManageError>
|
||||
) => Promise<any | IManageError>
|
||||
getBucketDomain: (
|
||||
param: IStringKeyMap
|
||||
) => Promise<any>
|
||||
@ -83,7 +80,7 @@ interface ManageApiType {
|
||||
*/
|
||||
getBucketInfo: (
|
||||
param?: IStringKeyMap
|
||||
) => Promise<IStringKeyMap | ManageError>
|
||||
) => Promise<IStringKeyMap | IManageError>
|
||||
/**
|
||||
* create bucket
|
||||
*/
|
||||
@ -102,7 +99,7 @@ interface ManageApiType {
|
||||
*/
|
||||
getOperatorList: (
|
||||
param?: IStringKeyMap
|
||||
) => Promise<string[] | ManageError>
|
||||
) => Promise<string[] | IManageError>
|
||||
/**
|
||||
* add Operator
|
||||
* specific for upyun
|
||||
@ -122,7 +119,7 @@ interface ManageApiType {
|
||||
*/
|
||||
getBucketAclPolicy: (
|
||||
param?: IStringKeyMap
|
||||
) => Promise<IStringKeyMap | ManageError>
|
||||
) => Promise<IStringKeyMap | IManageError>
|
||||
/**
|
||||
* set bucket ACL policy
|
||||
*/
|
||||
@ -134,7 +131,7 @@ interface ManageApiType {
|
||||
*/
|
||||
getBucketFileList: (
|
||||
param?: IStringKeyMap
|
||||
) => Promise<IStringKeyMap | ManageError>
|
||||
) => Promise<IStringKeyMap | IManageError>
|
||||
/**
|
||||
* delete bucket file
|
||||
*/
|
||||
@ -177,7 +174,7 @@ interface ManageApiType {
|
||||
uploadBucketFile: (
|
||||
param?: IStringKeyMap
|
||||
) => Promise<boolean>
|
||||
/**
|
||||
/**
|
||||
* 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
|
||||
}
|
8
src/universal/types/types.d.ts
vendored
8
src/universal/types/types.d.ts
vendored
@ -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
|
||||
}
|
@ -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'
|
||||
}
|
||||
}
|
||||
|
@ -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'
|
||||
|
Loading…
Reference in New Issue
Block a user