mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-06-09 01:30:15 +08:00
🔨 Refactor(custom): add config file type
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user