mirror of
https://github.com/Kuingsmile/PicList.git
synced 2025-02-02 02:58:13 -05:00
🐛 Fix: gallery db bug
This commit is contained in:
parent
6ddd660d89
commit
f1eb7f4d70
@ -34,7 +34,7 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@picgo/store": "^1.0.0-alpha.3",
|
"@picgo/store": "^1.0.3",
|
||||||
"axios": "^0.19.0",
|
"axios": "^0.19.0",
|
||||||
"core-js": "^3.3.2",
|
"core-js": "^3.3.2",
|
||||||
"element-ui": "^2.13.0",
|
"element-ui": "^2.13.0",
|
||||||
@ -43,7 +43,7 @@
|
|||||||
"keycode": "^2.2.0",
|
"keycode": "^2.2.0",
|
||||||
"lodash-id": "^0.14.0",
|
"lodash-id": "^0.14.0",
|
||||||
"lowdb": "^1.0.0",
|
"lowdb": "^1.0.0",
|
||||||
"picgo": "^1.4.21",
|
"picgo": "^1.4.23",
|
||||||
"qrcode.vue": "^1.7.0",
|
"qrcode.vue": "^1.7.0",
|
||||||
"uuidv4": "^6.2.11",
|
"uuidv4": "^6.2.11",
|
||||||
"vue": "^2.6.10",
|
"vue": "^2.6.10",
|
||||||
|
18
public/wsl.sh
Normal file
18
public/wsl.sh
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# grab the paths
|
||||||
|
scriptPath=$(echo $0 | awk '{ print substr( $0, 1, length($0)-6 ) }')"windows10.ps1"
|
||||||
|
imagePath=$(echo $1 | awk '{ print substr( $0, 1, length($0)-18 ) }')
|
||||||
|
imageName=$(echo $1 | awk '{ print substr( $0, length($0)-17, length($0) ) }')
|
||||||
|
|
||||||
|
# run the powershell script
|
||||||
|
res=$(powershell.exe -noprofile -noninteractive -nologo -sta -executionpolicy unrestricted -file $(wslpath -w $scriptPath) $(wslpath -w $imagePath)"\\"$imageName)
|
||||||
|
|
||||||
|
# note that there is a return symbol in powershell result
|
||||||
|
noImage=$(echo "no image\r")
|
||||||
|
|
||||||
|
# check whether image exists
|
||||||
|
if [ "$res" = "$noImage" ] ;then
|
||||||
|
echo "no image"
|
||||||
|
else
|
||||||
|
echo $(wslpath -u $res)
|
||||||
|
fi
|
@ -212,7 +212,7 @@ export function createTray () {
|
|||||||
if (imgs !== false) {
|
if (imgs !== false) {
|
||||||
const pasteText: string[] = []
|
const pasteText: string[] = []
|
||||||
for (let i = 0; i < imgs.length; i++) {
|
for (let i = 0; i < imgs.length; i++) {
|
||||||
pasteText.push(pasteTemplate(pasteStyle, imgs[i]))
|
pasteText.push(pasteTemplate(pasteStyle, imgs[i], db.get('settings.customLink')))
|
||||||
const notification = new Notification({
|
const notification = new Notification({
|
||||||
title: '上传成功',
|
title: '上传成功',
|
||||||
body: imgs[i].imgUrl!,
|
body: imgs[i].imgUrl!,
|
||||||
|
@ -16,7 +16,7 @@ export const uploadClipboardFiles = async (): Promise<string> => {
|
|||||||
if (img.length > 0) {
|
if (img.length > 0) {
|
||||||
const trayWindow = windowManager.get(IWindowList.TRAY_WINDOW)
|
const trayWindow = windowManager.get(IWindowList.TRAY_WINDOW)
|
||||||
const pasteStyle = db.get('settings.pasteStyle') || 'markdown'
|
const pasteStyle = db.get('settings.pasteStyle') || 'markdown'
|
||||||
handleCopyUrl(pasteTemplate(pasteStyle, img[0]))
|
handleCopyUrl(pasteTemplate(pasteStyle, img[0], db.get('settings.customLink')))
|
||||||
const notification = new Notification({
|
const notification = new Notification({
|
||||||
title: '上传成功',
|
title: '上传成功',
|
||||||
body: img[0].imgUrl!,
|
body: img[0].imgUrl!,
|
||||||
@ -52,7 +52,7 @@ export const uploadChoosedFiles = async (webContents: WebContents, files: IFileW
|
|||||||
const pasteStyle = db.get('settings.pasteStyle') || 'markdown'
|
const pasteStyle = db.get('settings.pasteStyle') || 'markdown'
|
||||||
const pasteText: string[] = []
|
const pasteText: string[] = []
|
||||||
for (let i = 0; i < imgs.length; i++) {
|
for (let i = 0; i < imgs.length; i++) {
|
||||||
pasteText.push(pasteTemplate(pasteStyle, imgs[i]))
|
pasteText.push(pasteTemplate(pasteStyle, imgs[i], db.get('settings.customLink')))
|
||||||
const notification = new Notification({
|
const notification = new Notification({
|
||||||
title: '上传成功',
|
title: '上传成功',
|
||||||
body: imgs[i].imgUrl!,
|
body: imgs[i].imgUrl!,
|
||||||
|
@ -81,6 +81,8 @@ function dbPathChecker (): string {
|
|||||||
return defaultConfigPath
|
return defaultConfigPath
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const defaultConfigPath = configFilePath
|
||||||
|
|
||||||
export {
|
export {
|
||||||
dbChecker,
|
dbChecker,
|
||||||
dbPathChecker
|
dbPathChecker
|
||||||
|
@ -4,7 +4,9 @@ import {
|
|||||||
Notification,
|
Notification,
|
||||||
ipcMain
|
ipcMain
|
||||||
} from 'electron'
|
} from 'electron'
|
||||||
import db, { GalleryDB } from '~/main/apis/core/datastore'
|
import path from 'path'
|
||||||
|
import db, { GalleryDB } from 'apis/core/datastore'
|
||||||
|
import { dbPathChecker, defaultConfigPath } from 'apis/core/datastore/dbChecker'
|
||||||
import uploader from 'apis/app/uploader'
|
import uploader from 'apis/app/uploader'
|
||||||
import pasteTemplate from '#/utils/pasteTemplate'
|
import pasteTemplate from '#/utils/pasteTemplate'
|
||||||
import { handleCopyUrl } from '~/main/utils/common'
|
import { handleCopyUrl } from '~/main/utils/common'
|
||||||
@ -15,6 +17,8 @@ import {
|
|||||||
import {
|
import {
|
||||||
SHOW_INPUT_BOX
|
SHOW_INPUT_BOX
|
||||||
} from '~/universal/events/constants'
|
} from '~/universal/events/constants'
|
||||||
|
import { DBStore } from '@picgo/store'
|
||||||
|
type PromiseResType<T> = T extends Promise<infer R> ? R : T
|
||||||
|
|
||||||
// Cross-process support may be required in the future
|
// Cross-process support may be required in the future
|
||||||
class GuiApi implements IGuiApi {
|
class GuiApi implements IGuiApi {
|
||||||
@ -79,7 +83,7 @@ class GuiApi implements IGuiApi {
|
|||||||
const pasteStyle = db.get('settings.pasteStyle') || 'markdown'
|
const pasteStyle = db.get('settings.pasteStyle') || 'markdown'
|
||||||
const pasteText: string[] = []
|
const pasteText: string[] = []
|
||||||
for (let i = 0; i < imgs.length; i++) {
|
for (let i = 0; i < imgs.length; i++) {
|
||||||
pasteText.push(pasteTemplate(pasteStyle, imgs[i]))
|
pasteText.push(pasteTemplate(pasteStyle, imgs[i], db.get('settings.customLink')))
|
||||||
const notification = new Notification({
|
const notification = new Notification({
|
||||||
title: '上传成功',
|
title: '上传成功',
|
||||||
body: imgs[i].imgUrl as string,
|
body: imgs[i].imgUrl as string,
|
||||||
@ -128,6 +132,44 @@ class GuiApi implements IGuiApi {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get picgo config/data path
|
||||||
|
*/
|
||||||
|
async getConfigPath () {
|
||||||
|
const currentConfigPath = dbPathChecker()
|
||||||
|
const galleryDBPath = path.join(path.dirname(currentConfigPath), 'picgo.db')
|
||||||
|
return {
|
||||||
|
defaultConfigPath,
|
||||||
|
currentConfigPath,
|
||||||
|
galleryDBPath
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
get galleryDB (): DBStore {
|
||||||
|
return new Proxy<DBStore>(GalleryDB.getInstance(), {
|
||||||
|
get (target, prop: keyof DBStore) {
|
||||||
|
if (prop === 'removeById') {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
const guiApi = GuiApi.getInstance()
|
||||||
|
guiApi.showMessageBox({
|
||||||
|
title: '警告',
|
||||||
|
message: '有插件正在试图删除一些相册文件,是否继续',
|
||||||
|
type: 'info',
|
||||||
|
buttons: ['Yes', 'No']
|
||||||
|
}).then(res => {
|
||||||
|
if (res.result === 0) {
|
||||||
|
resolve(Reflect.get(target, prop))
|
||||||
|
} else {
|
||||||
|
resolve(() => {})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return Reflect.get(target, prop)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default GuiApi
|
export default GuiApi
|
||||||
|
@ -32,7 +32,7 @@ export default {
|
|||||||
const img = await uploader.setWebContents(trayWindow.webContents).upload()
|
const img = await uploader.setWebContents(trayWindow.webContents).upload()
|
||||||
if (img !== false) {
|
if (img !== false) {
|
||||||
const pasteStyle = db.get('settings.pasteStyle') || 'markdown'
|
const pasteStyle = db.get('settings.pasteStyle') || 'markdown'
|
||||||
handleCopyUrl(pasteTemplate(pasteStyle, img[0]))
|
handleCopyUrl(pasteTemplate(pasteStyle, img[0], db.get('settings.customLink')))
|
||||||
const notification = new Notification({
|
const notification = new Notification({
|
||||||
title: '上传成功',
|
title: '上传成功',
|
||||||
body: img[0].imgUrl!,
|
body: img[0].imgUrl!,
|
||||||
|
@ -28,7 +28,7 @@ import {
|
|||||||
} from '#/events/constants'
|
} from '#/events/constants'
|
||||||
|
|
||||||
import { GalleryDB } from 'apis/core/datastore'
|
import { GalleryDB } from 'apis/core/datastore'
|
||||||
import { IObject } from '@picgo/store/dist/types'
|
import { IObject, IFilter } from '@picgo/store/dist/types'
|
||||||
|
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
const requireFunc = typeof __webpack_require__ === 'function' ? __non_webpack_require__ : require
|
const requireFunc = typeof __webpack_require__ === 'function' ? __non_webpack_require__ : require
|
||||||
@ -283,10 +283,10 @@ const handleImportLocalPlugin = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handlePicGoGalleryDB = () => {
|
const handlePicGoGalleryDB = () => {
|
||||||
ipcMain.on(PICGO_GET_DB, async (event: IpcMainEvent, callbackId: string) => {
|
ipcMain.on(PICGO_GET_DB, async (event: IpcMainEvent, filter: IFilter, callbackId: string) => {
|
||||||
const dbStore = GalleryDB.getInstance()
|
const dbStore = GalleryDB.getInstance()
|
||||||
const res = await dbStore.get()
|
const res = await dbStore.get(filter)
|
||||||
event.sender.send(PICGO_GET_CONFIG, res, callbackId)
|
event.sender.send(PICGO_GET_DB, res, callbackId)
|
||||||
})
|
})
|
||||||
|
|
||||||
ipcMain.on(PICGO_INSERT_DB, async (event: IpcMainEvent, value: IObject, callbackId: string) => {
|
ipcMain.on(PICGO_INSERT_DB, async (event: IpcMainEvent, value: IObject, callbackId: string) => {
|
||||||
|
@ -55,7 +55,7 @@ const handleStartUpFiles = (argv: string[], cwd: string) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class LifeCycle {
|
class LifeCycle {
|
||||||
private async beforeReady () {
|
private beforeReady () {
|
||||||
protocol.registerSchemesAsPrivileged([{ scheme: 'picgo', privileges: { secure: true, standard: true } }])
|
protocol.registerSchemesAsPrivileged([{ scheme: 'picgo', privileges: { secure: true, standard: true } }])
|
||||||
// fix the $PATH in macOS
|
// fix the $PATH in macOS
|
||||||
fixPath()
|
fixPath()
|
||||||
@ -63,10 +63,11 @@ class LifeCycle {
|
|||||||
ipcList.listen()
|
ipcList.listen()
|
||||||
busEventList.listen()
|
busEventList.listen()
|
||||||
updateShortKeyFromVersion212(db, db.get('settings.shortKey'))
|
updateShortKeyFromVersion212(db, db.get('settings.shortKey'))
|
||||||
await migrateGalleryFromVersion230(db, GalleryDB.getInstance())
|
|
||||||
}
|
}
|
||||||
private onReady () {
|
private onReady () {
|
||||||
app.on('ready', async () => {
|
app.on('ready', async () => {
|
||||||
|
console.log('on ready')
|
||||||
|
await migrateGalleryFromVersion230(db, GalleryDB.getInstance())
|
||||||
createProtocol('picgo')
|
createProtocol('picgo')
|
||||||
if (isDevelopment && !process.env.IS_TEST) {
|
if (isDevelopment && !process.env.IS_TEST) {
|
||||||
// Install Vue Devtools
|
// Install Vue Devtools
|
||||||
@ -169,7 +170,7 @@ class LifeCycle {
|
|||||||
if (!gotTheLock) {
|
if (!gotTheLock) {
|
||||||
app.quit()
|
app.quit()
|
||||||
} else {
|
} else {
|
||||||
await this.beforeReady()
|
this.beforeReady()
|
||||||
this.onReady()
|
this.onReady()
|
||||||
this.onRunning()
|
this.onRunning()
|
||||||
this.onQuit()
|
this.onQuit()
|
||||||
|
@ -38,10 +38,11 @@ const migrateGalleryFromVersion230 = async (configDB: typeof ConfigStore, galler
|
|||||||
if (fse.existsSync(configBakPath)) {
|
if (fse.existsSync(configBakPath)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fse.copyFileSync(configPath, configBakPath)
|
|
||||||
// migrate gallery from config to gallery db
|
// migrate gallery from config to gallery db
|
||||||
if (originGallery && originGallery.length > 0) {
|
if (originGallery && originGallery?.length > 0) {
|
||||||
|
fse.copyFileSync(configPath, configBakPath)
|
||||||
await galleryDB.insertMany(originGallery)
|
await galleryDB.insertMany(originGallery)
|
||||||
|
configDB.set('uploaded', [])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,6 +103,7 @@ class Server {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
startup () {
|
startup () {
|
||||||
|
console.log('startup', this.config.enable)
|
||||||
if (this.config.enable) {
|
if (this.config.enable) {
|
||||||
this.listen(this.config.port)
|
this.listen(this.config.port)
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import fs from 'fs-extra'
|
import fs from 'fs-extra'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
import os from 'os'
|
import os from 'os'
|
||||||
import { remote, app } from 'electron'
|
|
||||||
import pkg from 'root/package.json'
|
import pkg from 'root/package.json'
|
||||||
|
import { dbPathChecker } from 'apis/core/datastore/dbChecker'
|
||||||
|
|
||||||
const APP = process.type === 'renderer' ? remote.app : app
|
const configPath = dbPathChecker()
|
||||||
const STORE_PATH = APP.getPath('userData')
|
const CONFIG_DIR = path.dirname(configPath)
|
||||||
|
|
||||||
function injectPicGoVersion () {
|
function injectPicGoVersion () {
|
||||||
global.PICGO_GUI_VERSION = pkg.version
|
global.PICGO_GUI_VERSION = pkg.version
|
||||||
@ -41,7 +41,7 @@ function resolveMacWorkFlow () {
|
|||||||
*/
|
*/
|
||||||
function resolveClipboardImageGenerator () {
|
function resolveClipboardImageGenerator () {
|
||||||
let clipboardFiles = getClipboardFiles()
|
let clipboardFiles = getClipboardFiles()
|
||||||
if (!fs.pathExistsSync(path.join(STORE_PATH, 'windows10.ps1'))) {
|
if (!fs.pathExistsSync(path.join(CONFIG_DIR, 'windows10.ps1'))) {
|
||||||
clipboardFiles.forEach(item => {
|
clipboardFiles.forEach(item => {
|
||||||
fs.copyFileSync(item.origin, item.dest)
|
fs.copyFileSync(item.origin, item.dest)
|
||||||
})
|
})
|
||||||
@ -52,10 +52,15 @@ function resolveClipboardImageGenerator () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function diffFilesAndUpdate (filePath1: string, filePath2: string) {
|
function diffFilesAndUpdate (filePath1: string, filePath2: string) {
|
||||||
let file1 = fs.readFileSync(filePath1)
|
try {
|
||||||
let file2 = fs.readFileSync(filePath2)
|
let file1 = fs.existsSync(filePath1) && fs.readFileSync(filePath1)
|
||||||
|
let file2 = fs.existsSync(filePath1) && fs.readFileSync(filePath2)
|
||||||
|
|
||||||
if (!file1.equals(file2)) {
|
if (!file1 || !file2 || !file1.equals(file2)) {
|
||||||
|
fs.copyFileSync(filePath1, filePath2)
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e)
|
||||||
fs.copyFileSync(filePath1, filePath2)
|
fs.copyFileSync(filePath1, filePath2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -65,13 +70,14 @@ function resolveClipboardImageGenerator () {
|
|||||||
'/linux.sh',
|
'/linux.sh',
|
||||||
'/mac.applescript',
|
'/mac.applescript',
|
||||||
'/windows.ps1',
|
'/windows.ps1',
|
||||||
'/windows10.ps1'
|
'/windows10.ps1',
|
||||||
|
'/wsl.sh'
|
||||||
]
|
]
|
||||||
|
|
||||||
return files.map(item => {
|
return files.map(item => {
|
||||||
return {
|
return {
|
||||||
origin: path.join(__static, item),
|
origin: path.join(__static, item),
|
||||||
dest: path.join(STORE_PATH, item)
|
dest: path.join(CONFIG_DIR, item)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -71,12 +71,12 @@
|
|||||||
<el-col :span="20" :offset="2">
|
<el-col :span="20" :offset="2">
|
||||||
<el-row :gutter="16">
|
<el-row :gutter="16">
|
||||||
<gallerys
|
<gallerys
|
||||||
:images="images"
|
:images="filterList"
|
||||||
:index="idx"
|
:index="idx"
|
||||||
@close="handleClose"
|
@close="handleClose"
|
||||||
:options="options"
|
:options="options"
|
||||||
></gallerys>
|
></gallerys>
|
||||||
<el-col :span="6" v-for="(item, index) in images" :key="item.id" class="gallery-list__img">
|
<el-col :span="6" v-for="(item, index) in filterList" :key="item.id" class="gallery-list__img">
|
||||||
<div
|
<div
|
||||||
class="gallery-list__item"
|
class="gallery-list__item"
|
||||||
@click="zoomImage(index)"
|
@click="zoomImage(index)"
|
||||||
@ -162,12 +162,12 @@ export default class extends Vue {
|
|||||||
async created () {
|
async created () {
|
||||||
ipcRenderer.on('updateGallery', (event: IpcRendererEvent) => {
|
ipcRenderer.on('updateGallery', (event: IpcRendererEvent) => {
|
||||||
this.$nextTick(async () => {
|
this.$nextTick(async () => {
|
||||||
this.images = await this.$$db.get()
|
this.updateGallery()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
ipcRenderer.send('getPicBeds')
|
ipcRenderer.send('getPicBeds')
|
||||||
ipcRenderer.on('getPicBeds', this.getPicBeds)
|
ipcRenderer.on('getPicBeds', this.getPicBeds)
|
||||||
this.images = await this.$$db.get()
|
this.updateGallery()
|
||||||
}
|
}
|
||||||
mounted () {
|
mounted () {
|
||||||
document.addEventListener('keydown', this.handleDetectShiftKey)
|
document.addEventListener('keydown', this.handleDetectShiftKey)
|
||||||
@ -212,6 +212,9 @@ export default class extends Vue {
|
|||||||
return this.images
|
return this.images
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
async updateGallery () {
|
||||||
|
this.images = (await this.$$db.get({ orderBy: 'desc' })).data
|
||||||
|
}
|
||||||
|
|
||||||
@Watch('filterList')
|
@Watch('filterList')
|
||||||
handleFilterListChange () {
|
handleFilterListChange () {
|
||||||
@ -257,7 +260,8 @@ export default class extends Vue {
|
|||||||
}
|
}
|
||||||
async copy (item: ImgInfo) {
|
async copy (item: ImgInfo) {
|
||||||
const style = await this.getConfig<IPasteStyle>('settings.pasteStyle') || IPasteStyle.MARKDOWN
|
const style = await this.getConfig<IPasteStyle>('settings.pasteStyle') || IPasteStyle.MARKDOWN
|
||||||
const copyLink = pasteStyle(style, item)
|
const customLink = await this.getConfig<string>('settings.customLink')
|
||||||
|
const copyLink = pasteStyle(style, item, customLink)
|
||||||
const obj = {
|
const obj = {
|
||||||
title: '复制链接成功',
|
title: '复制链接成功',
|
||||||
body: copyLink,
|
body: copyLink,
|
||||||
@ -286,7 +290,7 @@ export default class extends Vue {
|
|||||||
myNotification.onclick = () => {
|
myNotification.onclick = () => {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
this.getGallery()
|
this.updateGallery()
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
console.log(e)
|
console.log(e)
|
||||||
return true
|
return true
|
||||||
@ -311,7 +315,7 @@ export default class extends Vue {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
this.dialogVisible = false
|
this.dialogVisible = false
|
||||||
this.getGallery()
|
this.updateGallery()
|
||||||
}
|
}
|
||||||
choosePicBed (type: string) {
|
choosePicBed (type: string) {
|
||||||
let idx = this.choosedPicBed.indexOf(type)
|
let idx = this.choosedPicBed.indexOf(type)
|
||||||
@ -356,7 +360,6 @@ export default class extends Vue {
|
|||||||
}
|
}
|
||||||
this.clearChoosedList()
|
this.clearChoosedList()
|
||||||
this.choosedList = {} // 只有删除才能将这个置空
|
this.choosedList = {} // 只有删除才能将这个置空
|
||||||
this.getGallery()
|
|
||||||
const obj = {
|
const obj = {
|
||||||
title: '操作结果',
|
title: '操作结果',
|
||||||
body: '删除成功'
|
body: '删除成功'
|
||||||
@ -366,6 +369,7 @@ export default class extends Vue {
|
|||||||
myNotification.onclick = () => {
|
myNotification.onclick = () => {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
this.updateGallery()
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
@ -375,6 +379,7 @@ export default class extends Vue {
|
|||||||
if (Object.values(this.choosedList).some(item => item)) {
|
if (Object.values(this.choosedList).some(item => item)) {
|
||||||
const copyString: string[] = []
|
const copyString: string[] = []
|
||||||
const style = await this.getConfig<IPasteStyle>('settings.pasteStyle') || IPasteStyle.MARKDOWN
|
const style = await this.getConfig<IPasteStyle>('settings.pasteStyle') || IPasteStyle.MARKDOWN
|
||||||
|
const customLink = await this.getConfig<string>('settings.customLink')
|
||||||
// choosedList -> { [id]: true or false }; true means choosed. false means not choosed.
|
// choosedList -> { [id]: true or false }; true means choosed. false means not choosed.
|
||||||
const imageIDList = Object.keys(this.choosedList)
|
const imageIDList = Object.keys(this.choosedList)
|
||||||
for (let i = 0; i < imageIDList.length; i++) {
|
for (let i = 0; i < imageIDList.length; i++) {
|
||||||
@ -382,7 +387,7 @@ export default class extends Vue {
|
|||||||
if (this.choosedList[key]) {
|
if (this.choosedList[key]) {
|
||||||
const item = await this.$$db.getById<ImgInfo>(key)
|
const item = await this.$$db.getById<ImgInfo>(key)
|
||||||
if (item) {
|
if (item) {
|
||||||
copyString.push(pasteStyle(style, item))
|
copyString.push(pasteStyle(style, item, customLink))
|
||||||
this.choosedList[key] = false
|
this.choosedList[key] = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,14 +50,15 @@ export default class extends Vue {
|
|||||||
return this.files.slice().reverse()
|
return this.files.slice().reverse()
|
||||||
}
|
}
|
||||||
async getData () {
|
async getData () {
|
||||||
this.files = (await this.$$db.get<ImgInfo>()).slice().reverse().slice(0, 5)
|
this.files = (await this.$$db.get<ImgInfo>({ orderBy: 'desc', limit: 5 })).data
|
||||||
}
|
}
|
||||||
async copyTheLink (item: ImgInfo) {
|
async copyTheLink (item: ImgInfo) {
|
||||||
this.notification.body = item.imgUrl!
|
this.notification.body = item.imgUrl!
|
||||||
this.notification.icon = item.imgUrl!
|
this.notification.icon = item.imgUrl!
|
||||||
const myNotification = new Notification(this.notification.title, this.notification)
|
const myNotification = new Notification(this.notification.title, this.notification)
|
||||||
const pasteStyle = await this.getConfig<IPasteStyle>('settings.pasteStyle') || IPasteStyle.MARKDOWN
|
const pasteStyle = await this.getConfig<IPasteStyle>('settings.pasteStyle') || IPasteStyle.MARKDOWN
|
||||||
clipboard.writeText(pasteTemplate(pasteStyle, item))
|
const customLink = await this.getConfig<string>('settings.customLink')
|
||||||
|
clipboard.writeText(pasteTemplate(pasteStyle, item, customLink))
|
||||||
myNotification.onclick = () => {
|
myNotification.onclick = () => {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -90,13 +91,13 @@ export default class extends Vue {
|
|||||||
const item = files[i]
|
const item = files[i]
|
||||||
await this.$$db.insert(item)
|
await this.$$db.insert(item)
|
||||||
}
|
}
|
||||||
this.files = (await this.$$db.get<ImgInfo>()).slice().reverse().slice(0, 5)
|
this.files = (await this.$$db.get<ImgInfo>({ orderBy: 'desc', limit: 5 })).data
|
||||||
})
|
})
|
||||||
ipcRenderer.on('clipboardFiles', (event: Event, files: ImgInfo[]) => {
|
ipcRenderer.on('clipboardFiles', (event: Event, files: ImgInfo[]) => {
|
||||||
this.clipboardFiles = files
|
this.clipboardFiles = files
|
||||||
})
|
})
|
||||||
ipcRenderer.on('uploadFiles', async (event: Event) => {
|
ipcRenderer.on('uploadFiles', async (event: Event) => {
|
||||||
this.files = (await this.$$db.get()).slice().reverse().slice(0, 5)
|
this.files = (await this.$$db.get<ImgInfo>({ orderBy: 'desc', limit: 5 })).data
|
||||||
console.log(this.files)
|
console.log(this.files)
|
||||||
this.uploadFlag = false
|
this.uploadFlag = false
|
||||||
})
|
})
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { IObject, IResult } from '@picgo/store/dist/types'
|
import { IObject, IResult, IGetResult, IFilter } from '@picgo/store/dist/types'
|
||||||
import { ipcRenderer, IpcRendererEvent } from 'electron'
|
import { ipcRenderer, IpcRendererEvent } from 'electron'
|
||||||
import { uuid } from 'uuidv4'
|
import { uuid } from 'uuidv4'
|
||||||
import {
|
import {
|
||||||
@ -11,8 +11,8 @@ import {
|
|||||||
} from '#/events/constants'
|
} from '#/events/constants'
|
||||||
import { IGalleryDB } from '#/types/extra-vue'
|
import { IGalleryDB } from '#/types/extra-vue'
|
||||||
export class GalleryDB implements IGalleryDB {
|
export class GalleryDB implements IGalleryDB {
|
||||||
async get<T> (): Promise<IResult<T>[]> {
|
async get<T> (filter?: IFilter): Promise<IGetResult<T>> {
|
||||||
const res = await this.msgHandler<IResult<T>[]>(PICGO_GET_DB)
|
const res = await this.msgHandler<IGetResult<T>>(PICGO_GET_DB, filter)
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
async insert<T> (value: T): Promise<IResult<T>> {
|
async insert<T> (value: T): Promise<IResult<T>> {
|
||||||
|
4
src/universal/types/extra-vue.d.ts
vendored
4
src/universal/types/extra-vue.d.ts
vendored
@ -1,9 +1,9 @@
|
|||||||
import VueRouter, { Route } from 'vue-router'
|
import VueRouter, { Route } from 'vue-router'
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import { IObject, IResult } from '@picgo/store/dist/types'
|
import { IObject, IResult, IGetResult, IFilter } from '@picgo/store/dist/types'
|
||||||
|
|
||||||
interface IGalleryDB {
|
interface IGalleryDB {
|
||||||
get<T>(): Promise<IResult<T>[]>
|
get<T>(filter?: IFilter): Promise<IGetResult<T>>
|
||||||
insert<T> (value: T): Promise<IResult<T>>
|
insert<T> (value: T): Promise<IResult<T>>
|
||||||
insertMany<T> (value: T[]): Promise<IResult<T>[]>
|
insertMany<T> (value: T[]): Promise<IResult<T>[]>
|
||||||
updateById (id: string, value: IObject): Promise<boolean>
|
updateById (id: string, value: IObject): Promise<boolean>
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import db from '~/main/apis/core/datastore'
|
|
||||||
import { IPasteStyle } from '#/types/enum'
|
import { IPasteStyle } from '#/types/enum'
|
||||||
import { handleUrlEncode } from './common'
|
import { handleUrlEncode } from './common'
|
||||||
|
|
||||||
@ -19,15 +18,15 @@ const formatCustomLink = (customLink: string, item: ImgInfo) => {
|
|||||||
return customLink
|
return customLink
|
||||||
}
|
}
|
||||||
|
|
||||||
export default (style: IPasteStyle, item: ImgInfo) => {
|
export default (style: IPasteStyle, item: ImgInfo, customLink: string | undefined) => {
|
||||||
const url = handleUrlEncode(item.url || item.imgUrl)
|
const url = handleUrlEncode(item.url || item.imgUrl)
|
||||||
const customLink = db.get('settings.customLink') || '$url'
|
const _customLink = customLink || '$url'
|
||||||
const tpl = {
|
const tpl = {
|
||||||
'markdown': `![](${url})`,
|
'markdown': `![](${url})`,
|
||||||
'HTML': `<img src="${url}"/>`,
|
'HTML': `<img src="${url}"/>`,
|
||||||
'URL': url,
|
'URL': url,
|
||||||
'UBB': `[IMG]${url}[/IMG]`,
|
'UBB': `[IMG]${url}[/IMG]`,
|
||||||
'Custom': formatCustomLink(customLink, item)
|
'Custom': formatCustomLink(_customLink, item)
|
||||||
}
|
}
|
||||||
return tpl[style]
|
return tpl[style]
|
||||||
}
|
}
|
||||||
|
29
yarn.lock
29
yarn.lock
@ -918,10 +918,10 @@
|
|||||||
dependencies:
|
dependencies:
|
||||||
ora "^3.4.0"
|
ora "^3.4.0"
|
||||||
|
|
||||||
"@picgo/store@^1.0.0-alpha.3":
|
"@picgo/store@^1.0.3":
|
||||||
version "1.0.0-alpha.3"
|
version "1.0.3"
|
||||||
resolved "https://registry.yarnpkg.com/@picgo/store/-/store-1.0.0-alpha.3.tgz#b0f4f12c471cf370a95dcab93ed2b6291760d887"
|
resolved "https://registry.yarnpkg.com/@picgo/store/-/store-1.0.3.tgz#cfe346ad30c80f378e0bc81311e7468df436bc1f"
|
||||||
integrity sha512-BUj/lZiAWDu7gZRwRtPIfw7LwV55PD/dUkAjPsscjn/EmckiC3LEek97/wr4j6vQc45C7LEJfgpzeEYSU76vUA==
|
integrity sha512-quyu56yuUsFFJGQ88suTwUSEzKosZPzR1M52eyqzyQ2HZWZVn0pa/eBBsh7OYefS0V13YLR5llnIkQaL8y11Ww==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@types/bson" "^4.0.1"
|
"@types/bson" "^4.0.1"
|
||||||
"@types/graceful-fs" "^4.1.3"
|
"@types/graceful-fs" "^4.1.3"
|
||||||
@ -6430,6 +6430,11 @@ is-directory@^0.3.1:
|
|||||||
resolved "https://registry.yarnpkg.com/is-directory/-/is-directory-0.3.1.tgz#61339b6f2475fc772fd9c9d83f5c8575dc154ae1"
|
resolved "https://registry.yarnpkg.com/is-directory/-/is-directory-0.3.1.tgz#61339b6f2475fc772fd9c9d83f5c8575dc154ae1"
|
||||||
integrity sha1-YTObbyR1/Hcv2cnYP1yFddwVSuE=
|
integrity sha1-YTObbyR1/Hcv2cnYP1yFddwVSuE=
|
||||||
|
|
||||||
|
is-docker@^2.0.0:
|
||||||
|
version "2.2.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/is-docker/-/is-docker-2.2.1.tgz#33eeabe23cfe86f14bde4408a02c0cfb853acdaa"
|
||||||
|
integrity sha512-F+i2BKsFrH66iaUFc0woD8sLy8getkwTwtOBjvs56Cx4CgJDeKQeqfz8wAYiSb8JOprWhHH5p77PbmYCvvUuXQ==
|
||||||
|
|
||||||
is-extendable@^0.1.0, is-extendable@^0.1.1:
|
is-extendable@^0.1.0, is-extendable@^0.1.1:
|
||||||
version "0.1.1"
|
version "0.1.1"
|
||||||
resolved "https://registry.yarnpkg.com/is-extendable/-/is-extendable-0.1.1.tgz#62b110e289a471418e3ec36a617d472e301dfc89"
|
resolved "https://registry.yarnpkg.com/is-extendable/-/is-extendable-0.1.1.tgz#62b110e289a471418e3ec36a617d472e301dfc89"
|
||||||
@ -6641,6 +6646,13 @@ is-wsl@^1.1.0:
|
|||||||
resolved "https://registry.yarnpkg.com/is-wsl/-/is-wsl-1.1.0.tgz#1f16e4aa22b04d1336b66188a66af3c600c3a66d"
|
resolved "https://registry.yarnpkg.com/is-wsl/-/is-wsl-1.1.0.tgz#1f16e4aa22b04d1336b66188a66af3c600c3a66d"
|
||||||
integrity sha1-HxbkqiKwTRM2tmGIpmrzxgDDpm0=
|
integrity sha1-HxbkqiKwTRM2tmGIpmrzxgDDpm0=
|
||||||
|
|
||||||
|
is-wsl@^2.2.0:
|
||||||
|
version "2.2.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/is-wsl/-/is-wsl-2.2.0.tgz#74a4c76e77ca9fd3f932f290c17ea326cd157271"
|
||||||
|
integrity sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww==
|
||||||
|
dependencies:
|
||||||
|
is-docker "^2.0.0"
|
||||||
|
|
||||||
is-yarn-global@^0.3.0:
|
is-yarn-global@^0.3.0:
|
||||||
version "0.3.0"
|
version "0.3.0"
|
||||||
resolved "https://registry.yarnpkg.com/is-yarn-global/-/is-yarn-global-0.3.0.tgz#d502d3382590ea3004893746754c89139973e232"
|
resolved "https://registry.yarnpkg.com/is-yarn-global/-/is-yarn-global-0.3.0.tgz#d502d3382590ea3004893746754c89139973e232"
|
||||||
@ -8378,10 +8390,10 @@ performance-now@^2.1.0:
|
|||||||
resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b"
|
resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b"
|
||||||
integrity sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=
|
integrity sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=
|
||||||
|
|
||||||
picgo@^1.4.21:
|
picgo@^1.4.23:
|
||||||
version "1.4.21"
|
version "1.4.23"
|
||||||
resolved "https://registry.yarnpkg.com/picgo/-/picgo-1.4.21.tgz#5ebbacda85200d63f5f83128b1c1b37c10cd80f3"
|
resolved "https://registry.yarnpkg.com/picgo/-/picgo-1.4.23.tgz#01232185a3c4cbf4972d9924a5968dd0f9726d04"
|
||||||
integrity sha512-WxPVNbWa2LPFfPftRvdFqf1fwUn6TrBn2vm12hSMHUjhdU+7nK3uysBfL5R9/vOAk+OPt3bU74zRHYi6gME+Dw==
|
integrity sha512-/QCbiye7Trw+hXGU67YYb2tOiBy/BoGn7bI2vOHejHlwRFQuKQxLXYHK97sRSlSCWubTFSv9QNrvXz6/jTr69A==
|
||||||
dependencies:
|
dependencies:
|
||||||
chalk "^2.4.1"
|
chalk "^2.4.1"
|
||||||
commander "^2.17.0"
|
commander "^2.17.0"
|
||||||
@ -8394,6 +8406,7 @@ picgo@^1.4.21:
|
|||||||
globby "^8.0.2"
|
globby "^8.0.2"
|
||||||
image-size "^0.8.3"
|
image-size "^0.8.3"
|
||||||
inquirer "^6.0.0"
|
inquirer "^6.0.0"
|
||||||
|
is-wsl "^2.2.0"
|
||||||
lodash-id "^0.14.0"
|
lodash-id "^0.14.0"
|
||||||
lowdb "^1.0.0"
|
lowdb "^1.0.0"
|
||||||
md5 "^2.2.1"
|
md5 "^2.2.1"
|
||||||
|
Loading…
Reference in New Issue
Block a user