mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-06-02 22:31:49 +08:00
🔨 Refactor(custom): add config file type
This commit is contained in:
@@ -1,8 +1,18 @@
|
||||
import axios from 'axios'
|
||||
import path from 'path'
|
||||
|
||||
interface IConfigMap {
|
||||
fileName: string
|
||||
config: {
|
||||
version: string
|
||||
url: string
|
||||
uploadPath: string
|
||||
token: string
|
||||
}
|
||||
}
|
||||
|
||||
export default class AlistApi {
|
||||
static async delete (configMap: IStringKeyMap): Promise<boolean> {
|
||||
static async delete (configMap: IConfigMap): Promise<boolean> {
|
||||
const { fileName, config } = configMap
|
||||
try {
|
||||
const { version, url, uploadPath, token } = config
|
||||
|
||||
@@ -2,13 +2,7 @@ import OSS from 'ali-oss'
|
||||
|
||||
interface IConfigMap {
|
||||
fileName: string
|
||||
config: {
|
||||
accessKeyId: string
|
||||
accessKeySecret: string
|
||||
bucket: string
|
||||
area: string
|
||||
path?: string
|
||||
}
|
||||
config: PartialKeys<IAliYunConfig, 'path'>
|
||||
}
|
||||
|
||||
export default class AliyunApi {
|
||||
|
||||
@@ -3,12 +3,7 @@ import { Octokit } from '@octokit/rest'
|
||||
interface IConfigMap {
|
||||
fileName: string
|
||||
hash: string
|
||||
config: {
|
||||
repo: string
|
||||
token: string
|
||||
branch: string
|
||||
path?: string
|
||||
}
|
||||
config: PartialKeys<IGitHubConfig, 'path'>
|
||||
}
|
||||
|
||||
export default class GithubApi {
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
import axios, { AxiosResponse } from 'axios'
|
||||
|
||||
interface IConfigMap {
|
||||
config?: {
|
||||
clientId?: string
|
||||
username?: string
|
||||
accessToken?: string
|
||||
}
|
||||
config?: Partial<IImgurConfig>
|
||||
hash?: string
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
import Qiniu from 'qiniu'
|
||||
|
||||
interface IConfigMap {
|
||||
fileName: string;
|
||||
config: {
|
||||
accessKey: string;
|
||||
secretKey: string;
|
||||
bucket: string;
|
||||
path?: string;
|
||||
}
|
||||
fileName: string
|
||||
config: PartialKeys<IQiniuConfig, 'path'>
|
||||
}
|
||||
|
||||
export default class QiniuApi {
|
||||
|
||||
@@ -2,9 +2,7 @@ import axios, { AxiosResponse } from 'axios'
|
||||
|
||||
interface IConfigMap {
|
||||
hash?: string
|
||||
config?: {
|
||||
token?: string
|
||||
}
|
||||
config?: Partial<ISMMSConfig>
|
||||
}
|
||||
|
||||
export default class SmmsApi {
|
||||
|
||||
@@ -1,14 +1,8 @@
|
||||
import COS from 'cos-nodejs-sdk-v5'
|
||||
|
||||
interface IConfigMap {
|
||||
fileName: string;
|
||||
config: {
|
||||
secretId: string;
|
||||
secretKey: string;
|
||||
bucket: string;
|
||||
area: string;
|
||||
path?: string;
|
||||
};
|
||||
fileName: string
|
||||
config: PartialKeys<ITcYunConfig, 'path'>
|
||||
}
|
||||
|
||||
export default class TcyunApi {
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
import Upyun from 'upyun'
|
||||
|
||||
interface IConfigMap {
|
||||
fileName: string
|
||||
config: PartialKeys<IUpYunConfig, 'path'>
|
||||
}
|
||||
|
||||
export default class UpyunApi {
|
||||
static async delete (configMap: IStringKeyMap): Promise<boolean> {
|
||||
static async delete (configMap: IConfigMap): Promise<boolean> {
|
||||
const { fileName, config: { bucket, operator, password, path } } = configMap
|
||||
try {
|
||||
const service = new Upyun.Service(bucket, operator, password)
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
import { AuthType, WebDAVClientOptions, createClient } from 'webdav'
|
||||
import { formatEndpoint } from '~/main/manage/utils/common'
|
||||
|
||||
interface IConfigMap {
|
||||
fileName: string
|
||||
config: PartialKeys<IWebdavPlistConfig, 'path'>
|
||||
}
|
||||
|
||||
export default class WebdavApi {
|
||||
static async delete (configMap: IStringKeyMap): Promise<boolean> {
|
||||
static async delete (configMap: IConfigMap): Promise<boolean> {
|
||||
const { fileName, config: { host, username, password, path, sslEnabled, authType } } = configMap
|
||||
const endpoint = formatEndpoint(host, sslEnabled)
|
||||
const options: WebDAVClientOptions = {
|
||||
|
||||
@@ -279,6 +279,8 @@ import {
|
||||
// 数据发送工具函数
|
||||
import { getConfig, saveConfig, sendToMain } from '@/utils/dataSender'
|
||||
import { openURL } from '@/utils/common'
|
||||
import { configPaths, manualPageOpenType } from '~/universal/utils/configPaths'
|
||||
import { II18nLanguage } from '~/universal/types/enum'
|
||||
|
||||
const version = ref(process.env.NODE_ENV === 'production' ? pkg.version : 'Dev')
|
||||
const routerConfig = reactive(config)
|
||||
@@ -326,10 +328,10 @@ const handleGetPicPeds = () => {
|
||||
const handleSelect = async (index: string) => {
|
||||
defaultActive.value = index
|
||||
if (index === routerConfig.DocumentPage) {
|
||||
const manualPageOpenSetting = await getConfig('settings.manualPageOpen')
|
||||
const lang = await getConfig('settings.language') || 'zh-CN'
|
||||
const manualPageOpenSetting = await getConfig<manualPageOpenType>(configPaths.settings.manualPageOpen)
|
||||
const lang = await getConfig(configPaths.settings.language) || II18nLanguage.ZH_CN
|
||||
const openManual = () => ipcRenderer.send('openManualWindow')
|
||||
const openExternal = () => openURL(lang === 'zh-CN' ? 'https://piclist.cn/app.html' : 'https://piclist.cn/en/app.html')
|
||||
const openExternal = () => openURL(lang === II18nLanguage.ZH_CN ? 'https://piclist.cn/app.html' : 'https://piclist.cn/en/app.html')
|
||||
|
||||
if (!manualPageOpenSetting) {
|
||||
ElMessageBox.confirm($T('MANUAL_PAGE_OPEN_TIP'), $T('MANUAL_PAGE_OPEN_TIP_TITLE'), {
|
||||
@@ -338,10 +340,10 @@ const handleSelect = async (index: string) => {
|
||||
type: 'info',
|
||||
center: true
|
||||
}).then(() => {
|
||||
saveConfig('settings.manualPageOpen', 'browser')
|
||||
saveConfig(configPaths.settings.manualPageOpen, 'browser')
|
||||
openExternal()
|
||||
}).catch(() => {
|
||||
saveConfig('settings.manualPageOpen', 'window')
|
||||
saveConfig(configPaths.settings.manualPageOpen, 'window')
|
||||
openManual()
|
||||
})
|
||||
} else {
|
||||
|
||||
@@ -11,7 +11,7 @@ import Dexie, { Table } from 'dexie'
|
||||
*/
|
||||
|
||||
export interface IFileCache {
|
||||
key: string,
|
||||
key: string
|
||||
value: any
|
||||
}
|
||||
|
||||
|
||||
@@ -499,6 +499,8 @@ import ALLApi from '@/apis/allApi'
|
||||
import { customRenameFormatTable, customStrMatch, customStrReplace } from '../manage/utils/common'
|
||||
import { picBedsCanbeDeleted } from '#/utils/static'
|
||||
import path from 'path'
|
||||
import { configPaths } from '~/universal/utils/configPaths'
|
||||
import { IPasteStyle } from '~/universal/types/enum'
|
||||
|
||||
const images = ref<ImgInfo[]>([])
|
||||
const dialogVisible = ref(false)
|
||||
@@ -731,7 +733,7 @@ function remove (item: ImgInfo) {
|
||||
type: 'warning'
|
||||
}).then(async () => {
|
||||
const file = await $$db.getById(item.id!)
|
||||
if (await getConfig('settings.deleteCloudFile') && picBedsCanbeDeleted.includes(item?.type || 'placeholder')) {
|
||||
if (await getConfig(configPaths.settings.deleteCloudFile) && picBedsCanbeDeleted.includes(item?.type || 'placeholder')) {
|
||||
const result = await ALLApi.delete(item)
|
||||
if (result) {
|
||||
ElNotification({
|
||||
@@ -767,7 +769,7 @@ function remove (item: ImgInfo) {
|
||||
|
||||
function handleDeleteCloudFile (val: ICheckBoxValueType) {
|
||||
saveConfig({
|
||||
'settings.deleteCloudFile': val
|
||||
[configPaths.settings.deleteCloudFile]: val
|
||||
})
|
||||
}
|
||||
|
||||
@@ -825,7 +827,7 @@ function multiRemove () {
|
||||
}).then(async () => {
|
||||
const files: IResult<ImgInfo>[] = []
|
||||
const imageIDList = Object.keys(choosedList)
|
||||
const isDeleteCloudFile = await getConfig('settings.deleteCloudFile')
|
||||
const isDeleteCloudFile = await getConfig(configPaths.settings.deleteCloudFile)
|
||||
if (isDeleteCloudFile) {
|
||||
for (let i = 0; i < imageIDList.length; i++) {
|
||||
const key = imageIDList[i]
|
||||
@@ -919,12 +921,12 @@ function toggleHandleBar () {
|
||||
}
|
||||
|
||||
async function handlePasteStyleChange (val: string) {
|
||||
saveConfig('settings.pasteStyle', val)
|
||||
saveConfig(configPaths.settings.pasteStyle, val)
|
||||
pasteStyle.value = val
|
||||
}
|
||||
|
||||
function handleUseShortUrlChange (value: string) {
|
||||
saveConfig('settings.useShortUrl', value === $T('UPLOAD_SHORT_URL'))
|
||||
saveConfig(configPaths.settings.useShortUrl, value === $T('UPLOAD_SHORT_URL'))
|
||||
useShortUrl.value = value
|
||||
}
|
||||
|
||||
@@ -1046,8 +1048,8 @@ onBeforeUnmount(() => {
|
||||
})
|
||||
|
||||
onActivated(async () => {
|
||||
pasteStyle.value = (await getConfig('settings.pasteStyle')) || 'markdown'
|
||||
useShortUrl.value = (await getConfig('settings.useShortUrl') ? $T('UPLOAD_SHORT_URL') : $T('UPLOAD_NORMAL_URL'))
|
||||
pasteStyle.value = (await getConfig(configPaths.settings.pasteStyle)) || IPasteStyle.MARKDOWN
|
||||
useShortUrl.value = (await getConfig(configPaths.settings.useShortUrl) ? $T('UPLOAD_SHORT_URL') : $T('UPLOAD_NORMAL_URL'))
|
||||
initDeleteCloud()
|
||||
})
|
||||
|
||||
|
||||
@@ -1735,7 +1735,7 @@ import pkg from 'root/package.json'
|
||||
|
||||
// 事件常量
|
||||
import { PICGO_OPEN_FILE, PICGO_OPEN_DIRECTORY, OPEN_URL, GET_PICBEDS, HIDE_DOCK } from '#/events/constants'
|
||||
import { IRPCActionType } from '~/universal/types/enum'
|
||||
import { IRPCActionType, ISartMode } from '~/universal/types/enum'
|
||||
|
||||
// Electron 相关
|
||||
import {
|
||||
@@ -1770,6 +1770,7 @@ import { invokeToMain } from '@/manage/utils/dataSender'
|
||||
|
||||
// 内置重命名格式表
|
||||
import { buildInRenameFormatTable } from '../manage/utils/common'
|
||||
import { configPaths, ISartModeValues } from '~/universal/utils/configPaths'
|
||||
|
||||
const imageProcessDialogVisible = ref(false)
|
||||
const activeName = ref<'system' | 'syncAndConfigure' | 'upload' | 'advanced' | 'upadte'>('system')
|
||||
@@ -1863,14 +1864,14 @@ function handleSaveConfig () {
|
||||
const formatConvertObjFilter = Object.fromEntries(formatConvertObjEntriesFilter)
|
||||
formatConvertObj.value = JSON.stringify(formatConvertObjFilter)
|
||||
compressForm.formatConvertObj = formatConvertObjFilter
|
||||
saveConfig('buildIn.compress', toRaw(compressForm))
|
||||
saveConfig('buildIn.watermark', toRaw(waterMarkForm))
|
||||
saveConfig(configPaths.buildIn.compress, toRaw(compressForm))
|
||||
saveConfig(configPaths.buildIn.watermark, toRaw(waterMarkForm))
|
||||
closeDialog()
|
||||
}
|
||||
|
||||
async function initForm () {
|
||||
const compress = await getConfig<IBuildInCompressOptions>('buildIn.compress')
|
||||
const watermark = await getConfig<IBuildInWaterMarkOptions>('buildIn.watermark')
|
||||
const compress = await getConfig<IBuildInCompressOptions>(configPaths.buildIn.compress)
|
||||
const watermark = await getConfig<IBuildInWaterMarkOptions>(configPaths.buildIn.watermark)
|
||||
if (compress) {
|
||||
compressForm.quality = compress.quality ?? 100
|
||||
compressForm.isConvert = compress.isConvert ?? false
|
||||
@@ -1986,10 +1987,6 @@ const customLink = reactive({
|
||||
value: ''
|
||||
})
|
||||
|
||||
const shortKey = reactive<IShortKeyMap>({
|
||||
upload: ''
|
||||
})
|
||||
|
||||
const mainWindowWidth = ref(1200)
|
||||
const mainWindowHeight = ref(800)
|
||||
const rawPicGoSize = ref(false)
|
||||
@@ -2051,7 +2048,7 @@ const syncType = [
|
||||
|
||||
async function cancelSyncSetting () {
|
||||
syncVisible.value = false
|
||||
sync.value = await getConfig('settings.sync') || {
|
||||
sync.value = await getConfig(configPaths.settings.sync) || {
|
||||
type: 'github',
|
||||
username: '',
|
||||
repo: '',
|
||||
@@ -2065,7 +2062,7 @@ async function cancelSyncSetting () {
|
||||
|
||||
function confirmSyncSetting () {
|
||||
saveConfig({
|
||||
'settings.sync': sync.value
|
||||
[configPaths.settings.sync]: sync.value
|
||||
})
|
||||
syncVisible.value = false
|
||||
}
|
||||
@@ -2134,7 +2131,6 @@ async function initData () {
|
||||
currentLanguage.value = settings.language ?? 'zh-CN'
|
||||
currentStartMode.value = settings.startMode || 'quiet'
|
||||
customLink.value = settings.customLink || ''
|
||||
shortKey.upload = settings.shortKey.upload
|
||||
proxy.value = picBed.proxy || ''
|
||||
npmRegistry.value = settings.registry || ''
|
||||
npmProxy.value = settings.proxy || ''
|
||||
@@ -2152,7 +2148,7 @@ async function initData () {
|
||||
if (advancedRename.value.enable) {
|
||||
form.autoRename = false
|
||||
saveConfig({
|
||||
'settings.autoRename': false
|
||||
[configPaths.settings.autoRename]: false
|
||||
})
|
||||
}
|
||||
sync.value = settings.sync || {
|
||||
@@ -2204,13 +2200,13 @@ function openLogSetting () {
|
||||
|
||||
async function cancelCustomLink () {
|
||||
customLinkVisible.value = false
|
||||
customLink.value = await getConfig<string>('settings.customLink') || ''
|
||||
customLink.value = await getConfig<string>(configPaths.settings.customLink) || ''
|
||||
}
|
||||
|
||||
function confirmCustomLink () {
|
||||
$customLink.value?.validate((valid: boolean) => {
|
||||
if (valid) {
|
||||
saveConfig('settings.customLink', customLink.value)
|
||||
saveConfig(configPaths.settings.customLink, customLink.value)
|
||||
customLinkVisible.value = false
|
||||
sendToMain('updateCustomLink')
|
||||
} else {
|
||||
@@ -2220,7 +2216,7 @@ function confirmCustomLink () {
|
||||
}
|
||||
|
||||
function handleEncodeOutputURL (val: ICheckBoxValueType) {
|
||||
saveConfig('settings.encodeOutputURL', val)
|
||||
saveConfig(configPaths.settings.encodeOutputURL, val)
|
||||
const successNotification = new Notification($T('SETTINGS_ENCODE_OUTPUT_URL'), {
|
||||
body: $T('TIPS_SET_SUCCEED')
|
||||
})
|
||||
@@ -2231,17 +2227,17 @@ function handleEncodeOutputURL (val: ICheckBoxValueType) {
|
||||
|
||||
async function handleCancelAdvancedRename () {
|
||||
advancedRenameVisible.value = false
|
||||
advancedRename.value = toRaw((await getConfig<any>('buildIn.rename')) || {
|
||||
advancedRename.value = toRaw((await getConfig<any>(configPaths.buildIn.rename)) || {
|
||||
enable: false,
|
||||
format: '{filename}'
|
||||
})
|
||||
}
|
||||
|
||||
function handleSaveAdvancedRename () {
|
||||
saveConfig('buildIn.rename', toRaw(advancedRename.value))
|
||||
saveConfig(configPaths.buildIn.rename, toRaw(advancedRename.value))
|
||||
if (advancedRename.value.enable) {
|
||||
form.autoRename = false
|
||||
saveConfig('settings.autoRename', false)
|
||||
saveConfig(configPaths.settings.autoRename, false)
|
||||
}
|
||||
advancedRenameVisible.value = false
|
||||
const successNotification = new Notification($T('SETTINGS_ADVANCED_RENAME'), {
|
||||
@@ -2254,15 +2250,15 @@ function handleSaveAdvancedRename () {
|
||||
|
||||
async function cancelProxy () {
|
||||
proxyVisible.value = false
|
||||
proxy.value = await getConfig<string>('picBed.proxy') || ''
|
||||
proxy.value = await getConfig<string>(configPaths.picBed.proxy) || ''
|
||||
}
|
||||
|
||||
function confirmProxy () {
|
||||
proxyVisible.value = false
|
||||
saveConfig({
|
||||
'picBed.proxy': proxy.value,
|
||||
'settings.proxy': npmProxy.value,
|
||||
'settings.registry': npmRegistry.value
|
||||
[configPaths.picBed.proxy]: proxy.value,
|
||||
[configPaths.settings.proxy]: npmProxy.value,
|
||||
[configPaths.settings.registry]: npmRegistry.value
|
||||
})
|
||||
const successNotification = new Notification($T('SETTINGS_SET_PROXY_AND_MIRROR'), {
|
||||
body: $T('TIPS_SET_SUCCEED')
|
||||
@@ -2290,15 +2286,15 @@ function handleMigrateFromPicGo () {
|
||||
}
|
||||
|
||||
function updateHelperChange (val: ICheckBoxValueType) {
|
||||
saveConfig('settings.showUpdateTip', val)
|
||||
saveConfig(configPaths.settings.showUpdateTip, val)
|
||||
}
|
||||
|
||||
function autoImportChange (val: ICheckBoxValueType) {
|
||||
saveConfig('settings.autoImport', val)
|
||||
saveConfig(configPaths.settings.autoImport, val)
|
||||
}
|
||||
|
||||
function handleAutoImportPicBedChange (val: string[]) {
|
||||
saveConfig('settings.autoImportPicBed', val)
|
||||
saveConfig(configPaths.settings.autoImportPicBed, val)
|
||||
}
|
||||
|
||||
function handleHideDockChange (val: ICheckBoxValueType) {
|
||||
@@ -2307,16 +2303,16 @@ function handleHideDockChange (val: ICheckBoxValueType) {
|
||||
form.isHideDock = false
|
||||
return
|
||||
}
|
||||
saveConfig('settings.isHideDock', val)
|
||||
saveConfig(configPaths.settings.isHideDock, val)
|
||||
sendToMain(HIDE_DOCK, val)
|
||||
}
|
||||
|
||||
function useBuiltinClipboardChange (val: ICheckBoxValueType) {
|
||||
saveConfig('settings.useBuiltinClipboard', val)
|
||||
saveConfig(configPaths.settings.useBuiltinClipboard, val)
|
||||
}
|
||||
|
||||
function handleIsAutoListenClipboard (val: ICheckBoxValueType) {
|
||||
saveConfig('settings.isAutoListenClipboard', val)
|
||||
saveConfig(configPaths.settings.isAutoListenClipboard, val)
|
||||
}
|
||||
|
||||
function handleShowPicBedListChange (val: ICheckBoxValueType[]) {
|
||||
@@ -2329,37 +2325,37 @@ function handleShowPicBedListChange (val: ICheckBoxValueType[]) {
|
||||
return item
|
||||
})
|
||||
saveConfig({
|
||||
'picBed.list': list
|
||||
[configPaths.picBed.list]: list
|
||||
})
|
||||
sendToMain(GET_PICBEDS)
|
||||
}
|
||||
|
||||
function handleAutoStartChange (val: ICheckBoxValueType) {
|
||||
saveConfig('settings.autoStart', val)
|
||||
saveConfig(configPaths.settings.autoStart, val)
|
||||
sendToMain('autoStart', val)
|
||||
}
|
||||
|
||||
function handleDeleteCloudFile (val: ICheckBoxValueType) {
|
||||
saveConfig({
|
||||
'settings.deleteCloudFile': val
|
||||
[configPaths.settings.deleteCloudFile]: val
|
||||
})
|
||||
}
|
||||
|
||||
function handleDeleteLocalFile (val: ICheckBoxValueType) {
|
||||
saveConfig({
|
||||
'settings.deleteLocalFile': val
|
||||
[configPaths.settings.deleteLocalFile]: val
|
||||
})
|
||||
}
|
||||
|
||||
function handleRename (val: ICheckBoxValueType) {
|
||||
saveConfig({
|
||||
'settings.rename': val
|
||||
[configPaths.settings.rename]: val
|
||||
})
|
||||
}
|
||||
|
||||
function handleAutoRename (val: ICheckBoxValueType) {
|
||||
saveConfig({
|
||||
'settings.autoRename': val
|
||||
[configPaths.settings.autoRename]: val
|
||||
})
|
||||
}
|
||||
|
||||
@@ -2389,19 +2385,19 @@ function cancelCheckVersion () {
|
||||
}
|
||||
|
||||
function handleEnableWebServerChange (val: ICheckBoxValueType) {
|
||||
saveConfig('settings.enableWebServer', val)
|
||||
saveConfig(configPaths.settings.enableWebServer, val)
|
||||
}
|
||||
|
||||
function handleWebServerHostChange (val: string) {
|
||||
saveConfig('settings.webServerHost', val)
|
||||
saveConfig(configPaths.settings.webServerHost, val)
|
||||
}
|
||||
|
||||
function handleWebServerPortChange (val?: number, oldVal?: number) {
|
||||
saveConfig('settings.webServerPort', Number(val) || 37777)
|
||||
saveConfig(configPaths.settings.webServerPort, Number(val) || 37777)
|
||||
}
|
||||
|
||||
function handleWebServerPathChange (val: string) {
|
||||
saveConfig('settings.webServerPath', val)
|
||||
saveConfig(configPaths.settings.webServerPath, val)
|
||||
}
|
||||
|
||||
function confirmWebServerSetting () {
|
||||
@@ -2413,25 +2409,25 @@ function confirmWebServerSetting () {
|
||||
}
|
||||
|
||||
function handleServerKeyChange (val: string) {
|
||||
saveConfig('settings.serverKey', val)
|
||||
saveConfig(configPaths.settings.serverKey, val)
|
||||
}
|
||||
|
||||
function handleUploadNotification (val: ICheckBoxValueType) {
|
||||
saveConfig({
|
||||
'settings.uploadNotification': val
|
||||
[configPaths.settings.uploadNotification]: val
|
||||
})
|
||||
}
|
||||
|
||||
function handleUploadResultNotification (val: ICheckBoxValueType) {
|
||||
saveConfig({
|
||||
'settings.uploadResultNotification': val
|
||||
[configPaths.settings.uploadResultNotification]: val
|
||||
})
|
||||
}
|
||||
|
||||
async function cancelWindowSize () {
|
||||
mainWindowSizeVisible.value = false
|
||||
mainWindowWidth.value = await getConfig<number>('settings.mainWindowWidth') || 1200
|
||||
mainWindowHeight.value = await getConfig<number>('settings.mainWindowHeight') || 800
|
||||
mainWindowWidth.value = await getConfig<number>(configPaths.settings.mainWindowWidth) || 1200
|
||||
mainWindowHeight.value = await getConfig<number>(configPaths.settings.mainWindowHeight) || 800
|
||||
}
|
||||
|
||||
async function confirmWindowSize () {
|
||||
@@ -2439,8 +2435,8 @@ async function confirmWindowSize () {
|
||||
const width = enforceNumber(mainWindowWidth.value)
|
||||
const height = enforceNumber(mainWindowHeight.value)
|
||||
saveConfig({
|
||||
'settings.mainWindowWidth': rawPicGoSize.value ? 800 : width < 100 ? 100 : width,
|
||||
'settings.mainWindowHeight': rawPicGoSize.value ? 450 : height < 100 ? 100 : height
|
||||
[configPaths.settings.mainWindowWidth]: rawPicGoSize.value ? 800 : width < 100 ? 100 : width,
|
||||
[configPaths.settings.mainWindowHeight]: rawPicGoSize.value ? 450 : height < 100 ? 100 : height
|
||||
})
|
||||
|
||||
const successNotification = new Notification($T('SETTINGS_MAIN_WINDOW_SIZE'), {
|
||||
@@ -2452,15 +2448,15 @@ async function confirmWindowSize () {
|
||||
}
|
||||
|
||||
function handleAutoCloseMainWindowChange (val: ICheckBoxValueType) {
|
||||
saveConfig('settings.autoCloseMainWindow', val)
|
||||
saveConfig(configPaths.settings.autoCloseMainWindow, val)
|
||||
}
|
||||
|
||||
function handleAutoCloseMiniWindowChange (val: ICheckBoxValueType) {
|
||||
saveConfig('settings.autoCloseMiniWindow', val)
|
||||
saveConfig(configPaths.settings.autoCloseMiniWindow, val)
|
||||
}
|
||||
|
||||
function handleMiniWindowOntop (val: ICheckBoxValueType) {
|
||||
saveConfig('settings.miniWindowOntop', val)
|
||||
saveConfig(configPaths.settings.miniWindowOntop, val)
|
||||
$message.info($T('TIPS_NEED_RELOAD'))
|
||||
}
|
||||
|
||||
@@ -2468,18 +2464,18 @@ async function handleMiniIconPath (evt: Event) {
|
||||
const result = await invokeToMain('openFileSelectDialog')
|
||||
if (result && result[0]) {
|
||||
form.customMiniIcon = result[0]
|
||||
saveConfig('settings.customMiniIcon', form.customMiniIcon)
|
||||
saveConfig(configPaths.settings.customMiniIcon, form.customMiniIcon)
|
||||
$message.info($T('TIPS_NEED_RELOAD'))
|
||||
}
|
||||
}
|
||||
|
||||
function handleIsCustomMiniIcon (val: ICheckBoxValueType) {
|
||||
saveConfig('settings.isCustomMiniIcon', val)
|
||||
saveConfig(configPaths.settings.isCustomMiniIcon, val)
|
||||
$message.info($T('TIPS_NEED_RELOAD'))
|
||||
}
|
||||
|
||||
function handleAutoCopyUrl (val: ICheckBoxValueType) {
|
||||
saveConfig('settings.autoCopy', val)
|
||||
saveConfig(configPaths.settings.autoCopy, val)
|
||||
const successNotification = new Notification($T('SETTINGS_AUTO_COPY_URL_AFTER_UPLOAD'), {
|
||||
body: $T('TIPS_SET_SUCCEED')
|
||||
})
|
||||
@@ -2489,7 +2485,7 @@ function handleAutoCopyUrl (val: ICheckBoxValueType) {
|
||||
}
|
||||
|
||||
function handleUseShortUrl (val: ICheckBoxValueType) {
|
||||
saveConfig('settings.useShortUrl', val)
|
||||
saveConfig(configPaths.settings.useShortUrl, val)
|
||||
const successNotification = new Notification($T('SETTINGS_SHORT_URL'), {
|
||||
body: $T('TIPS_SET_SUCCEED')
|
||||
})
|
||||
@@ -2499,27 +2495,27 @@ function handleUseShortUrl (val: ICheckBoxValueType) {
|
||||
}
|
||||
|
||||
function handleShortUrlServerChange (val: string) {
|
||||
saveConfig('settings.shortUrlServer', val)
|
||||
saveConfig(configPaths.settings.shortUrlServer, val)
|
||||
}
|
||||
|
||||
function handleC1nTokenChange (val: string) {
|
||||
saveConfig('settings.c1nToken', val)
|
||||
saveConfig(configPaths.settings.c1nToken, val)
|
||||
}
|
||||
|
||||
function handleYourlsDomainChange (val: string) {
|
||||
saveConfig('settings.yourlsDomain', val)
|
||||
saveConfig(configPaths.settings.yourlsDomain, val)
|
||||
}
|
||||
|
||||
function handleYourlsSignatureChange (val: string) {
|
||||
saveConfig('settings.yourlsSignature', val)
|
||||
saveConfig(configPaths.settings.yourlsSignature, val)
|
||||
}
|
||||
|
||||
function handleCfWorkerHostChange (val: string) {
|
||||
saveConfig('settings.cfWorkerHost', val)
|
||||
saveConfig(configPaths.settings.cfWorkerHost, val)
|
||||
}
|
||||
|
||||
function handleAesPasswordChange (val: string) {
|
||||
saveConfig('settings.aesPassword', val || 'PicList-aesPassword')
|
||||
saveConfig(configPaths.settings.aesPassword, val || 'PicList-aesPassword')
|
||||
}
|
||||
|
||||
function confirmLogLevelSetting () {
|
||||
@@ -2527,8 +2523,8 @@ function confirmLogLevelSetting () {
|
||||
return $message.error($T('TIPS_PLEASE_CHOOSE_LOG_LEVEL'))
|
||||
}
|
||||
saveConfig({
|
||||
'settings.logLevel': form.logLevel,
|
||||
'settings.logFileSizeLimit': form.logFileSizeLimit
|
||||
[configPaths.settings.logLevel]: form.logLevel,
|
||||
[configPaths.settings.logFileSizeLimit]: form.logFileSizeLimit
|
||||
})
|
||||
const successNotification = new Notification($T('SETTINGS_SET_LOG_FILE'), {
|
||||
body: $T('TIPS_SET_SUCCEED')
|
||||
@@ -2541,8 +2537,8 @@ function confirmLogLevelSetting () {
|
||||
|
||||
async function cancelLogLevelSetting () {
|
||||
logFileVisible.value = false
|
||||
let logLevel = await getConfig<string | string[]>('settings.logLevel')
|
||||
const logFileSizeLimit = await getConfig<number>('settings.logFileSizeLimit') || 10
|
||||
let logLevel = await getConfig<string | string[]>(configPaths.settings.logLevel)
|
||||
const logFileSizeLimit = await getConfig<number>(configPaths.settings.logFileSizeLimit) || 10
|
||||
if (!Array.isArray(logLevel)) {
|
||||
if (logLevel && logLevel.length > 0) {
|
||||
logLevel = [logLevel]
|
||||
@@ -2617,7 +2613,7 @@ async function downloadAll () {
|
||||
function confirmServerSetting () {
|
||||
server.value.port = parseInt(server.value.port as unknown as string, 10)
|
||||
saveConfig({
|
||||
'settings.server': server.value
|
||||
[configPaths.settings.server]: server.value
|
||||
})
|
||||
const successNotification = new Notification($T('SETTINGS_SET_PICGO_SERVER'), {
|
||||
body: $T('TIPS_SET_SUCCEED')
|
||||
@@ -2631,7 +2627,7 @@ function confirmServerSetting () {
|
||||
|
||||
async function cancelServerSetting () {
|
||||
serverVisible.value = false
|
||||
server.value = await getConfig('settings.server') || {
|
||||
server.value = await getConfig(configPaths.settings.server) || {
|
||||
port: 36677,
|
||||
host: '0.0.0.0',
|
||||
enable: true
|
||||
@@ -2662,28 +2658,28 @@ function handleLevelDisabled (val: string) {
|
||||
function handleLanguageChange (val: string) {
|
||||
i18nManager.setCurrentLanguage(val)
|
||||
saveConfig({
|
||||
'settings.language': val
|
||||
[configPaths.settings.language]: val
|
||||
})
|
||||
sendToMain(GET_PICBEDS)
|
||||
}
|
||||
|
||||
function handleStartModeChange (val: 'quiet' | 'mini' | 'main' | 'no-tray') {
|
||||
if (val === 'no-tray') {
|
||||
function handleStartModeChange (val: ISartModeValues) {
|
||||
if (val === ISartMode.NO_TRAY) {
|
||||
if (form.isHideDock) {
|
||||
ElMessage.warning($T('SETTINGS_ISHIDEDOCK_TIPS'))
|
||||
currentStartMode.value = 'quiet'
|
||||
currentStartMode.value = ISartMode.QUIET
|
||||
return
|
||||
}
|
||||
$message.info($T('TIPS_NEED_RELOAD'))
|
||||
}
|
||||
saveConfig({
|
||||
'settings.startMode': val
|
||||
[configPaths.settings.startMode]: val
|
||||
})
|
||||
}
|
||||
|
||||
function handleManualPageOpenChange (val: string) {
|
||||
saveConfig({
|
||||
'settings.manualPageOpen': val
|
||||
[configPaths.settings.manualPageOpen]: val
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -274,6 +274,7 @@ import axios from 'axios'
|
||||
|
||||
// 枚举类型声明
|
||||
import { IRPCActionType } from '~/universal/types/enum'
|
||||
import { configPaths } from '~/universal/utils/configPaths'
|
||||
|
||||
const $confirm = ElMessageBox.confirm
|
||||
const searchText = ref('')
|
||||
@@ -416,7 +417,7 @@ onBeforeMount(async () => {
|
||||
})
|
||||
getPluginList()
|
||||
getSearchResult = debounce(_getSearchResult, 50)
|
||||
needReload.value = await getConfig<boolean>('needReload') || false
|
||||
needReload.value = await getConfig<boolean>(configPaths.needReload) || false
|
||||
})
|
||||
|
||||
async function buildContextMenu (plugin: IPicGoPlugin) {
|
||||
@@ -577,19 +578,19 @@ function handleSearchResult (item: INPMSearchResultObject) {
|
||||
// restore Uploader & Transformer
|
||||
async function handleRestoreState (item: string, name: string) {
|
||||
if (item === 'uploader') {
|
||||
const current = await getConfig('picBed.current')
|
||||
const current = await getConfig(configPaths.picBed.current)
|
||||
if (current === name) {
|
||||
saveConfig({
|
||||
'picBed.current': 'smms',
|
||||
'picBed.uploader': 'smms'
|
||||
[configPaths.picBed.current]: 'smms',
|
||||
[configPaths.picBed.uploader]: 'smms'
|
||||
})
|
||||
}
|
||||
}
|
||||
if (item === 'transformer') {
|
||||
const current = await getConfig('picBed.transformer')
|
||||
const current = await getConfig(configPaths.picBed.transformer)
|
||||
if (current === name) {
|
||||
saveConfig({
|
||||
'picBed.transformer': 'path'
|
||||
[configPaths.picBed.transformer]: 'path'
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,6 +132,7 @@ import { getConfig, sendToMain } from '@/utils/dataSender'
|
||||
|
||||
// 国际化函数
|
||||
import { T as $T } from '@/i18n'
|
||||
import { configPaths } from '~/universal/utils/configPaths'
|
||||
|
||||
const list = ref<IShortKeyConfig[]>([])
|
||||
const keyBindingVisible = ref(false)
|
||||
@@ -140,7 +141,7 @@ const shortKey = ref('')
|
||||
const currentIndex = ref(0)
|
||||
|
||||
onBeforeMount(async () => {
|
||||
const shortKeyConfig = (await getConfig<IShortKeyConfigs>('settings.shortKey'))!
|
||||
const shortKeyConfig = (await getConfig<IShortKeyConfigs>(configPaths.settings.shortKey._path))!
|
||||
list.value = Object.keys(shortKeyConfig).map(item => {
|
||||
return {
|
||||
...shortKeyConfig[item],
|
||||
|
||||
@@ -88,6 +88,7 @@ import { getConfig, sendToMain } from '@/utils/dataSender'
|
||||
|
||||
// 工具函数
|
||||
import { handleUrlEncode } from '#/utils/common'
|
||||
import { configPaths } from '~/universal/utils/configPaths'
|
||||
|
||||
const files = ref<IResult<ImgInfo>[]>([])
|
||||
const notification = reactive({
|
||||
@@ -128,8 +129,8 @@ const formatCustomLink = (customLink: string, item: ImgInfo) => {
|
||||
}
|
||||
|
||||
async function copyTheLink (item: ImgInfo) {
|
||||
const pasteStyle = await getConfig<IPasteStyle>('settings.pasteStyle') || IPasteStyle.MARKDOWN
|
||||
const customLink = await getConfig<string>('settings.customLink')
|
||||
const pasteStyle = await getConfig<IPasteStyle>(configPaths.settings.pasteStyle) || IPasteStyle.MARKDOWN
|
||||
const customLink = await getConfig<string>(configPaths.settings.customLink)
|
||||
const txt = await pasteTemplate(pasteStyle, item, customLink)
|
||||
clipboard.writeText(txt)
|
||||
const myNotification = new Notification(notification.title, notification)
|
||||
@@ -143,10 +144,10 @@ async function pasteTemplate (style: IPasteStyle, item: ImgInfo, customLink: str
|
||||
if (item.type === 'aws-s3' || item.type === 'aws-s3-plist') {
|
||||
url = item.imgUrl || item.url || ''
|
||||
}
|
||||
if ((await getConfig('settings.encodeOutputURL')) === true) {
|
||||
if ((await getConfig(configPaths.settings.encodeOutputURL)) === true) {
|
||||
url = handleUrlEncode(url)
|
||||
}
|
||||
const useShortUrl = await getConfig('settings.useShortUrl') || false
|
||||
const useShortUrl = await getConfig(configPaths.settings.useShortUrl) || false
|
||||
if (useShortUrl) {
|
||||
url = await ipcRenderer.invoke('getShortUrl', url)
|
||||
}
|
||||
|
||||
@@ -466,7 +466,8 @@ import { useRouter } from 'vue-router'
|
||||
|
||||
// 路由配置常量
|
||||
import { PICBEDS_PAGE } from '@/router/config'
|
||||
import { IRPCActionType } from '~/universal/types/enum'
|
||||
import { IPasteStyle, IRPCActionType } from '~/universal/types/enum'
|
||||
import { configPaths } from '~/universal/utils/configPaths'
|
||||
|
||||
const $router = useRouter()
|
||||
|
||||
@@ -538,14 +539,14 @@ function handleSaveConfig () {
|
||||
const formatConvertObjFilter = Object.fromEntries(formatConvertObjEntriesFilter)
|
||||
formatConvertObj.value = JSON.stringify(formatConvertObjFilter)
|
||||
compressForm.formatConvertObj = formatConvertObjFilter
|
||||
saveConfig('buildIn.compress', toRaw(compressForm))
|
||||
saveConfig('buildIn.watermark', toRaw(waterMarkForm))
|
||||
saveConfig(configPaths.buildIn.compress, toRaw(compressForm))
|
||||
saveConfig(configPaths.buildIn.watermark, toRaw(waterMarkForm))
|
||||
closeDialog()
|
||||
}
|
||||
|
||||
async function initData () {
|
||||
const compress = await getConfig<IBuildInCompressOptions>('buildIn.compress')
|
||||
const watermark = await getConfig<IBuildInWaterMarkOptions>('buildIn.watermark')
|
||||
const compress = await getConfig<IBuildInCompressOptions>(configPaths.buildIn.compress)
|
||||
const watermark = await getConfig<IBuildInWaterMarkOptions>(configPaths.buildIn.watermark)
|
||||
if (compress) {
|
||||
compressForm.quality = compress.quality ?? 100
|
||||
compressForm.isConvert = compress.isConvert ?? false
|
||||
@@ -637,7 +638,7 @@ function onProgressChange (val: number) {
|
||||
|
||||
async function handlePicBedNameClick (_picBedName: string, picBedConfigName: string | undefined) {
|
||||
const formatedpicBedConfigName = picBedConfigName || 'Default'
|
||||
const currentPicBed = await getConfig<string>('picBed.current')
|
||||
const currentPicBed = await getConfig<string>(configPaths.picBed.current)
|
||||
const currentPicBedConfig = await getConfig<any[]>(`uploader.${currentPicBed}`) as any || {}
|
||||
const configList = await triggerRPC<IUploaderConfigItem>(IRPCActionType.GET_PICBED_CONFIG_LIST, currentPicBed)
|
||||
const currentConfigList = configList?.configList ?? []
|
||||
@@ -721,23 +722,23 @@ function ipcSendFiles (files: FileList) {
|
||||
}
|
||||
|
||||
async function getPasteStyle () {
|
||||
pasteStyle.value = await getConfig('settings.pasteStyle') || 'markdown'
|
||||
customLink.value = await getConfig('settings.customLink') || ''
|
||||
pasteStyle.value = await getConfig(configPaths.settings.pasteStyle) || IPasteStyle.MARKDOWN
|
||||
customLink.value = await getConfig(configPaths.settings.customLink) || ''
|
||||
}
|
||||
|
||||
async function getUseShortUrl () {
|
||||
useShortUrl.value = await getConfig('settings.useShortUrl') || false
|
||||
useShortUrl.value = await getConfig(configPaths.settings.useShortUrl) || false
|
||||
}
|
||||
|
||||
async function handleUseShortUrlChange () {
|
||||
saveConfig({
|
||||
'settings.useShortUrl': useShortUrl.value
|
||||
[configPaths.settings.useShortUrl]: useShortUrl.value
|
||||
})
|
||||
}
|
||||
|
||||
function handlePasteStyleChange (val: string | number | boolean) {
|
||||
saveConfig({
|
||||
'settings.pasteStyle': val
|
||||
[configPaths.settings.pasteStyle]: val
|
||||
})
|
||||
}
|
||||
|
||||
@@ -766,7 +767,7 @@ function handleInputBoxValue (val: string) {
|
||||
}
|
||||
|
||||
async function getDefaultPicBed () {
|
||||
const currentPicBed = await getConfig<string>('picBed.current')
|
||||
const currentPicBed = await getConfig<string>(configPaths.picBed.current)
|
||||
picBed.value.forEach(item => {
|
||||
if (item.type === currentPicBed) {
|
||||
picBedName.value = item.name
|
||||
|
||||
@@ -118,6 +118,7 @@ import { PICBEDS_PAGE, UPLOADER_CONFIG_PAGE } from '@/router/config'
|
||||
|
||||
// 状态管理
|
||||
import { useStore } from '@/hooks/useStore'
|
||||
import { configPaths } from '~/universal/utils/configPaths'
|
||||
|
||||
const $router = useRouter()
|
||||
const $route = useRoute()
|
||||
@@ -187,8 +188,8 @@ function addNewConfig () {
|
||||
|
||||
function setDefaultPicBed (type: string) {
|
||||
saveConfig({
|
||||
'picBed.current': type,
|
||||
'picBed.uploader': type
|
||||
[configPaths.picBed.current]: type,
|
||||
[configPaths.picBed.uploader]: type
|
||||
})
|
||||
|
||||
store?.setDefaultPicBed(type)
|
||||
|
||||
@@ -132,6 +132,7 @@ import dayjs from 'dayjs'
|
||||
|
||||
// Element Plus 下拉菜单组件
|
||||
import { ElDropdown, ElMessage } from 'element-plus'
|
||||
import { configPaths } from '~/universal/utils/configPaths'
|
||||
|
||||
const type = ref('')
|
||||
const config = ref<IPicGoPluginConfig[]>([])
|
||||
@@ -227,8 +228,8 @@ function handleNameClick () {
|
||||
|
||||
async function handleCopyApi () {
|
||||
try {
|
||||
const { port = 36677, host = '127.0.0.1' } = await getConfig<IStringKeyMap>('settings.server') || {}
|
||||
const serverKey = await getConfig('settings.serverKey') || ''
|
||||
const { port = 36677, host = '127.0.0.1' } = await getConfig<IStringKeyMap>(configPaths.settings.server) || {}
|
||||
const serverKey = await getConfig(configPaths.settings.serverKey) || ''
|
||||
const uploader = await getConfig('uploader') as IStringKeyMap || {}
|
||||
const picBedConfigList = uploader[$route.params.type as string].configList || []
|
||||
const picBedConfig = picBedConfigList.find((item: IUploaderConfigListItem) => item._id === $route.params.configId)
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
import { reactive, InjectionKey, readonly, App, UnwrapRef, ref } from 'vue'
|
||||
import { saveConfig } from '@/utils/dataSender'
|
||||
import { configPaths } from '~/universal/utils/configPaths'
|
||||
|
||||
export interface IState {
|
||||
defaultPicBed: string;
|
||||
defaultPicBed: string
|
||||
}
|
||||
|
||||
export interface IStore {
|
||||
state: UnwrapRef<IState>
|
||||
setDefaultPicBed: (type: string) => void;
|
||||
updateForceUpdateTime: () => void;
|
||||
setDefaultPicBed: (type: string) => void
|
||||
updateForceUpdateTime: () => void
|
||||
}
|
||||
|
||||
export const storeKey: InjectionKey<IStore> = Symbol('store')
|
||||
@@ -23,8 +24,8 @@ const forceUpdateTime = ref<number>(Date.now())
|
||||
// methods
|
||||
const setDefaultPicBed = (type: string) => {
|
||||
saveConfig({
|
||||
'picBed.current': type,
|
||||
'picBed.uploader': type
|
||||
[configPaths.picBed.current]: type,
|
||||
[configPaths.picBed.uploader]: type
|
||||
})
|
||||
state.defaultPicBed = type
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user