mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-05-06 20:42:57 +08:00
🚧 WIP(custom): support picbed specific image preprocess and rename config
This commit is contained in:
@@ -13,7 +13,7 @@ import writeFile from 'write-file-atomic'
|
||||
|
||||
import { GET_RENAME_FILE_NAME, RENAME_FILE_NAME } from '~/events/constant'
|
||||
import { T as $t } from '~/i18n'
|
||||
import { getClipboardFilePath, showNotification } from '~/utils/common'
|
||||
import { getClipboardFilePath, getUploaderType, showNotification } from '~/utils/common'
|
||||
import { configPaths } from '~/utils/configPaths'
|
||||
import { ICOREBuildInEvent, IWindowList } from '~/utils/enum'
|
||||
import { CLIPBOARD_IMAGE_FOLDER } from '~/utils/static'
|
||||
@@ -60,8 +60,15 @@ class Uploader {
|
||||
|
||||
picgo.helper.beforeUploadPlugins.register('renameFn', {
|
||||
handle: async (ctx: IPicGo) => {
|
||||
const rename = db.get(configPaths.settings.rename)
|
||||
const autoRename = db.get(configPaths.settings.autoRename)
|
||||
const uploaderType = getUploaderType(ctx)
|
||||
|
||||
const globalRename = db.get(configPaths.settings.rename)
|
||||
const globalAutoRename = db.get(configPaths.settings.autoRename)
|
||||
const buildInList = db.get(configPaths.buildIn.list._name) || []
|
||||
const idSpecificRename = buildInList.find((item: any) => item.id === uploaderType.id)?.manualRename
|
||||
const idSpecificAutoRename = buildInList.find((item: any) => item.id === uploaderType.id)?.autoRename
|
||||
const rename = idSpecificRename !== undefined ? !!idSpecificRename : !!globalRename
|
||||
const autoRename = idSpecificAutoRename !== undefined ? !!idSpecificAutoRename : !!globalAutoRename
|
||||
if (autoRename || rename) {
|
||||
await Promise.all(
|
||||
ctx.output.map(async (item, index) => {
|
||||
|
||||
@@ -7,6 +7,7 @@ import { clipboard, Notification, Tray } from 'electron'
|
||||
import { gunzipSync, gzipSync, strFromU8 } from 'fflate'
|
||||
import FormData from 'form-data'
|
||||
import fs from 'fs-extra'
|
||||
import { IPicGo } from 'piclist'
|
||||
import { isReactive, isRef, toRaw, unref } from 'vue'
|
||||
|
||||
import { configPaths } from '~/utils/configPaths'
|
||||
@@ -341,3 +342,16 @@ export const zipData = async (data: Record<string, any>, zipPath: string): Promi
|
||||
throw new Error('Zip failed')
|
||||
}
|
||||
}
|
||||
|
||||
export function getUploaderType(ctx: IPicGo): {
|
||||
picBed: string
|
||||
id?: string
|
||||
} {
|
||||
const picBed =
|
||||
ctx.getConfig<Undefinable<string>>('picBed.uploader') ||
|
||||
ctx.getConfig<Undefinable<string>>('picBed.current') ||
|
||||
'smms'
|
||||
const picBedConfig = ctx.getConfig<Undefinable<IStringKeyMap>>(`picBed.${picBed}`) || {}
|
||||
const id = picBedConfig._id || ''
|
||||
return { picBed, id }
|
||||
}
|
||||
|
||||
@@ -184,6 +184,23 @@ export const configPaths = {
|
||||
watermark: 'buildIn.watermark',
|
||||
rename: 'buildIn.rename',
|
||||
skipProcess: 'buildIn.skipProcess',
|
||||
list: {
|
||||
_name: 'buildIn.list',
|
||||
id: 'buildIn.list.id',
|
||||
compress: 'buildIn.list.compress',
|
||||
watermark: 'buildIn.list.watermark',
|
||||
skipProcess: {
|
||||
_name: 'buildIn.list.skipProcess',
|
||||
skipProcessExtList: 'buildIn.list.skipProcess.skipProcessExtList',
|
||||
},
|
||||
rename: {
|
||||
_name: 'buildIn.list.rename',
|
||||
enable: 'buildIn.list.rename.enable',
|
||||
format: 'buildIn.list.rename.format',
|
||||
},
|
||||
autoRename: 'buildIn.list.autoRename',
|
||||
manualRename: 'buildIn.list.manualRename',
|
||||
},
|
||||
},
|
||||
debug: 'debug',
|
||||
PICGO_ENV: 'PICGO_ENV',
|
||||
|
||||
15
src/universal/types/types.d.ts
vendored
15
src/universal/types/types.d.ts
vendored
@@ -506,3 +506,18 @@ interface IGalleryDBFile {
|
||||
gallery: IGalleryDBGalleryItem[]
|
||||
__gallery_KEY__: Record<string, number>
|
||||
}
|
||||
|
||||
interface IBuildInListItem {
|
||||
id: string
|
||||
compress?: Partial<import('piclist').IBuildInCompressOptionsTreated>
|
||||
watermark?: Partial<import('piclist').IBuildInWaterMarkOptionsTreated>
|
||||
skipProcess?: import('piclist').IBuildInSkipProcessOptions
|
||||
rename?: {
|
||||
enable?: boolean
|
||||
format?: string
|
||||
}
|
||||
// settings.autoRename
|
||||
autoRename?: boolean
|
||||
// settings.rename
|
||||
manualRename?: boolean
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user