mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-06-12 03:00:29 +08:00
✨ Feature: add /delete route for build in http server
This commit is contained in:
@@ -10,6 +10,9 @@ import db, { GalleryDB } from '~/main/apis/core/datastore'
|
||||
import { handleCopyUrl } from '~/main/utils/common'
|
||||
import { handleUrlEncode } from '#/utils/common'
|
||||
import { T } from '~/main/i18n/index'
|
||||
import ALLApi from '@/apis/allApi'
|
||||
import picgo from '@core/picgo'
|
||||
import GuiApi from '../../gui'
|
||||
|
||||
const handleClipboardUploading = async (): Promise<false | ImgInfo[]> => {
|
||||
const useBuiltinClipboard = !!db.get('settings.useBuiltinClipboard')
|
||||
@@ -20,7 +23,7 @@ const handleClipboardUploading = async (): Promise<false | ImgInfo[]> => {
|
||||
return await uploader.setWebContents(win!.webContents).upload()
|
||||
}
|
||||
|
||||
export const uploadClipboardFiles = async (): Promise<string> => {
|
||||
export const uploadClipboardFiles = async (): Promise<IStringKeyMap> => {
|
||||
const img = await handleClipboardUploading()
|
||||
console.log(img)
|
||||
if (img !== false) {
|
||||
@@ -43,21 +46,30 @@ export const uploadClipboardFiles = async (): Promise<string> => {
|
||||
if (windowManager.has(IWindowList.SETTING_WINDOW)) {
|
||||
windowManager.get(IWindowList.SETTING_WINDOW)!.webContents?.send('updateGallery')
|
||||
}
|
||||
return handleUrlEncode(img[0].imgUrl as string)
|
||||
return {
|
||||
url: handleUrlEncode(img[0].imgUrl as string),
|
||||
fullResult: img[0]
|
||||
}
|
||||
} else {
|
||||
const notification = new Notification({
|
||||
title: T('UPLOAD_FAILED'),
|
||||
body: T('TIPS_UPLOAD_NOT_PICTURES')
|
||||
})
|
||||
notification.show()
|
||||
return ''
|
||||
return {
|
||||
url: '',
|
||||
fullResult: {}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return ''
|
||||
return {
|
||||
url: '',
|
||||
fullResult: {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const uploadChoosedFiles = async (webContents: WebContents, files: IFileWithPath[]): Promise<string[]> => {
|
||||
export const uploadChoosedFiles = async (webContents: WebContents, files: IFileWithPath[]): Promise<IStringKeyMap[]> => {
|
||||
const input = files.map(item => item.path)
|
||||
const imgs = await uploader.setWebContents(webContents).upload(input)
|
||||
const result = []
|
||||
@@ -75,7 +87,10 @@ export const uploadChoosedFiles = async (webContents: WebContents, files: IFileW
|
||||
notification.show()
|
||||
}, i * 100)
|
||||
await GalleryDB.getInstance().insert(imgs[i])
|
||||
result.push(handleUrlEncode(imgs[i].imgUrl!))
|
||||
result.push({
|
||||
url: handleUrlEncode(imgs[i].imgUrl!),
|
||||
fullResult: imgs[i]
|
||||
})
|
||||
}
|
||||
handleCopyUrl(pasteText.join('\n'))
|
||||
// trayWindow just be created in mac/windows, not in linux
|
||||
@@ -88,3 +103,47 @@ export const uploadChoosedFiles = async (webContents: WebContents, files: IFileW
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
export const deleteChoosedFiles = async (list: ImgInfo[]): Promise<boolean[]> => {
|
||||
const result = []
|
||||
const picBedsCanbeDeleted = ['smms', 'github', 'imgur', 'tcyun', 'aliyun', 'qiniu', 'upyun', 'aws-s3', 'webdavplist']
|
||||
for (const item of list) {
|
||||
if (item.id) {
|
||||
try {
|
||||
const dbStore = GalleryDB.getInstance()
|
||||
const file = await dbStore.removeById(item.id)
|
||||
if (await picgo.getConfig('settings.deleteCloudFile')) {
|
||||
if (item.type !== undefined && picBedsCanbeDeleted.includes(item.type)) {
|
||||
setTimeout(() => {
|
||||
ALLApi.delete(item).then((value: boolean) => {
|
||||
if (value) {
|
||||
const notification = new Notification({
|
||||
title: T('MANAGE_BUCKET_BATCH_DELETE_ERROR_MSG_MSG2'),
|
||||
body: T('GALLERY_SYNC_DELETE_NOTICE_SUCCEED')
|
||||
})
|
||||
notification.show()
|
||||
} else {
|
||||
const notification = new Notification({
|
||||
title: T('MANAGE_BUCKET_BATCH_DELETE_ERROR_MSG_MSG2'),
|
||||
body: T('GALLERY_SYNC_DELETE_NOTICE_FAILED')
|
||||
})
|
||||
notification.show()
|
||||
}
|
||||
})
|
||||
}, 0)
|
||||
}
|
||||
}
|
||||
setTimeout(() => {
|
||||
picgo.emit('remove', [file], GuiApi.getInstance())
|
||||
}, 500)
|
||||
result.push(true)
|
||||
} catch (e) {
|
||||
result.push(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (windowManager.has(IWindowList.SETTING_WINDOW)) {
|
||||
windowManager.get(IWindowList.SETTING_WINDOW)!.webContents?.send('updateGallery')
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user