mirror of
https://github.com/Kuingsmile/PicList.git
synced 2025-01-22 22:28:14 -05:00
🔨 Refactor(custom): add config file type
This commit is contained in:
parent
ae40a1615e
commit
c35776201a
@ -18,6 +18,7 @@ import shortKeyService from './shortKeyService'
|
||||
|
||||
// External utility functions
|
||||
import { TOGGLE_SHORTKEY_MODIFIED_MODE } from '#/events/constants'
|
||||
import { configPaths } from '~/universal/utils/configPaths'
|
||||
|
||||
class ShortKeyHandler {
|
||||
private isInModifiedMode: boolean = false
|
||||
@ -33,7 +34,7 @@ class ShortKeyHandler {
|
||||
}
|
||||
|
||||
private initBuiltInShortKey () {
|
||||
const commands = db.get('settings.shortKey') as IShortKeyConfigs
|
||||
const commands = db.get(configPaths.settings.shortKey._path) as IShortKeyConfigs
|
||||
Object.keys(commands)
|
||||
.filter(item => item.includes('picgo:'))
|
||||
.forEach(command => {
|
||||
@ -175,7 +176,7 @@ class ShortKeyHandler {
|
||||
}
|
||||
|
||||
unregisterPluginShortKey (pluginName: string) {
|
||||
const commands = db.get('settings.shortKey') as IShortKeyConfigs
|
||||
const commands = db.get(configPaths.settings.shortKey._path) as IShortKeyConfigs
|
||||
const keyList = Object.keys(commands)
|
||||
.filter(command => command.includes(pluginName))
|
||||
.map(command => {
|
||||
@ -187,7 +188,7 @@ class ShortKeyHandler {
|
||||
keyList.forEach(item => {
|
||||
globalShortcut.unregister(item.key)
|
||||
shortKeyService.unregisterCommand(item.command)
|
||||
db.unset('settings.shortKey', item.command)
|
||||
db.unset(configPaths.settings.shortKey._path, item.command)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ import {
|
||||
import uploader from 'apis/app/uploader'
|
||||
import db, { GalleryDB } from '~/main/apis/core/datastore'
|
||||
import windowManager from 'apis/app/window/windowManager'
|
||||
import { IWindowList } from '#/types/enum'
|
||||
import { IPasteStyle, IWindowList } from '#/types/enum'
|
||||
import pasteTemplate from '~/main/utils/pasteTemplate'
|
||||
import pkg from 'root/package.json'
|
||||
import { ensureFilePath, handleCopyUrl } from '~/main/utils/common'
|
||||
@ -28,13 +28,14 @@ import { buildPicBedListMenu } from '~/main/events/remotes/menu'
|
||||
import clipboardPoll from '~/main/utils/clipboardPoll'
|
||||
import picgo from '../../core/picgo'
|
||||
import { uploadClipboardFiles } from '../uploader/apis'
|
||||
import { configPaths } from '~/universal/utils/configPaths'
|
||||
|
||||
let contextMenu: Menu | null
|
||||
let tray: Tray | null
|
||||
|
||||
export function setDockMenu () {
|
||||
const isListeningClipboard = db.get('settings.isListeningClipboard') || false
|
||||
const autoCloseMiniWindow = db.get('settings.autoCloseMiniWindow') || false
|
||||
const isListeningClipboard = db.get(configPaths.settings.isListeningClipboard) || false
|
||||
const autoCloseMiniWindow = db.get(configPaths.settings.autoCloseMiniWindow) || false
|
||||
const dockMenu = Menu.buildFromTemplate([
|
||||
{
|
||||
label: T('OPEN_MAIN_WINDOW'),
|
||||
@ -50,7 +51,7 @@ export function setDockMenu () {
|
||||
{
|
||||
label: T('START_WATCH_CLIPBOARD'),
|
||||
click () {
|
||||
db.set('settings.isListeningClipboard', true)
|
||||
db.set(configPaths.settings.isListeningClipboard, true)
|
||||
clipboardPoll.startListening()
|
||||
clipboardPoll.on('change', () => {
|
||||
picgo.log.info('clipboard changed')
|
||||
@ -63,7 +64,7 @@ export function setDockMenu () {
|
||||
{
|
||||
label: T('STOP_WATCH_CLIPBOARD'),
|
||||
click () {
|
||||
db.set('settings.isListeningClipboard', false)
|
||||
db.set(configPaths.settings.isListeningClipboard, false)
|
||||
clipboardPoll.stopListening()
|
||||
clipboardPoll.removeAllListeners()
|
||||
setDockMenu()
|
||||
@ -84,7 +85,7 @@ export function createMenu () {
|
||||
label: T('OPEN_MAIN_WINDOW'),
|
||||
click () {
|
||||
const settingWindow = windowManager.get(IWindowList.SETTING_WINDOW)
|
||||
const autoCloseMiniWindow = db.get('settings.autoCloseMiniWindow') || false
|
||||
const autoCloseMiniWindow = db.get(configPaths.settings.autoCloseMiniWindow) || false
|
||||
settingWindow!.show()
|
||||
settingWindow!.focus()
|
||||
if (windowManager.has(IWindowList.MINI_WINDOW) && autoCloseMiniWindow) {
|
||||
@ -141,7 +142,7 @@ export function createMenu () {
|
||||
|
||||
export function createContextMenu () {
|
||||
const ClipboardWatcher = clipboardPoll
|
||||
const isListeningClipboard = db.get('settings.isListeningClipboard') || false
|
||||
const isListeningClipboard = db.get(configPaths.settings.isListeningClipboard) || false
|
||||
if (process.platform === 'darwin' || process.platform === 'win32') {
|
||||
const submenu = buildPicBedListMenu()
|
||||
const template = [
|
||||
@ -149,7 +150,7 @@ export function createContextMenu () {
|
||||
label: T('OPEN_MAIN_WINDOW'),
|
||||
click () {
|
||||
const settingWindow = windowManager.get(IWindowList.SETTING_WINDOW)
|
||||
const autoCloseMiniWindow = db.get('settings.autoCloseMiniWindow') || false
|
||||
const autoCloseMiniWindow = db.get(configPaths.settings.autoCloseMiniWindow) || false
|
||||
settingWindow!.show()
|
||||
settingWindow!.focus()
|
||||
if (windowManager.has(IWindowList.MINI_WINDOW) && autoCloseMiniWindow) {
|
||||
@ -166,7 +167,7 @@ export function createContextMenu () {
|
||||
{
|
||||
label: T('START_WATCH_CLIPBOARD'),
|
||||
click () {
|
||||
db.set('settings.isListeningClipboard', true)
|
||||
db.set(configPaths.settings.isListeningClipboard, true)
|
||||
ClipboardWatcher.startListening()
|
||||
ClipboardWatcher.on('change', () => {
|
||||
picgo.log.info('clipboard changed')
|
||||
@ -179,7 +180,7 @@ export function createContextMenu () {
|
||||
{
|
||||
label: T('STOP_WATCH_CLIPBOARD'),
|
||||
click () {
|
||||
db.set('settings.isListeningClipboard', false)
|
||||
db.set(configPaths.settings.isListeningClipboard, false)
|
||||
ClipboardWatcher.stopListening()
|
||||
ClipboardWatcher.removeAllListeners()
|
||||
createContextMenu()
|
||||
@ -206,11 +207,11 @@ export function createContextMenu () {
|
||||
click () {
|
||||
const miniWindow = windowManager.get(IWindowList.MINI_WINDOW)!
|
||||
miniWindow.removeAllListeners()
|
||||
if (db.get('settings.miniWindowOntop')) {
|
||||
if (db.get(configPaths.settings.miniWindowOntop)) {
|
||||
miniWindow.setAlwaysOnTop(true)
|
||||
}
|
||||
const { width, height } = screen.getPrimaryDisplay().workAreaSize
|
||||
const lastPosition = db.get('settings.miniWindowPosition')
|
||||
const lastPosition = db.get(configPaths.settings.miniWindowPosition)
|
||||
if (lastPosition) {
|
||||
miniWindow.setPosition(lastPosition[0], lastPosition[1])
|
||||
} else {
|
||||
@ -218,13 +219,13 @@ export function createContextMenu () {
|
||||
}
|
||||
const setPositionFunc = () => {
|
||||
const position = miniWindow.getPosition()
|
||||
db.set('settings.miniWindowPosition', position)
|
||||
db.set(configPaths.settings.miniWindowPosition, position)
|
||||
}
|
||||
miniWindow.on('close', setPositionFunc)
|
||||
miniWindow.on('move', setPositionFunc)
|
||||
miniWindow.show()
|
||||
miniWindow.focus()
|
||||
const autoCloseMainWindow = db.get('settings.autoCloseMainWindow') || false
|
||||
const autoCloseMainWindow = db.get(configPaths.settings.autoCloseMainWindow) || false
|
||||
if (windowManager.has(IWindowList.SETTING_WINDOW) && autoCloseMainWindow) {
|
||||
windowManager.get(IWindowList.SETTING_WINDOW)!.hide()
|
||||
}
|
||||
@ -246,7 +247,7 @@ export function createContextMenu () {
|
||||
label: T('OPEN_MAIN_WINDOW'),
|
||||
click () {
|
||||
const settingWindow = windowManager.get(IWindowList.SETTING_WINDOW)
|
||||
const autoCloseMiniWindow = db.get('settings.autoCloseMiniWindow') || false
|
||||
const autoCloseMiniWindow = db.get(configPaths.settings.autoCloseMiniWindow) || false
|
||||
settingWindow!.show()
|
||||
settingWindow!.focus()
|
||||
if (windowManager.has(IWindowList.MINI_WINDOW) && autoCloseMiniWindow) {
|
||||
@ -259,11 +260,11 @@ export function createContextMenu () {
|
||||
click () {
|
||||
const miniWindow = windowManager.get(IWindowList.MINI_WINDOW)!
|
||||
miniWindow.removeAllListeners()
|
||||
if (db.get('settings.miniWindowOntop')) {
|
||||
if (db.get(configPaths.settings.miniWindowOntop)) {
|
||||
miniWindow.setAlwaysOnTop(true)
|
||||
}
|
||||
const { width, height } = screen.getPrimaryDisplay().workAreaSize
|
||||
const lastPosition = db.get('settings.miniWindowPosition')
|
||||
const lastPosition = db.get(configPaths.settings.miniWindowPosition)
|
||||
if (lastPosition) {
|
||||
miniWindow.setPosition(lastPosition[0], lastPosition[1])
|
||||
} else {
|
||||
@ -271,13 +272,13 @@ export function createContextMenu () {
|
||||
}
|
||||
const setPositionFunc = () => {
|
||||
const position = miniWindow.getPosition()
|
||||
db.set('settings.miniWindowPosition', position)
|
||||
db.set(configPaths.settings.miniWindowPosition, position)
|
||||
}
|
||||
miniWindow.on('close', setPositionFunc)
|
||||
miniWindow.on('move', setPositionFunc)
|
||||
miniWindow.show()
|
||||
miniWindow.focus()
|
||||
const autoCloseMainWindow = db.get('settings.autoCloseMainWindow') || false
|
||||
const autoCloseMainWindow = db.get(configPaths.settings.autoCloseMainWindow) || false
|
||||
if (windowManager.has(IWindowList.SETTING_WINDOW) && autoCloseMainWindow) {
|
||||
windowManager.get(IWindowList.SETTING_WINDOW)!.hide()
|
||||
}
|
||||
@ -286,7 +287,7 @@ export function createContextMenu () {
|
||||
{
|
||||
label: T('START_WATCH_CLIPBOARD'),
|
||||
click () {
|
||||
db.set('settings.isListeningClipboard', true)
|
||||
db.set(configPaths.settings.isListeningClipboard, true)
|
||||
ClipboardWatcher.startListening()
|
||||
ClipboardWatcher.on('change', () => {
|
||||
picgo.log.info('clipboard changed')
|
||||
@ -299,7 +300,7 @@ export function createContextMenu () {
|
||||
{
|
||||
label: T('STOP_WATCH_CLIPBOARD'),
|
||||
click () {
|
||||
db.set('settings.isListeningClipboard', false)
|
||||
db.set(configPaths.settings.isListeningClipboard, false)
|
||||
ClipboardWatcher.stopListening()
|
||||
ClipboardWatcher.removeAllListeners()
|
||||
createContextMenu()
|
||||
@ -388,7 +389,7 @@ export function createTray () {
|
||||
windowManager.get(IWindowList.TRAY_WINDOW)!.hide()
|
||||
}
|
||||
const settingWindow = windowManager.get(IWindowList.SETTING_WINDOW)
|
||||
const autoCloseMiniWindow = db.get('settings.autoCloseMiniWindow') || false
|
||||
const autoCloseMiniWindow = db.get(configPaths.settings.autoCloseMiniWindow) || false
|
||||
settingWindow!.show()
|
||||
settingWindow!.focus()
|
||||
if (windowManager.has(IWindowList.MINI_WINDOW) && autoCloseMiniWindow) {
|
||||
@ -412,21 +413,21 @@ export function createTray () {
|
||||
// drop-files only be supported in macOS
|
||||
// so the tray window must be available
|
||||
tray.on('drop-files', async (event: Event, files: string[]) => {
|
||||
const pasteStyle = db.get('settings.pasteStyle') || 'markdown'
|
||||
const pasteStyle = db.get(configPaths.settings.pasteStyle) || IPasteStyle.MARKDOWN
|
||||
const rawInput = cloneDeep(files)
|
||||
const trayWindow = windowManager.get(IWindowList.TRAY_WINDOW)!
|
||||
const imgs = await uploader
|
||||
.setWebContents(trayWindow.webContents)
|
||||
.upload(files)
|
||||
const deleteLocalFile = db.get('settings.deleteLocalFile') || false
|
||||
const deleteLocalFile = db.get(configPaths.settings.deleteLocalFile) || false
|
||||
if (imgs !== false) {
|
||||
const pasteText: string[] = []
|
||||
for (let i = 0; i < imgs.length; i++) {
|
||||
if (deleteLocalFile) {
|
||||
await fs.remove(rawInput[i])
|
||||
}
|
||||
pasteText.push(await (pasteTemplate(pasteStyle, imgs[i], db.get('settings.customLink'))))
|
||||
const isShowResultNotification = db.get('settings.uploadResultNotification') === undefined ? true : !!db.get('settings.uploadResultNotification')
|
||||
pasteText.push(await (pasteTemplate(pasteStyle, imgs[i], db.get(configPaths.settings.customLink))))
|
||||
const isShowResultNotification = db.get(configPaths.settings.uploadResultNotification) === undefined ? true : !!db.get(configPaths.settings.uploadResultNotification)
|
||||
if (isShowResultNotification) {
|
||||
const notification = new Notification({
|
||||
title: T('UPLOAD_SUCCEED'),
|
||||
|
@ -18,15 +18,16 @@ import ALLApi from '@/apis/allApi'
|
||||
import picgo from '@core/picgo'
|
||||
import GuiApi from '../../gui'
|
||||
import uploader from '.'
|
||||
import { IWindowList } from '#/types/enum'
|
||||
import { IPasteStyle, IWindowList } from '#/types/enum'
|
||||
import { picBedsCanbeDeleted } from '#/utils/static'
|
||||
import path from 'path'
|
||||
import SSHClient from '~/main/utils/sshClient'
|
||||
import { ISftpPlistConfig } from 'piclist'
|
||||
import { getRawData } from '~/renderer/utils/common'
|
||||
import { configPaths } from '~/universal/utils/configPaths'
|
||||
|
||||
const handleClipboardUploading = async (): Promise<false | ImgInfo[]> => {
|
||||
const useBuiltinClipboard = db.get('settings.useBuiltinClipboard') === undefined ? true : !!db.get('settings.useBuiltinClipboard')
|
||||
const useBuiltinClipboard = db.get(configPaths.settings.useBuiltinClipboard) === undefined ? true : !!db.get(configPaths.settings.useBuiltinClipboard)
|
||||
const win = windowManager.getAvailableWindow()
|
||||
if (useBuiltinClipboard) {
|
||||
return await uploader.setWebContents(win!.webContents).uploadWithBuildInClipboard()
|
||||
@ -39,9 +40,9 @@ export const uploadClipboardFiles = async (): Promise<IStringKeyMap> => {
|
||||
if (img !== false) {
|
||||
if (img.length > 0) {
|
||||
const trayWindow = windowManager.get(IWindowList.TRAY_WINDOW)
|
||||
const pasteStyle = db.get('settings.pasteStyle') || 'markdown'
|
||||
handleCopyUrl(await (pasteTemplate(pasteStyle, img[0], db.get('settings.customLink'))))
|
||||
const isShowResultNotification = db.get('settings.uploadResultNotification') === undefined ? true : !!db.get('settings.uploadResultNotification')
|
||||
const pasteStyle = db.get(configPaths.settings.pasteStyle) || IPasteStyle.MARKDOWN
|
||||
handleCopyUrl(await (pasteTemplate(pasteStyle, img[0], db.get(configPaths.settings.customLink))))
|
||||
const isShowResultNotification = db.get(configPaths.settings.uploadResultNotification) === undefined ? true : !!db.get(configPaths.settings.uploadResultNotification)
|
||||
if (isShowResultNotification) {
|
||||
const notification = new Notification({
|
||||
title: T('UPLOAD_SUCCEED'),
|
||||
@ -88,8 +89,8 @@ export const uploadChoosedFiles = async (webContents: WebContents, files: IFileW
|
||||
const imgs = await uploader.setWebContents(webContents).upload(input)
|
||||
const result = []
|
||||
if (imgs !== false) {
|
||||
const pasteStyle = db.get('settings.pasteStyle') || 'markdown'
|
||||
const deleteLocalFile = db.get('settings.deleteLocalFile') || false
|
||||
const pasteStyle = db.get(configPaths.settings.pasteStyle) || IPasteStyle.MARKDOWN
|
||||
const deleteLocalFile = db.get(configPaths.settings.deleteLocalFile) || false
|
||||
const pasteText: string[] = []
|
||||
for (let i = 0; i < imgs.length; i++) {
|
||||
if (deleteLocalFile) {
|
||||
@ -99,8 +100,8 @@ export const uploadChoosedFiles = async (webContents: WebContents, files: IFileW
|
||||
picgo.log.error(err)
|
||||
})
|
||||
}
|
||||
pasteText.push(await (pasteTemplate(pasteStyle, imgs[i], db.get('settings.customLink'))))
|
||||
const isShowResultNotification = db.get('settings.uploadResultNotification') === undefined ? true : !!db.get('settings.uploadResultNotification')
|
||||
pasteText.push(await (pasteTemplate(pasteStyle, imgs[i], db.get(configPaths.settings.customLink))))
|
||||
const isShowResultNotification = db.get(configPaths.settings.uploadResultNotification) === undefined ? true : !!db.get(configPaths.settings.uploadResultNotification)
|
||||
if (isShowResultNotification) {
|
||||
const notification = new Notification({
|
||||
title: T('UPLOAD_SUCCEED'),
|
||||
@ -152,7 +153,7 @@ export const deleteChoosedFiles = async (list: ImgInfo[]): Promise<boolean[]> =>
|
||||
const dbStore = GalleryDB.getInstance()
|
||||
const file = await dbStore.getById(item.id)
|
||||
await dbStore.removeById(item.id)
|
||||
if (await picgo.getConfig('settings.deleteCloudFile')) {
|
||||
if (await picgo.getConfig(configPaths.settings.deleteCloudFile)) {
|
||||
if (item.type !== undefined && picBedsCanbeDeleted.includes(item.type)) {
|
||||
const noteFunc = (value: boolean) => {
|
||||
const notification = new Notification({
|
||||
|
@ -33,6 +33,7 @@ import {
|
||||
RENAME_FILE_NAME,
|
||||
TALKING_DATA_EVENT
|
||||
} from '~/universal/events/constants'
|
||||
import { configPaths } from '~/universal/utils/configPaths'
|
||||
|
||||
const waitForRename = (window: BrowserWindow, id: number): Promise<string|null> => {
|
||||
return new Promise((resolve) => {
|
||||
@ -80,7 +81,7 @@ class Uploader {
|
||||
this.webContents?.send('uploadProgress', progress)
|
||||
})
|
||||
picgo.on('beforeTransform', () => {
|
||||
if (db.get('settings.uploadNotification')) {
|
||||
if (db.get(configPaths.settings.uploadNotification)) {
|
||||
const notification = new Notification({
|
||||
title: T('UPLOAD_PROGRESS'),
|
||||
body: T('UPLOADING')
|
||||
@ -90,8 +91,8 @@ class Uploader {
|
||||
})
|
||||
picgo.helper.beforeUploadPlugins.register('renameFn', {
|
||||
handle: async (ctx: IPicGo) => {
|
||||
const rename = db.get('settings.rename')
|
||||
const autoRename = db.get('settings.autoRename')
|
||||
const rename = db.get(configPaths.settings.rename)
|
||||
const autoRename = db.get(configPaths.settings.autoRename)
|
||||
if (autoRename || rename) {
|
||||
await Promise.all(ctx.output.map(async (item, index) => {
|
||||
let name: undefined | string | null
|
||||
@ -163,7 +164,7 @@ class Uploader {
|
||||
if (this.webContents) {
|
||||
handleTalkingData(this.webContents, {
|
||||
fromClipboard: !img,
|
||||
type: db.get('picBed.uploader') || db.get('picBed.current') || 'smms',
|
||||
type: db.get(configPaths.picBed.uploader) || db.get(configPaths.picBed.current) || 'smms',
|
||||
count: img ? img.length : 1,
|
||||
duration: Date.now() - startTime
|
||||
} as IAnalyticsData)
|
||||
|
@ -23,14 +23,15 @@ import { IWindowList } from '#/types/enum'
|
||||
// External utility functions
|
||||
import { CREATE_APP_MENU } from '@core/bus/constants'
|
||||
import { TOGGLE_SHORTKEY_MODIFIED_MODE } from '#/events/constants'
|
||||
import { configPaths } from '~/universal/utils/configPaths'
|
||||
|
||||
const windowList = new Map<IWindowList, IWindowListItem>()
|
||||
|
||||
const handleWindowParams = (windowURL: string) => windowURL
|
||||
|
||||
const getDefaultWindowSizes = (): { width: number, height: number } => {
|
||||
const mainWindowWidth = picgo.getConfig<any>('settings.mainWindowWidth')
|
||||
const mainWindowHeight = picgo.getConfig<any>('settings.mainWindowHeight')
|
||||
const mainWindowWidth = picgo.getConfig<any>(configPaths.settings.mainWindowWidth)
|
||||
const mainWindowHeight = picgo.getConfig<any>(configPaths.settings.mainWindowHeight)
|
||||
return {
|
||||
width: mainWindowWidth || 1200,
|
||||
height: mainWindowHeight || 800
|
||||
@ -127,7 +128,7 @@ const miniWindowOptions = {
|
||||
}
|
||||
} as IBrowserWindowOptions
|
||||
|
||||
if (db.get('settings.miniWindowOntop')) {
|
||||
if (db.get(configPaths.settings.miniWindowOntop)) {
|
||||
miniWindowOptions.alwaysOnTop = true
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,7 @@ import { DBStore, JSONStore } from '@picgo/store'
|
||||
|
||||
// External utility functions
|
||||
import { T } from '~/main/i18n'
|
||||
import { configPaths } from '~/universal/utils/configPaths'
|
||||
|
||||
const STORE_PATH = dbPathDir()
|
||||
|
||||
@ -37,8 +38,8 @@ class ConfigStore {
|
||||
})
|
||||
}
|
||||
|
||||
if (!this.db.has('settings.shortKey')) {
|
||||
this.db.set('settings.shortKey[picgo:upload]', {
|
||||
if (!this.db.has(configPaths.settings.shortKey._path)) {
|
||||
this.db.set(configPaths.settings.shortKey['picgo:upload'], {
|
||||
enable: true,
|
||||
key: 'CommandOrControl+Shift+P',
|
||||
name: 'upload',
|
||||
|
@ -24,6 +24,8 @@ import { SHOW_INPUT_BOX } from '~/universal/events/constants'
|
||||
// External utility functions
|
||||
import { DBStore } from '@picgo/store'
|
||||
import { T } from '~/main/i18n'
|
||||
import { configPaths } from '~/universal/utils/configPaths'
|
||||
import { IPasteStyle } from '~/universal/types/enum'
|
||||
|
||||
// Cross-process support may be required in the future
|
||||
class GuiApi implements IGuiApi {
|
||||
@ -85,15 +87,15 @@ class GuiApi implements IGuiApi {
|
||||
const rawInput = cloneDeep(input)
|
||||
const imgs = await uploader.setWebContents(webContents!).upload(input)
|
||||
if (imgs !== false) {
|
||||
const pasteStyle = db.get('settings.pasteStyle') || 'markdown'
|
||||
const deleteLocalFile = db.get('settings.deleteLocalFile') || false
|
||||
const pasteStyle = db.get(configPaths.settings.pasteStyle) || IPasteStyle.MARKDOWN
|
||||
const deleteLocalFile = db.get(configPaths.settings.deleteLocalFile) || false
|
||||
const pasteText: string[] = []
|
||||
for (let i = 0; i < imgs.length; i++) {
|
||||
if (deleteLocalFile) {
|
||||
await fs.remove(rawInput[i])
|
||||
}
|
||||
pasteText.push(await (pasteTemplate(pasteStyle, imgs[i], db.get('settings.customLink'))))
|
||||
const isShowResultNotification = db.get('settings.uploadResultNotification') === undefined ? true : !!db.get('settings.uploadResultNotification')
|
||||
pasteText.push(await (pasteTemplate(pasteStyle, imgs[i], db.get(configPaths.settings.customLink))))
|
||||
const isShowResultNotification = db.get(configPaths.settings.uploadResultNotification) === undefined ? true : !!db.get(configPaths.settings.uploadResultNotification)
|
||||
if (isShowResultNotification) {
|
||||
const notification = new Notification({
|
||||
title: T('UPLOAD_SUCCEED'),
|
||||
|
@ -14,7 +14,7 @@ import {
|
||||
import windowManager from 'apis/app/window/windowManager'
|
||||
|
||||
// 枚举类型声明
|
||||
import { IWindowList } from '#/types/enum'
|
||||
import { IPasteStyle, IWindowList } from '#/types/enum'
|
||||
|
||||
// 上传器
|
||||
import uploader from 'apis/app/uploader'
|
||||
@ -90,6 +90,7 @@ import { ISftpPlistConfig } from 'piclist'
|
||||
|
||||
import { removeFileFromS3InMain, removeFileFromDogeInMain, removeFileFromHuaweiInMain } from '~/main/utils/deleteFunc'
|
||||
import webServer from '../server/webServer'
|
||||
import { configPaths } from '~/universal/utils/configPaths'
|
||||
|
||||
const STORE_PATH = app.getPath('userData')
|
||||
|
||||
@ -103,9 +104,9 @@ export default {
|
||||
// macOS use builtin clipboard is OK
|
||||
const img = await uploader.setWebContents(trayWindow.webContents).uploadWithBuildInClipboard()
|
||||
if (img !== false) {
|
||||
const pasteStyle = db.get('settings.pasteStyle') || 'markdown'
|
||||
handleCopyUrl(await (pasteTemplate(pasteStyle, img[0], db.get('settings.customLink'))))
|
||||
const isShowResultNotification = db.get('settings.uploadResultNotification') === undefined ? true : !!db.get('settings.uploadResultNotification')
|
||||
const pasteStyle = db.get(configPaths.settings.pasteStyle) || IPasteStyle.MARKDOWN
|
||||
handleCopyUrl(await (pasteTemplate(pasteStyle, img[0], db.get(configPaths.settings.customLink))))
|
||||
const isShowResultNotification = db.get(configPaths.settings.uploadResultNotification) === undefined ? true : !!db.get(configPaths.settings.uploadResultNotification)
|
||||
if (isShowResultNotification) {
|
||||
const notification = new Notification({
|
||||
title: T('UPLOAD_SUCCEED'),
|
||||
@ -299,7 +300,7 @@ export default {
|
||||
|
||||
ipcMain.on('openSettingWindow', () => {
|
||||
windowManager.get(IWindowList.SETTING_WINDOW)!.show()
|
||||
const autoCloseMiniWindow = db.get('settings.autoCloseMiniWindow') || false
|
||||
const autoCloseMiniWindow = db.get(configPaths.settings.autoCloseMiniWindow) || false
|
||||
if (autoCloseMiniWindow) {
|
||||
if (windowManager.has(IWindowList.MINI_WINDOW)) {
|
||||
windowManager.get(IWindowList.MINI_WINDOW)!.hide()
|
||||
@ -315,11 +316,11 @@ export default {
|
||||
const miniWindow = windowManager.get(IWindowList.MINI_WINDOW)!
|
||||
const settingWindow = windowManager.get(IWindowList.SETTING_WINDOW)!
|
||||
miniWindow.removeAllListeners()
|
||||
if (db.get('settings.miniWindowOntop')) {
|
||||
if (db.get(configPaths.settings.miniWindowOntop)) {
|
||||
miniWindow.setAlwaysOnTop(true)
|
||||
}
|
||||
const { width, height } = screen.getPrimaryDisplay().workAreaSize
|
||||
const lastPosition = db.get('settings.miniWindowPosition')
|
||||
const lastPosition = db.get(configPaths.settings.miniWindowPosition)
|
||||
if (lastPosition) {
|
||||
miniWindow.setPosition(lastPosition[0], lastPosition[1])
|
||||
} else {
|
||||
@ -327,7 +328,7 @@ export default {
|
||||
}
|
||||
const setPositionFunc = () => {
|
||||
const position = miniWindow.getPosition()
|
||||
db.set('settings.miniWindowPosition', position)
|
||||
db.set(configPaths.settings.miniWindowPosition, position)
|
||||
}
|
||||
miniWindow.on('close', setPositionFunc)
|
||||
miniWindow.on('move', setPositionFunc)
|
||||
|
@ -47,6 +47,7 @@ import {
|
||||
SET_CURRENT_LANGUAGE,
|
||||
GET_CURRENT_LANGUAGE
|
||||
} from '#/events/constants'
|
||||
import { configPaths } from '~/universal/utils/configPaths'
|
||||
|
||||
// eslint-disable-next-line
|
||||
const requireFunc = typeof __webpack_require__ === 'function' ? __non_webpack_require__ : require
|
||||
@ -360,8 +361,8 @@ const handlePicGoGalleryDB = () => {
|
||||
})
|
||||
|
||||
ipcMain.handle(PASTE_TEXT, async (_, item: ImgInfo, copy = true) => {
|
||||
const pasteStyle = picgo.getConfig<IPasteStyle>('settings.pasteStyle') || IPasteStyle.MARKDOWN
|
||||
const customLink = picgo.getConfig<string>('settings.customLink')
|
||||
const pasteStyle = picgo.getConfig<IPasteStyle>(configPaths.settings.pasteStyle) || IPasteStyle.MARKDOWN
|
||||
const customLink = picgo.getConfig<string>(configPaths.settings.customLink)
|
||||
const txt = await pasteTemplate(pasteStyle, item, customLink)
|
||||
if (copy) {
|
||||
clipboard.writeText(txt)
|
||||
|
@ -30,6 +30,7 @@ import {
|
||||
} from '~/universal/events/constants'
|
||||
import { PicGo as PicGoCore } from 'piclist'
|
||||
import { T } from '~/main/i18n'
|
||||
import { configPaths } from '~/universal/utils/configPaths'
|
||||
|
||||
interface GuiMenuItem {
|
||||
label: string
|
||||
@ -37,7 +38,7 @@ interface GuiMenuItem {
|
||||
}
|
||||
|
||||
const buildMiniPageMenu = () => {
|
||||
const isListeningClipboard = db.get('settings.isListeningClipboard') || false
|
||||
const isListeningClipboard = db.get(configPaths.settings.isListeningClipboard) || false
|
||||
const ClipboardWatcher = clipboardPoll
|
||||
const submenu = buildPicBedListMenu()
|
||||
const template = [
|
||||
@ -45,7 +46,7 @@ const buildMiniPageMenu = () => {
|
||||
label: T('OPEN_MAIN_WINDOW'),
|
||||
click () {
|
||||
windowManager.get(IWindowList.SETTING_WINDOW)!.show()
|
||||
const autoCloseMiniWindow = db.get('settings.autoCloseMiniWindow') || false
|
||||
const autoCloseMiniWindow = db.get(configPaths.settings.autoCloseMiniWindow) || false
|
||||
if (autoCloseMiniWindow) {
|
||||
if (windowManager.has(IWindowList.MINI_WINDOW)) {
|
||||
windowManager.get(IWindowList.MINI_WINDOW)!.hide()
|
||||
@ -73,7 +74,7 @@ const buildMiniPageMenu = () => {
|
||||
{
|
||||
label: T('START_WATCH_CLIPBOARD'),
|
||||
click () {
|
||||
db.set('settings.isListeningClipboard', true)
|
||||
db.set(configPaths.settings.isListeningClipboard, true)
|
||||
ClipboardWatcher.startListening()
|
||||
ClipboardWatcher.on('change', () => {
|
||||
picgo.log.info('clipboard changed')
|
||||
@ -86,7 +87,7 @@ const buildMiniPageMenu = () => {
|
||||
{
|
||||
label: T('STOP_WATCH_CLIPBOARD'),
|
||||
click () {
|
||||
db.set('settings.isListeningClipboard', false)
|
||||
db.set(configPaths.settings.isListeningClipboard, false)
|
||||
ClipboardWatcher.stopListening()
|
||||
ClipboardWatcher.removeAllListeners()
|
||||
buildMiniPageMenu()
|
||||
@ -147,7 +148,7 @@ const buildMainPageMenu = (win: BrowserWindow) => {
|
||||
|
||||
const buildPicBedListMenu = () => {
|
||||
const picBeds = getPicBeds()
|
||||
const currentPicBed = picgo.getConfig('picBed.uploader')
|
||||
const currentPicBed = picgo.getConfig(configPaths.picBed.uploader)
|
||||
const currentPicBedName = picBeds.find(item => item.type === currentPicBed)?.name
|
||||
const picBedConfigList = picgo.getConfig<IUploaderConfig>('uploader')
|
||||
const currentPicBedMenuItem = [{
|
||||
@ -184,8 +185,8 @@ const buildPicBedListMenu = () => {
|
||||
click: !hasSubmenu
|
||||
? function () {
|
||||
picgo.saveConfig({
|
||||
'picBed.current': item.type,
|
||||
'picBed.uploader': item.type
|
||||
[configPaths.picBed.current]: item.type,
|
||||
[configPaths.picBed.uploader]: item.type
|
||||
})
|
||||
if (windowManager.has(IWindowList.SETTING_WINDOW)) {
|
||||
windowManager.get(IWindowList.SETTING_WINDOW)!.webContents.send('syncPicBed')
|
||||
@ -204,19 +205,19 @@ const buildPicBedListMenu = () => {
|
||||
|
||||
const handleRestoreState = (item: string, name: string): void => {
|
||||
if (item === 'uploader') {
|
||||
const current = picgo.getConfig('picBed.current')
|
||||
const current = picgo.getConfig(configPaths.picBed.current)
|
||||
if (current === name) {
|
||||
picgo.saveConfig({
|
||||
'picBed.current': 'smms',
|
||||
'picBed.uploader': 'smms'
|
||||
[configPaths.picBed.current]: 'smms',
|
||||
[configPaths.picBed.uploader]: 'smms'
|
||||
})
|
||||
}
|
||||
}
|
||||
if (item === 'transformer') {
|
||||
const current = picgo.getConfig('picBed.transformer')
|
||||
const current = picgo.getConfig(configPaths.picBed.transformer)
|
||||
if (current === name) {
|
||||
picgo.saveConfig({
|
||||
'picBed.transformer': 'path'
|
||||
[configPaths.picBed.transformer]: 'path'
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -286,20 +287,20 @@ const buildPluginPageMenu = (plugin: IPicGoPlugin) => {
|
||||
|
||||
// handle transformer
|
||||
if (plugin.config.transformer.name) {
|
||||
const currentTransformer = picgo.getConfig<string>('picBed.transformer') || 'path'
|
||||
const currentTransformer = picgo.getConfig<string>(configPaths.picBed.transformer) || 'path'
|
||||
const pluginTransformer = plugin.config.transformer.name
|
||||
const obj = {
|
||||
label: `${currentTransformer === pluginTransformer ? T('DISABLE') : T('ENABLE')}transformer - ${plugin.config.transformer.name}`,
|
||||
click () {
|
||||
const transformer = plugin.config.transformer.name
|
||||
const currentTransformer = picgo.getConfig<string>('picBed.transformer') || 'path'
|
||||
const currentTransformer = picgo.getConfig<string>(configPaths.picBed.transformer) || 'path'
|
||||
if (currentTransformer === transformer) {
|
||||
picgo.saveConfig({
|
||||
'picBed.transformer': 'path'
|
||||
[configPaths.picBed.transformer]: 'path'
|
||||
})
|
||||
} else {
|
||||
picgo.saveConfig({
|
||||
'picBed.transformer': transformer
|
||||
[configPaths.picBed.transformer]: transformer
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ import {
|
||||
import beforeOpen from '~/main/utils/beforeOpen'
|
||||
import ipcList from '~/main/events/ipcList'
|
||||
import busEventList from '~/main/events/busEventList'
|
||||
import { IRemoteNoticeTriggerHook, IWindowList } from '#/types/enum'
|
||||
import { II18nLanguage, IRemoteNoticeTriggerHook, ISartMode, IWindowList } from '#/types/enum'
|
||||
import windowManager from 'apis/app/window/windowManager'
|
||||
import {
|
||||
uploadChoosedFiles,
|
||||
@ -47,6 +47,7 @@ import fs from 'fs-extra'
|
||||
import { startFileServer } from '../fileServer'
|
||||
import webServer from '../server/webServer'
|
||||
import axios from 'axios'
|
||||
import { configPaths } from '~/universal/utils/configPaths'
|
||||
const isDevelopment = process.env.NODE_ENV !== 'production'
|
||||
|
||||
const handleStartUpFiles = (argv: string[], cwd: string) => {
|
||||
@ -74,10 +75,10 @@ autoUpdater.setFeedURL({
|
||||
autoUpdater.autoDownload = false
|
||||
|
||||
autoUpdater.on('update-available', async (info: UpdateInfo) => {
|
||||
const lang = db.get('settings.language') || 'zh-CN'
|
||||
const lang = db.get(configPaths.settings.language) || II18nLanguage.ZH_CN
|
||||
let updateLog = ''
|
||||
try {
|
||||
const url = lang === 'zh-CN' ? 'https://release.piclist.cn/currentVersion.md' : 'https://release.piclist.cn/currentVersion_en.md'
|
||||
const url = lang === II18nLanguage.ZH_CN ? 'https://release.piclist.cn/currentVersion.md' : 'https://release.piclist.cn/currentVersion_en.md'
|
||||
const res = await axios.get(url)
|
||||
updateLog = res.data
|
||||
} catch (e: any) {
|
||||
@ -98,7 +99,7 @@ autoUpdater.on('update-available', async (info: UpdateInfo) => {
|
||||
} else {
|
||||
shell.openExternal('https://github.com/Kuingsmile/PicList/releases/latest')
|
||||
}
|
||||
db.set('settings.showUpdateTip', !result.checkboxChecked)
|
||||
db.set(configPaths.settings.showUpdateTip, !result.checkboxChecked)
|
||||
}).catch((err) => {
|
||||
logger.error(err)
|
||||
})
|
||||
@ -152,27 +153,27 @@ class LifeCycle {
|
||||
createProtocol('picgo')
|
||||
windowManager.create(IWindowList.TRAY_WINDOW)
|
||||
windowManager.create(IWindowList.SETTING_WINDOW)
|
||||
const isAutoListenClipboard = db.get('settings.isAutoListenClipboard') || false
|
||||
const isAutoListenClipboard = db.get(configPaths.settings.isAutoListenClipboard) || false
|
||||
const ClipboardWatcher = clipboardPoll
|
||||
if (isAutoListenClipboard) {
|
||||
db.set('settings.isListeningClipboard', true)
|
||||
db.set(configPaths.settings.isListeningClipboard, true)
|
||||
ClipboardWatcher.startListening()
|
||||
ClipboardWatcher.on('change', () => {
|
||||
picgo.log.info('clipboard changed')
|
||||
uploadClipboardFiles()
|
||||
})
|
||||
} else {
|
||||
db.set('settings.isListeningClipboard', false)
|
||||
db.set(configPaths.settings.isListeningClipboard, false)
|
||||
}
|
||||
const isHideDock = db.get('settings.isHideDock') || false
|
||||
const startMode = db.get('settings.startMode') || 'quiet'
|
||||
const isHideDock = db.get(configPaths.settings.isHideDock) || false
|
||||
const startMode = db.get(configPaths.settings.startMode) || ISartMode.QUIET
|
||||
if (process.platform === 'darwin') {
|
||||
isHideDock ? app.dock.hide() : setDockMenu()
|
||||
startMode !== 'no-tray' && createTray()
|
||||
startMode !== ISartMode.NO_TRAY && createTray()
|
||||
} else {
|
||||
createTray()
|
||||
}
|
||||
db.set('needReload', false)
|
||||
db.set(configPaths.needReload, false)
|
||||
updateChecker()
|
||||
// 不需要阻塞
|
||||
process.nextTick(() => {
|
||||
@ -194,15 +195,15 @@ class LifeCycle {
|
||||
}
|
||||
await remoteNoticeHandler.init()
|
||||
remoteNoticeHandler.triggerHook(IRemoteNoticeTriggerHook.APP_START)
|
||||
if (startMode === 'mini') {
|
||||
if (startMode === ISartMode.MINI) {
|
||||
windowManager.create(IWindowList.MINI_WINDOW)
|
||||
const miniWindow = windowManager.get(IWindowList.MINI_WINDOW)!
|
||||
miniWindow.removeAllListeners()
|
||||
if (db.get('settings.miniWindowOntop')) {
|
||||
if (db.get(configPaths.settings.miniWindowOntop)) {
|
||||
miniWindow.setAlwaysOnTop(true)
|
||||
}
|
||||
const { width, height } = screen.getPrimaryDisplay().workAreaSize
|
||||
const lastPosition = db.get('settings.miniWindowPosition')
|
||||
const lastPosition = db.get(configPaths.settings.miniWindowPosition)
|
||||
if (lastPosition) {
|
||||
miniWindow.setPosition(lastPosition[0], lastPosition[1])
|
||||
} else {
|
||||
@ -210,13 +211,13 @@ class LifeCycle {
|
||||
}
|
||||
const setPositionFunc = () => {
|
||||
const position = miniWindow.getPosition()
|
||||
db.set('settings.miniWindowPosition', position)
|
||||
db.set(configPaths.settings.miniWindowPosition, position)
|
||||
}
|
||||
miniWindow.on('close', setPositionFunc)
|
||||
miniWindow.on('move', setPositionFunc)
|
||||
miniWindow.show()
|
||||
miniWindow.focus()
|
||||
} else if (startMode === 'main') {
|
||||
} else if (startMode === ISartMode.MAIN) {
|
||||
const settingWindow = windowManager.get(IWindowList.SETTING_WINDOW)!
|
||||
settingWindow.show()
|
||||
settingWindow.focus()
|
||||
@ -251,7 +252,7 @@ class LifeCycle {
|
||||
}
|
||||
})
|
||||
app.setLoginItemSettings({
|
||||
openAtLogin: db.get('settings.autoStart') || false
|
||||
openAtLogin: db.get(configPaths.settings.autoStart) || false
|
||||
})
|
||||
if (process.platform === 'win32') {
|
||||
app.setAppUserModelId('com.kuingsmile.piclist')
|
||||
|
@ -7,6 +7,7 @@ import { ILogType } from '#/types/enum'
|
||||
import { ILogColor, ILogger } from 'piclist/dist/types'
|
||||
import { ManageApiType, Undefinable } from '~/universal/types/manage'
|
||||
import { enforceNumber, isDev } from '#/utils/common'
|
||||
import { configPaths } from '~/universal/utils/configPaths'
|
||||
|
||||
export class ManageLogger implements ILogger {
|
||||
private readonly level = {
|
||||
@ -29,9 +30,9 @@ export class ManageLogger implements ILogger {
|
||||
`[PicList ${type.toUpperCase()}]`
|
||||
)
|
||||
console.log(logHeader, ...msg)
|
||||
this.logLevel = this.ctx.getConfig('settings.logLevel')
|
||||
this.logLevel = this.ctx.getConfig(configPaths.settings.logLevel)
|
||||
this.logPath =
|
||||
this.ctx.getConfig<Undefinable<string>>('settings.logPath') ||
|
||||
this.ctx.getConfig<Undefinable<string>>(configPaths.settings.logPath) ||
|
||||
path.join(this.ctx.baseDir, './manage.log')
|
||||
setTimeout(() => {
|
||||
try {
|
||||
@ -61,7 +62,7 @@ export class ManageLogger implements ILogger {
|
||||
const logFileSizeLimit =
|
||||
enforceNumber(
|
||||
this.ctx.getConfig<Undefinable<number>>(
|
||||
'settings.logFileSizeLimit'
|
||||
configPaths.settings.logFileSizeLimit
|
||||
) || 10
|
||||
) *
|
||||
1024 *
|
||||
|
@ -11,6 +11,7 @@ import multer from 'multer'
|
||||
import { app } from 'electron'
|
||||
import path from 'path'
|
||||
import fs from 'fs-extra'
|
||||
import { configPaths } from '~/universal/utils/configPaths'
|
||||
|
||||
const DEFAULT_PORT = 36677
|
||||
const DEFAULT_HOST = '0.0.0.0'
|
||||
@ -49,10 +50,10 @@ class Server {
|
||||
}
|
||||
|
||||
getConfigWithDefaults () {
|
||||
let config = picgo.getConfig<IServerConfig>('settings.server')
|
||||
let config = picgo.getConfig<IServerConfig>(configPaths.settings.server)
|
||||
if (!this.isValidConfig(config)) {
|
||||
config = { port: DEFAULT_PORT, host: DEFAULT_HOST, enable: true }
|
||||
picgo.saveConfig({ 'settings.server': config })
|
||||
picgo.saveConfig({ [configPaths.settings.server]: config })
|
||||
}
|
||||
config.host = config.host === '127.0.0.1' ? '0.0.0.0' : config.host
|
||||
return config
|
||||
@ -96,7 +97,7 @@ class Server {
|
||||
logger.info('[PicList Server] get a POST request from IP:', remoteAddress)
|
||||
let urlSP = query ? new URLSearchParams(query) : undefined
|
||||
if (remoteAddress === '::1' || remoteAddress === '127.0.0.1') {
|
||||
const serverKey = picgo.getConfig<string>('settings.serverKey') || ''
|
||||
const serverKey = picgo.getConfig<string>(configPaths.settings.serverKey) || ''
|
||||
if (urlSP) {
|
||||
urlSP.set('key', serverKey)
|
||||
} else {
|
||||
|
@ -15,6 +15,7 @@ import { AESHelper } from '../utils/aesHelper'
|
||||
import { marked } from 'marked'
|
||||
import { markdownContent } from './apiDoc'
|
||||
import http from 'http'
|
||||
import { configPaths } from '~/universal/utils/configPaths'
|
||||
|
||||
const appPath = app.getPath('userData')
|
||||
const serverTempDir = path.join(appPath, 'serverTemp')
|
||||
@ -46,7 +47,7 @@ router.post('/upload', async ({
|
||||
}): Promise<void> => {
|
||||
try {
|
||||
const passedKey = urlparams?.get('key')
|
||||
const serverKey = picgo.getConfig<string>('settings.serverKey') || ''
|
||||
const serverKey = picgo.getConfig<string>(configPaths.settings.serverKey) || ''
|
||||
if (serverKey && passedKey !== serverKey) {
|
||||
handleResponse({
|
||||
response,
|
||||
|
@ -4,6 +4,7 @@ import path from 'path'
|
||||
import picgo from '@core/picgo'
|
||||
import logger from '../../apis/core/picgo/logger'
|
||||
import { encodeFilePath } from '~/universal/utils/common'
|
||||
import { configPaths } from '~/universal/utils/configPaths'
|
||||
|
||||
const defaultPath = process.platform === 'win32' ? 'C:\\Users' : '/'
|
||||
|
||||
@ -49,10 +50,10 @@ class WebServer {
|
||||
|
||||
loadConfig (): void {
|
||||
this.config = {
|
||||
enableWebServer: picgo.getConfig<boolean>('settings.enableWebServer') || false,
|
||||
webServerHost: picgo.getConfig<string>('settings.webServerHost') || '0.0.0.0',
|
||||
webServerPort: picgo.getConfig<number>('settings.webServerPort') || 37777,
|
||||
webServerPath: picgo.getConfig<string>('settings.webServerPath') || defaultPath
|
||||
enableWebServer: picgo.getConfig<boolean>(configPaths.settings.enableWebServer) || false,
|
||||
webServerHost: picgo.getConfig<string>(configPaths.settings.webServerHost) || '0.0.0.0',
|
||||
webServerPort: picgo.getConfig<number>(configPaths.settings.webServerPort) || 37777,
|
||||
webServerPath: picgo.getConfig<string>(configPaths.settings.webServerPath) || defaultPath
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,10 @@
|
||||
import crypto from 'crypto'
|
||||
import picgo from '@core/picgo'
|
||||
import { DEFAULT_AES_PASSWORD } from '~/universal/utils/static'
|
||||
import { configPaths } from '~/universal/utils/configPaths'
|
||||
|
||||
function getDerivedKey (): Buffer {
|
||||
const userPassword = picgo.getConfig<string>('settings.aesPassword') || 'PicList-aesPassword'
|
||||
const userPassword = picgo.getConfig<string>(configPaths.settings.aesPassword) || DEFAULT_AES_PASSWORD
|
||||
const fixedSalt = Buffer.from('a8b3c4d2e4f5098712345678feedc0de', 'hex')
|
||||
const fixedIterations = 100000
|
||||
const keyLength = 32
|
||||
|
@ -5,9 +5,11 @@ import { handleUrlEncode } from '~/universal/utils/common'
|
||||
import axios from 'axios'
|
||||
import FormData from 'form-data'
|
||||
import logger from '../apis/core/picgo/logger'
|
||||
import { configPaths } from '~/universal/utils/configPaths'
|
||||
import { IShortUrlServer } from '~/universal/types/enum'
|
||||
|
||||
export const handleCopyUrl = (str: string): void => {
|
||||
if (db.get('settings.autoCopy') !== false) {
|
||||
if (db.get(configPaths.settings.autoCopy) !== false) {
|
||||
clipboard.writeText(str)
|
||||
}
|
||||
}
|
||||
@ -122,16 +124,16 @@ export const getClipboardFilePath = (): string => {
|
||||
return ''
|
||||
}
|
||||
|
||||
export const handleUrlEncodeWithSetting = (url: string) => db.get('settings.encodeOutputURL') ? handleUrlEncode(url) : url
|
||||
export const handleUrlEncodeWithSetting = (url: string) => db.get(configPaths.settings.encodeOutputURL) ? handleUrlEncode(url) : url
|
||||
|
||||
const c1nApi = 'https://c1n.cn/link/short'
|
||||
|
||||
export const generateShortUrl = async (url: string) => {
|
||||
const server = db.get('settings.shortUrlServer') || 'c1n'
|
||||
if (server === 'c1n') {
|
||||
const server = db.get(configPaths.settings.shortUrlServer) || IShortUrlServer.C1N
|
||||
if (server === IShortUrlServer.C1N) {
|
||||
const form = new FormData()
|
||||
form.append('url', url)
|
||||
const c1nToken = db.get('settings.c1nToken') || ''
|
||||
const c1nToken = db.get(configPaths.settings.c1nToken) || ''
|
||||
if (!c1nToken) {
|
||||
logger.warn('c1n token is not set')
|
||||
return url
|
||||
@ -148,9 +150,9 @@ export const generateShortUrl = async (url: string) => {
|
||||
} catch (e: any) {
|
||||
logger.error(e)
|
||||
}
|
||||
} else if (server === 'yourls') {
|
||||
let domain = db.get('settings.yourlsDomain') || ''
|
||||
const signature = db.get('settings.yourlsSignature') || ''
|
||||
} else if (server === IShortUrlServer.YOURLS) {
|
||||
let domain = db.get(configPaths.settings.yourlsDomain) || ''
|
||||
const signature = db.get(configPaths.settings.yourlsSignature) || ''
|
||||
if (domain && signature) {
|
||||
if (!/^https?:\/\//.test(domain)) {
|
||||
domain = `http://${domain}`
|
||||
@ -169,8 +171,8 @@ export const generateShortUrl = async (url: string) => {
|
||||
} else {
|
||||
logger.warn('Yourls server or signature is not set')
|
||||
}
|
||||
} else if (server === 'cf_worker') {
|
||||
let cfWorkerHost = db.get('settings.cfWorkerHost') || ''
|
||||
} else if (server === IShortUrlServer.CFWORKER) {
|
||||
let cfWorkerHost = db.get(configPaths.settings.cfWorkerHost) || ''
|
||||
cfWorkerHost = cfWorkerHost.replace(/\/$/, '')
|
||||
if (cfWorkerHost) {
|
||||
try {
|
||||
|
@ -12,8 +12,8 @@ interface DogecloudTokenFull {
|
||||
accessKeyId: string
|
||||
secretAccessKey: string
|
||||
sessionToken: string
|
||||
},
|
||||
ExpiredAt: number,
|
||||
}
|
||||
ExpiredAt: number
|
||||
Buckets: {
|
||||
name: string
|
||||
s3Bucket: string
|
||||
|
@ -1,8 +1,9 @@
|
||||
import picgo from '@core/picgo'
|
||||
import { configPaths } from '~/universal/utils/configPaths'
|
||||
|
||||
const getPicBeds = () => {
|
||||
const picBedTypes = picgo.helper.uploader.getIdList()
|
||||
const picBedFromDB = picgo.getConfig<IPicBedType[]>('picBed.list') || []
|
||||
const picBedFromDB = picgo.getConfig<IPicBedType[]>(configPaths.picBed.list) || []
|
||||
const picBeds = picBedTypes.map((item: string) => {
|
||||
const visible = picBedFromDB.find((i: IPicBedType) => i.type === item) // object or undefined
|
||||
return {
|
||||
|
@ -1,6 +1,9 @@
|
||||
import db from '~/main/apis/core/datastore'
|
||||
import { i18nManager } from '~/main/i18n'
|
||||
import { II18nLanguage } from '~/universal/types/enum'
|
||||
import { configPaths } from '~/universal/utils/configPaths'
|
||||
|
||||
export const initI18n = () => {
|
||||
const currentLanguage = db.get('settings.language') || 'zh-CN'
|
||||
const currentLanguage = db.get(configPaths.settings.language) || II18nLanguage.ZH_CN
|
||||
i18nManager.setCurrentLanguage(currentLanguage)
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { v4 as uuid } from 'uuid'
|
||||
import { trimValues } from '#/utils/common'
|
||||
import picgo from '@core/picgo'
|
||||
import { configPaths } from '~/universal/utils/configPaths'
|
||||
|
||||
export const handleConfigWithFunction = (config: IPicGoPluginOriginConfig[]): IPicGoPluginConfig[] => {
|
||||
for (const i in config) {
|
||||
@ -61,8 +62,8 @@ export const changeCurrentUploader = (type: string, config?: IStringKeyMap, id?:
|
||||
})
|
||||
}
|
||||
picgo.saveConfig({
|
||||
'picBed.current': type,
|
||||
'picBed.uploader': type
|
||||
[configPaths.picBed.current]: type,
|
||||
[configPaths.picBed.uploader]: type
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@ import { IPasteStyle } from '#/types/enum'
|
||||
import { generateShortUrl } from '~/main/utils/common'
|
||||
import db from '~/main/apis/core/datastore'
|
||||
import { handleUrlEncodeWithSetting } from './common'
|
||||
import { configPaths } from '~/universal/utils/configPaths'
|
||||
|
||||
export const formatCustomLink = (customLink: string, item: ImgInfo) => {
|
||||
const fileName = item.fileName!.replace(new RegExp(`\\${item.extname}$`), '')
|
||||
@ -28,7 +29,7 @@ export default async (style: IPasteStyle, item: ImgInfo, customLink: string | un
|
||||
url = item.imgUrl || item.url || ''
|
||||
}
|
||||
url = handleUrlEncodeWithSetting(url)
|
||||
const useShortUrl = db.get('settings.useShortUrl') || false
|
||||
const useShortUrl = db.get(configPaths.settings.useShortUrl) || false
|
||||
if (useShortUrl) {
|
||||
url = await generateShortUrl(url)
|
||||
}
|
||||
|
@ -6,18 +6,7 @@ import db from '~/main/apis/core/datastore'
|
||||
import { HttpsProxyAgent } from 'hpagent'
|
||||
import { Octokit } from '@octokit/rest'
|
||||
import logger from 'apis/core/picgo/logger'
|
||||
|
||||
interface SyncConfig {
|
||||
type: string
|
||||
file?: string
|
||||
username: string
|
||||
repo: string
|
||||
branch: string
|
||||
token: string
|
||||
endpoint?: string
|
||||
proxy?: string
|
||||
interval?: number
|
||||
}
|
||||
import { configPaths } from '~/universal/utils/configPaths'
|
||||
|
||||
const STORE_PATH = app.getPath('userData')
|
||||
|
||||
@ -28,7 +17,7 @@ const configFileNames = [
|
||||
'manage.bak.json'
|
||||
]
|
||||
|
||||
function getOctokit (syncConfig: SyncConfig) {
|
||||
function getOctokit (syncConfig: ISyncConfig) {
|
||||
const { token, proxy } = syncConfig
|
||||
return new Octokit({
|
||||
auth: token,
|
||||
@ -47,7 +36,7 @@ function getOctokit (syncConfig: SyncConfig) {
|
||||
}
|
||||
|
||||
function getSyncConfig () {
|
||||
return db.get('settings.sync') || {
|
||||
return db.get(configPaths.settings.sync) || {
|
||||
type: 'github',
|
||||
username: '',
|
||||
repo: '',
|
||||
@ -57,12 +46,12 @@ function getSyncConfig () {
|
||||
}
|
||||
}
|
||||
|
||||
function syncConfigValidator (syncConfig: SyncConfig) {
|
||||
function syncConfigValidator (syncConfig: ISyncConfig) {
|
||||
const { type, username, repo, branch, token } = syncConfig
|
||||
return type && username && repo && branch && token
|
||||
}
|
||||
|
||||
async function uploadLocalToRemote (syncConfig: SyncConfig, fileName: string) {
|
||||
async function uploadLocalToRemote (syncConfig: ISyncConfig, fileName: string) {
|
||||
const localFilePath = path.join(STORE_PATH, fileName)
|
||||
if (!fs.existsSync(localFilePath)) {
|
||||
return false
|
||||
@ -120,7 +109,7 @@ async function uploadLocalToRemote (syncConfig: SyncConfig, fileName: string) {
|
||||
}
|
||||
}
|
||||
|
||||
async function updateLocalToRemote (syncConfig: SyncConfig, fileName: string) {
|
||||
async function updateLocalToRemote (syncConfig: ISyncConfig, fileName: string) {
|
||||
const localFilePath = path.join(STORE_PATH, fileName)
|
||||
if (!fs.existsSync(localFilePath)) {
|
||||
return false
|
||||
@ -201,7 +190,7 @@ async function updateLocalToRemote (syncConfig: SyncConfig, fileName: string) {
|
||||
}
|
||||
}
|
||||
|
||||
async function downloadRemoteToLocal (syncConfig: SyncConfig, fileName: string) {
|
||||
async function downloadRemoteToLocal (syncConfig: ISyncConfig, fileName: string) {
|
||||
const localFilePath = path.join(STORE_PATH, fileName)
|
||||
const { username, repo, branch, token, proxy, type } = syncConfig
|
||||
if (type === 'gitee') {
|
||||
@ -304,7 +293,7 @@ async function uploadFile (fileName: string, all = false) {
|
||||
}
|
||||
}
|
||||
|
||||
async function uploadFunc (syncConfig: SyncConfig, fileName: string) {
|
||||
async function uploadFunc (syncConfig: ISyncConfig, fileName: string) {
|
||||
let result = false
|
||||
try {
|
||||
result = await updateLocalToRemote(syncConfig, fileName)
|
||||
@ -342,7 +331,7 @@ async function downloadFile (fileName: string, all = false) {
|
||||
}
|
||||
}
|
||||
|
||||
async function downloadFunc (syncConfig: SyncConfig, fileName: string) {
|
||||
async function downloadFunc (syncConfig: ISyncConfig, fileName: string) {
|
||||
const result = await downloadRemoteToLocal(syncConfig, fileName)
|
||||
if (!result) {
|
||||
logger.error(`download ${fileName} failed`)
|
||||
|
@ -1,10 +1,11 @@
|
||||
import db from '~/main/apis/core/datastore'
|
||||
import { autoUpdater } from 'electron-updater'
|
||||
import { configPaths } from '~/universal/utils/configPaths'
|
||||
|
||||
const updateChecker = async () => {
|
||||
let showTip = db.get('settings.showUpdateTip')
|
||||
let showTip = db.get(configPaths.settings.showUpdateTip)
|
||||
if (showTip === undefined) {
|
||||
db.set('settings.showUpdateTip', true)
|
||||
db.set(configPaths.settings.showUpdateTip, true)
|
||||
showTip = true
|
||||
}
|
||||
if (showTip) {
|
||||
|
@ -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: '![$fileName]($url)'
|
||||
})
|
||||
|
||||
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 || '![$fileName]($url)'
|
||||
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') || '![$fileName]($url)'
|
||||
customLink.value = await getConfig<string>(configPaths.settings.customLink) || '![$fileName]($url)'
|
||||
}
|
||||
|
||||
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') || '![$fileName]($url)'
|
||||
pasteStyle.value = await getConfig(configPaths.settings.pasteStyle) || IPasteStyle.MARKDOWN
|
||||
customLink.value = await getConfig(configPaths.settings.customLink) || '![$fileName]($url)'
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
2
src/universal/types/electron.d.ts
vendored
2
src/universal/types/electron.d.ts
vendored
@ -5,7 +5,7 @@ declare type IWindowList = import('./enum').IWindowList
|
||||
declare interface IWindowListItem {
|
||||
isValid: boolean
|
||||
multiple: boolean
|
||||
options: () => IBrowserWindowOptions,
|
||||
options: () => IBrowserWindowOptions
|
||||
callback: (window: BrowserWindow, windowManager: IWindowManager) => void
|
||||
}
|
||||
|
||||
|
@ -96,3 +96,22 @@ export enum IToolboxItemCheckStatus {
|
||||
SUCCESS = 'success',
|
||||
ERROR = 'error',
|
||||
}
|
||||
|
||||
export enum ISartMode {
|
||||
QUIET = 'quiet',
|
||||
MINI = 'mini',
|
||||
MAIN = 'main',
|
||||
NO_TRAY = 'no-tray'
|
||||
}
|
||||
|
||||
export enum II18nLanguage {
|
||||
ZH_CN = 'zh-CN',
|
||||
ZH_TW = 'zh-TW',
|
||||
EN = 'en'
|
||||
}
|
||||
|
||||
export enum IShortUrlServer {
|
||||
C1N = 'c1n',
|
||||
YOURLS = 'yourls',
|
||||
CFWORKER = 'cf_worker'
|
||||
}
|
||||
|
72
src/universal/types/manage.d.ts
vendored
72
src/universal/types/manage.d.ts
vendored
@ -4,39 +4,39 @@ import { ILogger } from "piclist/dist/types";
|
||||
type Undefinable<T> = T | undefined;
|
||||
|
||||
declare interface ManageError extends Error {
|
||||
code?: number;
|
||||
param?: string;
|
||||
stack?: string;
|
||||
picbed?: string;
|
||||
code?: number
|
||||
param?: string
|
||||
stack?: string
|
||||
picbed?: string
|
||||
}
|
||||
|
||||
type PicBedMangeConfig = IStringKeyMap;
|
||||
|
||||
interface PicBedManageConfigMap {
|
||||
[key: string]: PicBedMangeConfig;
|
||||
[key: string]: PicBedMangeConfig
|
||||
}
|
||||
|
||||
interface ManageApiType {
|
||||
/**
|
||||
* logger
|
||||
*/
|
||||
logger: ILogger;
|
||||
logger: ILogger
|
||||
/**
|
||||
* congif path
|
||||
*/
|
||||
configPath: string;
|
||||
configPath: string
|
||||
/**
|
||||
* basedir
|
||||
*/
|
||||
baseDir: string;
|
||||
baseDir: string
|
||||
/**
|
||||
* current picBed name
|
||||
*/
|
||||
currentPicBed: string;
|
||||
currentPicBed: string
|
||||
/**
|
||||
* current picBed config
|
||||
*/
|
||||
currentPicBedConfig: PicBedMangeConfig;
|
||||
currentPicBedConfig: PicBedMangeConfig
|
||||
/**
|
||||
* get manage config
|
||||
*/
|
||||
@ -62,136 +62,136 @@ interface ManageApiType {
|
||||
*/
|
||||
getBucketListRecursively: (
|
||||
param?: IStringKeyMap
|
||||
) => Promise<any | ManageError>;
|
||||
) => Promise<any | ManageError>
|
||||
/**
|
||||
* get bucket list
|
||||
*/
|
||||
getBucketListBackstage: (
|
||||
param?: IStringKeyMap
|
||||
) => Promise<any | ManageError>;
|
||||
) => Promise<any | ManageError>
|
||||
/**
|
||||
* get bucket list
|
||||
*/
|
||||
getBucketList: (
|
||||
param?: IStringKeyMap
|
||||
) => Promise<any | ManageError>;
|
||||
) => Promise<any | ManageError>
|
||||
getBucketDomain: (
|
||||
param: IStringKeyMap
|
||||
) => Promise<any>;
|
||||
) => Promise<any>
|
||||
/**
|
||||
* get bucket info
|
||||
*/
|
||||
getBucketInfo: (
|
||||
param?: IStringKeyMap
|
||||
) => Promise<IStringKeyMap | ManageError>;
|
||||
) => Promise<IStringKeyMap | ManageError>
|
||||
/**
|
||||
* create bucket
|
||||
*/
|
||||
createBucket: (
|
||||
param?: IStringKeyMap
|
||||
) => Promise<boolean>;
|
||||
) => Promise<boolean>
|
||||
/**
|
||||
* delete bucket
|
||||
*/
|
||||
deleteBucket: (
|
||||
param?: IStringKeyMap
|
||||
) => Promise<boolean>;
|
||||
) => Promise<boolean>
|
||||
/**
|
||||
* get Operator list
|
||||
* specific for upyun
|
||||
*/
|
||||
getOperatorList: (
|
||||
param?: IStringKeyMap
|
||||
) => Promise<string[] | ManageError>;
|
||||
) => Promise<string[] | ManageError>
|
||||
/**
|
||||
* add Operator
|
||||
* specific for upyun
|
||||
*/
|
||||
addOperator: (
|
||||
param?: IStringKeyMap
|
||||
) => Promise<boolean>;
|
||||
) => Promise<boolean>
|
||||
/**
|
||||
* delete Operator
|
||||
* specific for upyun
|
||||
*/
|
||||
deleteOperator: (
|
||||
param?: IStringKeyMap
|
||||
) => Promise<boolean>;
|
||||
) => Promise<boolean>
|
||||
/**
|
||||
* get bucket ACL policy
|
||||
*/
|
||||
getBucketAclPolicy: (
|
||||
param?: IStringKeyMap
|
||||
) => Promise<IStringKeyMap | ManageError>;
|
||||
) => Promise<IStringKeyMap | ManageError>
|
||||
/**
|
||||
* set bucket ACL policy
|
||||
*/
|
||||
setBucketAclPolicy: (
|
||||
param?: IStringKeyMap
|
||||
) => Promise<boolean>;
|
||||
) => Promise<boolean>
|
||||
/**
|
||||
* get bucket file list
|
||||
*/
|
||||
getBucketFileList: (
|
||||
param?: IStringKeyMap
|
||||
) => Promise<IStringKeyMap | ManageError>;
|
||||
) => Promise<IStringKeyMap | ManageError>
|
||||
/**
|
||||
* delete bucket file
|
||||
*/
|
||||
deleteBucketFile: (
|
||||
param?: IStringKeyMap
|
||||
) => Promise<boolean>;
|
||||
) => Promise<boolean>
|
||||
/**
|
||||
* delete folder
|
||||
*/
|
||||
deleteBucketFolder: (
|
||||
param?: IStringKeyMap
|
||||
) => Promise<boolean>;
|
||||
) => Promise<boolean>
|
||||
/**
|
||||
* rename bucket file
|
||||
*/
|
||||
renameBucketFile: (
|
||||
param?: IStringKeyMap
|
||||
) => Promise<boolean>;
|
||||
) => Promise<boolean>
|
||||
/**
|
||||
* download bucket file
|
||||
*/
|
||||
downloadBucketFile: (
|
||||
param?: IStringKeyMap
|
||||
) => Promise<boolean>;
|
||||
) => Promise<boolean>
|
||||
/**
|
||||
* copy or move between buckets
|
||||
*/
|
||||
copyMoveBucketFile: (
|
||||
param?: IStringKeyMap
|
||||
) => Promise<boolean>;
|
||||
) => Promise<boolean>
|
||||
/**
|
||||
* create folder
|
||||
*/
|
||||
createBucketFolder: (
|
||||
param?: IStringKeyMap
|
||||
) => Promise<boolean>;
|
||||
) => Promise<boolean>
|
||||
/**
|
||||
* upload file
|
||||
*/
|
||||
uploadBucketFile: (
|
||||
param?: IStringKeyMap
|
||||
) => Promise<boolean>;
|
||||
) => Promise<boolean>
|
||||
/**
|
||||
* get presigned url
|
||||
*/
|
||||
getPreSignedUrl: (
|
||||
param?: IStringKeyMap
|
||||
) => Promise<string>;
|
||||
) => Promise<string>
|
||||
}
|
||||
|
||||
/** PicList 存储管理功能配置文件类型定义 */
|
||||
interface ManageConfigType {
|
||||
picBed: {
|
||||
[others: string]: any;
|
||||
};
|
||||
[others: string]: any
|
||||
}
|
||||
settings: {
|
||||
[others: string]: any;
|
||||
};
|
||||
[others: string]: any;
|
||||
[others: string]: any
|
||||
}
|
||||
[others: string]: any
|
||||
}
|
||||
|
175
src/universal/types/types.d.ts
vendored
175
src/universal/types/types.d.ts
vendored
@ -35,6 +35,18 @@ interface IServerConfig {
|
||||
enable: boolean
|
||||
}
|
||||
|
||||
interface ISyncConfig {
|
||||
type: string
|
||||
file?: string
|
||||
username: string
|
||||
repo: string
|
||||
branch: string
|
||||
token: string
|
||||
endpoint?: string
|
||||
proxy?: string
|
||||
interval?: number
|
||||
}
|
||||
|
||||
// Image && PicBed
|
||||
interface ImgInfo {
|
||||
buffer?: Buffer
|
||||
@ -86,25 +98,25 @@ interface IOldShortKeyConfigs {
|
||||
}
|
||||
|
||||
interface IKeyCommandType {
|
||||
key: string,
|
||||
key: string
|
||||
command: string
|
||||
}
|
||||
|
||||
// Main process
|
||||
interface IBrowserWindowOptions {
|
||||
height: number,
|
||||
width: number,
|
||||
show: boolean,
|
||||
fullscreenable: boolean,
|
||||
resizable: boolean,
|
||||
height: number
|
||||
width: number
|
||||
show: boolean
|
||||
fullscreenable: boolean
|
||||
resizable: boolean
|
||||
webPreferences: {
|
||||
nodeIntegration: boolean,
|
||||
nodeIntegrationInWorker: boolean,
|
||||
contextIsolation: boolean,
|
||||
nodeIntegration: boolean
|
||||
nodeIntegrationInWorker: boolean
|
||||
contextIsolation: boolean
|
||||
backgroundThrottling: boolean
|
||||
webSecurity?: boolean
|
||||
},
|
||||
vibrancy?: string | any,
|
||||
}
|
||||
vibrancy?: string | any
|
||||
frame?: boolean
|
||||
center?: boolean
|
||||
title?: string
|
||||
@ -275,67 +287,148 @@ interface IShortKeyHandlerObj {
|
||||
|
||||
type IShortKeyHandler = (ctx: ICtx, guiApi?: IGuiApi) => Promise<void | ICtx>
|
||||
|
||||
type PartialKeys<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>
|
||||
|
||||
interface shortKeyHandlerMap {
|
||||
from: string
|
||||
handle: IShortKeyHandler
|
||||
}
|
||||
|
||||
// PicBeds
|
||||
interface ITelegraphConfig {
|
||||
proxy?: string
|
||||
}
|
||||
|
||||
interface ILocalConfig {
|
||||
path: string
|
||||
customUrl?: string
|
||||
webPath?: string
|
||||
}
|
||||
|
||||
interface IAliYunConfig {
|
||||
accessKeyId: string
|
||||
accessKeySecret: string,
|
||||
bucket: string,
|
||||
area: string,
|
||||
path: string,
|
||||
accessKeySecret: string
|
||||
bucket: string
|
||||
area: string
|
||||
path: string
|
||||
customUrl: string
|
||||
options: string
|
||||
}
|
||||
|
||||
interface IGitHubConfig {
|
||||
repo: string,
|
||||
token: string,
|
||||
path: string,
|
||||
customUrl: string,
|
||||
repo: string
|
||||
token: string
|
||||
path: string
|
||||
customUrl: string
|
||||
branch: string
|
||||
}
|
||||
|
||||
interface IImgurConfig {
|
||||
clientId: string,
|
||||
clientId: string
|
||||
proxy: string
|
||||
username: string
|
||||
accessToken: string
|
||||
album: string
|
||||
}
|
||||
|
||||
interface IQiniuConfig {
|
||||
accessKey: string,
|
||||
secretKey: string,
|
||||
bucket: string,
|
||||
url: string,
|
||||
area: string,
|
||||
options: string,
|
||||
accessKey: string
|
||||
secretKey: string
|
||||
bucket: string
|
||||
url: string
|
||||
area: 'z0' | 'z1' | 'z2' | 'na0' | 'as0' | string
|
||||
options: string
|
||||
path: string
|
||||
}
|
||||
|
||||
interface ISMMSConfig {
|
||||
token: string
|
||||
backupDomain?: string
|
||||
}
|
||||
|
||||
interface ITcYunConfig {
|
||||
secretId: string,
|
||||
secretKey: string,
|
||||
bucket: string,
|
||||
appId: string,
|
||||
area: string,
|
||||
path: string,
|
||||
customUrl: string,
|
||||
version: 'v4' | 'v5',
|
||||
secretId: string
|
||||
secretKey: string
|
||||
bucket: string
|
||||
appId: string
|
||||
endpoint: string
|
||||
area: string
|
||||
path: string
|
||||
customUrl: string
|
||||
version: 'v4' | 'v5'
|
||||
options: string
|
||||
slim: boolean
|
||||
}
|
||||
|
||||
interface IUpYunConfig {
|
||||
bucket: string,
|
||||
operator: string,
|
||||
password: string,
|
||||
options: string,
|
||||
bucket: string
|
||||
operator: string
|
||||
password: string
|
||||
options: string
|
||||
path: string
|
||||
url: string
|
||||
antiLeechToken: string
|
||||
expireTime: number
|
||||
endpoint: string
|
||||
}
|
||||
|
||||
interface IWebdavPlistConfig {
|
||||
host: string
|
||||
sslEnabled: boolean
|
||||
username: string
|
||||
password: string
|
||||
path: string
|
||||
webpath: string
|
||||
customUrl: string
|
||||
authType: string
|
||||
options: string
|
||||
}
|
||||
|
||||
interface ISftpPlistConfig {
|
||||
host: string
|
||||
port?: number
|
||||
username: string
|
||||
password?: string
|
||||
privateKey?: string
|
||||
passphrase?: string
|
||||
uploadPath?: string
|
||||
customUrl?: string
|
||||
webPath?: string
|
||||
fileUser?: string
|
||||
fileMode?: string
|
||||
dirMode?: string
|
||||
}
|
||||
|
||||
interface IPicListConfig {
|
||||
host: string
|
||||
port?: number
|
||||
picbed?: string
|
||||
configName?: string
|
||||
serverKey?: string
|
||||
}
|
||||
|
||||
interface ILskyConfig {
|
||||
version: string
|
||||
host: string
|
||||
token: string
|
||||
strategyId: string
|
||||
albumId: string
|
||||
permission: IStringKeyMap
|
||||
}
|
||||
|
||||
interface IAwsS3PListUserConfig {
|
||||
accessKeyID: string
|
||||
secretAccessKey: string
|
||||
bucketName: string
|
||||
uploadPath: string
|
||||
region?: string
|
||||
endpoint?: string
|
||||
proxy?: string
|
||||
urlPrefix?: string
|
||||
pathStyleAccess?: boolean
|
||||
rejectUnauthorized?: boolean
|
||||
acl?: string
|
||||
disableBucketPrefixToURL?: boolean | string
|
||||
}
|
||||
|
||||
type ILoggerType = string | Error | boolean | number | undefined
|
||||
@ -362,9 +455,9 @@ type ILogArgvType = string | number
|
||||
type ILogArgvTypeWithError = ILogArgvType | Error
|
||||
|
||||
interface IMiniWindowPos {
|
||||
x: number,
|
||||
y: number,
|
||||
height: number,
|
||||
x: number
|
||||
y: number
|
||||
height: number
|
||||
width: number
|
||||
}
|
||||
|
||||
|
48
src/universal/types/view.d.ts
vendored
48
src/universal/types/view.d.ts
vendored
@ -13,30 +13,30 @@ interface ISettingForm {
|
||||
autoCopyUrl: boolean
|
||||
checkBetaUpdate: boolean
|
||||
useBuiltinClipboard: boolean
|
||||
language: string
|
||||
logFileSizeLimit: number,
|
||||
deleteCloudFile: boolean,
|
||||
isCustomMiniIcon: boolean,
|
||||
customMiniIcon: string,
|
||||
isHideDock: boolean,
|
||||
autoImport: boolean,
|
||||
autoImportPicBed: string[],
|
||||
encodeOutputURL: boolean,
|
||||
isAutoListenClipboard: boolean,
|
||||
useShortUrl: boolean,
|
||||
c1nToken: string,
|
||||
shortUrlServer: string,
|
||||
yourlsDomain: string,
|
||||
yourlsSignature: string,
|
||||
cfWorkerHost: string,
|
||||
deleteLocalFile: boolean,
|
||||
serverKey: string,
|
||||
aesPassword: string,
|
||||
manualPageOpen: string,
|
||||
enableWebServer: boolean,
|
||||
webServerHost: string,
|
||||
webServerPort: number,
|
||||
webServerPath: string,
|
||||
language: 'zh-CN' | 'zh-TW' | 'en'
|
||||
logFileSizeLimit: number
|
||||
deleteCloudFile: boolean
|
||||
isCustomMiniIcon: boolean
|
||||
customMiniIcon: string
|
||||
isHideDock: boolean
|
||||
autoImport: boolean
|
||||
autoImportPicBed: string[]
|
||||
encodeOutputURL: boolean
|
||||
isAutoListenClipboard: boolean
|
||||
useShortUrl: boolean
|
||||
c1nToken: string
|
||||
shortUrlServer: string
|
||||
yourlsDomain: string
|
||||
yourlsSignature: string
|
||||
cfWorkerHost: string
|
||||
deleteLocalFile: boolean
|
||||
serverKey: string
|
||||
aesPassword: string
|
||||
manualPageOpen: 'window' | 'browser'
|
||||
enableWebServer: boolean
|
||||
webServerHost: string
|
||||
webServerPort: number
|
||||
webServerPath: string
|
||||
}
|
||||
|
||||
interface IShortKeyMap {
|
||||
|
@ -33,7 +33,15 @@ export const enforceNumber = (num: number | string) => isNaN(+num) ? 0 : +num
|
||||
export const isDev = process.env.NODE_ENV === 'development'
|
||||
|
||||
export const trimValues = <T extends IStringKeyMap>(obj: T): {[K in keyof T]: T[K] extends string ? string : T[K]} => {
|
||||
return Object.fromEntries(Object.entries(obj).map(([key, value]) => [key, typeof value === 'string' ? value.trim() : value])) as {[K in keyof T]: T[K] extends string ? string : T[K]}
|
||||
return Object
|
||||
.fromEntries(
|
||||
Object
|
||||
.entries(obj)
|
||||
.map(([key, value]) =>
|
||||
[key, typeof value === 'string'
|
||||
? value.trim()
|
||||
: value])
|
||||
) as {[K in keyof T]: T[K] extends string ? string : T[K]}
|
||||
}
|
||||
|
||||
export function isNeedToShorten (alias: string, cutOff = 20) {
|
||||
@ -54,7 +62,9 @@ export function safeSliceF (str:string, total: number) {
|
||||
}
|
||||
|
||||
export function encodeFilePath (filePath: string) {
|
||||
filePath = filePath.replace(/\\/g, '/')
|
||||
const parts = filePath.split('/')
|
||||
return parts.map(encodeURIComponent).join('/')
|
||||
return filePath
|
||||
.replace(/\\/g, '/')
|
||||
.split('/')
|
||||
.map(encodeURIComponent)
|
||||
.join('/')
|
||||
}
|
||||
|
257
src/universal/utils/configPaths.ts
Normal file
257
src/universal/utils/configPaths.ts
Normal file
@ -0,0 +1,257 @@
|
||||
|
||||
import { II18nLanguage, IPasteStyle, ISartMode, IShortUrlServer } from '../types/enum'
|
||||
import { IBuildInCompressOptions, IBuildInWaterMarkOptions } from 'piclist'
|
||||
|
||||
export type ISartModeValues = typeof ISartMode[keyof typeof ISartMode]
|
||||
export type IPasteStyleValues = typeof IPasteStyle[keyof typeof IPasteStyle]
|
||||
export type II18nLanguageValues = typeof II18nLanguage[keyof typeof II18nLanguage]
|
||||
export type IShortUrlServerValues = typeof IShortUrlServer[keyof typeof IShortUrlServer]
|
||||
export type manualPageOpenType = 'window' | 'browser'
|
||||
|
||||
interface IPicGoPlugins {
|
||||
[key: `picgo-plugin-${string}`]: boolean
|
||||
}
|
||||
|
||||
export interface IConfigStruct {
|
||||
picBed: {
|
||||
uploader: string,
|
||||
current?: string,
|
||||
smms?: ISMMSConfig,
|
||||
qiniu?: IQiniuConfig,
|
||||
upyun?: IUpYunConfig
|
||||
tcyun?: ITcYunConfig
|
||||
github?: IGitHubConfig
|
||||
aliyun?: IAliYunConfig
|
||||
imgur?: IImgurConfig
|
||||
webdavplist?: IWebdavPlistConfig
|
||||
local?: ILocalConfig
|
||||
sftpplist?: ISftpPlistConfig
|
||||
telegraphplist?: ITelegraphConfig
|
||||
lskyplist?: ILskyConfig
|
||||
'aws-s3-plist': IAwsS3PListUserConfig
|
||||
proxy?: string
|
||||
transformer?: string
|
||||
list: IPicBedType[]
|
||||
[others: string]: any
|
||||
},
|
||||
settings: {
|
||||
shortKey: {
|
||||
[key: string]: IShortKeyConfig
|
||||
}
|
||||
logLevel: string[]
|
||||
logPath: string
|
||||
logFileSizeLimit: number
|
||||
isAutoListenClipboard: boolean
|
||||
isListeningClipboard: boolean
|
||||
showUpdateTip: boolean
|
||||
miniWindowPosition: [number, number]
|
||||
miniWindowOntop: boolean
|
||||
mainWindowWidth: number
|
||||
mainWindowHeight: number
|
||||
isHideDock: boolean
|
||||
autoCloseMiniWindow: boolean
|
||||
autoCloseMainWindow: boolean
|
||||
isCustomMiniIcon: boolean
|
||||
customMiniIcon: string
|
||||
startMode: ISartModeValues
|
||||
autoRename: boolean
|
||||
deleteCloudFile: boolean
|
||||
server: IServerConfig
|
||||
serverKey: string
|
||||
pasteStyle: IPasteStyleValues
|
||||
aesPassword: string
|
||||
rename: boolean
|
||||
sync: ISyncConfig
|
||||
tempDirPath: string
|
||||
language: II18nLanguageValues
|
||||
customLink: string
|
||||
manualPageOpen: manualPageOpenType
|
||||
encodeOutputURL: boolean
|
||||
useShortUrl: boolean
|
||||
shortUrlServer: IShortUrlServerValues
|
||||
c1nToken: string
|
||||
cfWorkerHost: string
|
||||
yourlsDomain: string
|
||||
yourlsSignature: string
|
||||
isSilentNotice: boolean
|
||||
proxy: string
|
||||
registry: string
|
||||
autoCopy: boolean
|
||||
enableWebServer: boolean
|
||||
webServerHost: string
|
||||
webServerPort: number
|
||||
webServerPath: string
|
||||
deleteLocalFile: boolean
|
||||
uploadResultNotification: boolean
|
||||
uploadNotification: boolean
|
||||
useBuiltinClipboard: boolean
|
||||
autoStart: boolean
|
||||
autoImport: boolean
|
||||
autoImportPicBed: string[]
|
||||
}
|
||||
needReload: boolean
|
||||
picgoPlugins: IPicGoPlugins
|
||||
uploader: IUploaderConfig
|
||||
buildIn: {
|
||||
compress: IBuildInCompressOptions
|
||||
waterMark: IBuildInWaterMarkOptions
|
||||
rename: {
|
||||
enable: boolean
|
||||
format: string
|
||||
}
|
||||
}
|
||||
debug: boolean
|
||||
PICGO_ENV: string
|
||||
}
|
||||
|
||||
interface IConfigPaths {
|
||||
picBed: {
|
||||
current: string
|
||||
uploader: string
|
||||
proxy: string
|
||||
transformer: string
|
||||
list: string
|
||||
},
|
||||
settings: {
|
||||
shortKey: {
|
||||
_path: string
|
||||
'picgo:upload': string
|
||||
}
|
||||
logLevel: string
|
||||
logPath: string
|
||||
logFileSizeLimit: string
|
||||
isAutoListenClipboard: string
|
||||
isListeningClipboard: string
|
||||
showUpdateTip: string
|
||||
miniWindowPosition: string
|
||||
miniWindowOntop: string
|
||||
isHideDock: string
|
||||
mainWindowWidth: string
|
||||
mainWindowHeight: string
|
||||
autoCloseMiniWindow: string
|
||||
autoCloseMainWindow: string
|
||||
isCustomMiniIcon: string
|
||||
customMiniIcon: string
|
||||
startMode: string
|
||||
autoRename: string
|
||||
deleteCloudFile: string
|
||||
server: string
|
||||
serverKey: string
|
||||
pasteStyle: string
|
||||
aesPassword: string
|
||||
rename: string
|
||||
sync: string
|
||||
tempDirPath: string
|
||||
language: string
|
||||
customLink: string
|
||||
manualPageOpen: string
|
||||
encodeOutputURL: string
|
||||
useShortUrl: string
|
||||
shortUrlServer: string
|
||||
c1nToken: string
|
||||
cfWorkerHost: string
|
||||
yourlsDomain: string
|
||||
yourlsSignature: string
|
||||
isSilentNotice: string
|
||||
proxy: string
|
||||
registry: string
|
||||
autoCopy: string
|
||||
enableWebServer: string
|
||||
webServerHost: string
|
||||
webServerPort: string
|
||||
webServerPath: string
|
||||
deleteLocalFile: string
|
||||
uploadResultNotification: string
|
||||
uploadNotification: string
|
||||
useBuiltinClipboard: string
|
||||
autoStart: string
|
||||
autoImport: string
|
||||
autoImportPicBed: string
|
||||
}
|
||||
needReload: string
|
||||
picgoPlugins: string
|
||||
uploader: string
|
||||
buildIn: {
|
||||
compress: string
|
||||
watermark: string
|
||||
rename: string
|
||||
}
|
||||
debug: string
|
||||
PICGO_ENV: string
|
||||
}
|
||||
|
||||
export const configPaths: IConfigPaths = {
|
||||
picBed: {
|
||||
current: 'picBed.current',
|
||||
uploader: 'picBed.uploader',
|
||||
proxy: 'picBed.proxy',
|
||||
transformer: 'picBed.transformer',
|
||||
list: 'picBed.list'
|
||||
},
|
||||
settings: {
|
||||
shortKey: {
|
||||
_path: 'settings.shortKey',
|
||||
'picgo:upload': 'settings.shortKey[picgo:upload]'
|
||||
},
|
||||
logLevel: 'settings.logLevel',
|
||||
logPath: 'settings.logPath',
|
||||
logFileSizeLimit: 'settings.logFileSizeLimit',
|
||||
isAutoListenClipboard: 'settings.isAutoListenClipboard',
|
||||
isListeningClipboard: 'settings.isListeningClipboard',
|
||||
showUpdateTip: 'settings.showUpdateTip',
|
||||
miniWindowPosition: 'settings.miniWindowPosition',
|
||||
miniWindowOntop: 'settings.miniWindowOntop',
|
||||
isHideDock: 'settings.isHideDock',
|
||||
mainWindowWidth: 'settings.mainWindowWidth',
|
||||
mainWindowHeight: 'settings.mainWindowHeight',
|
||||
autoCloseMiniWindow: 'settings.autoCloseMiniWindow',
|
||||
autoCloseMainWindow: 'settings.autoCloseMainWindow',
|
||||
isCustomMiniIcon: 'settings.isCustomMiniIcon',
|
||||
customMiniIcon: 'settings.customMiniIcon',
|
||||
startMode: 'settings.startMode',
|
||||
autoRename: 'settings.autoRename',
|
||||
deleteCloudFile: 'settings.deleteCloudFile',
|
||||
server: 'settings.server',
|
||||
serverKey: 'settings.serverKey',
|
||||
pasteStyle: 'settings.pasteStyle',
|
||||
aesPassword: 'settings.aesPassword',
|
||||
rename: 'settings.rename',
|
||||
sync: 'settings.sync',
|
||||
tempDirPath: 'settings.tempDirPath',
|
||||
language: 'settings.language',
|
||||
customLink: 'settings.customLink',
|
||||
manualPageOpen: 'settings.manualPageOpen',
|
||||
encodeOutputURL: 'settings.encodeOutputURL',
|
||||
useShortUrl: 'settings.useShortUrl',
|
||||
shortUrlServer: 'settings.shortUrlServer',
|
||||
c1nToken: 'settings.c1nToken',
|
||||
cfWorkerHost: 'settings.cfWorkerHost',
|
||||
yourlsDomain: 'settings.yourlsDomain',
|
||||
yourlsSignature: 'settings.yourlsSignature',
|
||||
isSilentNotice: 'settings.isSilentNotice',
|
||||
proxy: 'settings.proxy',
|
||||
registry: 'settings.registry',
|
||||
autoCopy: 'settings.autoCopy',
|
||||
enableWebServer: 'settings.enableWebServer',
|
||||
webServerHost: 'settings.webServerHost',
|
||||
webServerPort: 'settings.webServerPort',
|
||||
webServerPath: 'settings.webServerPath',
|
||||
deleteLocalFile: 'settings.deleteLocalFile',
|
||||
uploadResultNotification: 'settings.uploadResultNotification',
|
||||
uploadNotification: 'settings.uploadNotification',
|
||||
useBuiltinClipboard: 'settings.useBuiltinClipboard',
|
||||
autoStart: 'settings.autoStart',
|
||||
autoImport: 'settings.autoImport',
|
||||
autoImportPicBed: 'settings.autoImportPicBed'
|
||||
},
|
||||
needReload: 'needReload',
|
||||
picgoPlugins: 'picgoPlugins',
|
||||
uploader: 'uploader',
|
||||
buildIn: {
|
||||
compress: 'buildIn.compress',
|
||||
watermark: 'buildIn.waterMark',
|
||||
rename: 'buildIn.rename'
|
||||
},
|
||||
debug: 'debug',
|
||||
PICGO_ENV: 'PICGO_ENV'
|
||||
}
|
@ -22,3 +22,5 @@ export const picBedsCanbeDeleted = [
|
||||
'upyun',
|
||||
'webdavplist'
|
||||
]
|
||||
|
||||
export const DEFAULT_AES_PASSWORD = 'aesPassword'
|
||||
|
Loading…
Reference in New Issue
Block a user