mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-05-31 09:09:38 +08:00
✨ Feature: add delete local file after uploading, fix compatibility with auto-delete
ISSUES CLOSED: #40
This commit is contained in:
@@ -23,6 +23,7 @@ import clipboardListener from 'clipboard-event'
|
||||
import clipboardPoll from '~/main/utils/clipboardPoll'
|
||||
import picgo from '../../core/picgo'
|
||||
import { uploadClipboardFiles } from '../uploader/apis'
|
||||
import { cloneDeep } from 'lodash'
|
||||
let contextMenu: Menu | null
|
||||
let tray: Tray | null
|
||||
|
||||
@@ -394,13 +395,18 @@ export function createTray () {
|
||||
// so the tray window must be available
|
||||
tray.on('drop-files', async (event: Event, files: string[]) => {
|
||||
const pasteStyle = db.get('settings.pasteStyle') || '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
|
||||
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 notification = new Notification({
|
||||
title: T('UPLOAD_SUCCEED'),
|
||||
|
||||
@@ -13,6 +13,8 @@ import { T } from '~/main/i18n/index'
|
||||
import ALLApi from '@/apis/allApi'
|
||||
import picgo from '@core/picgo'
|
||||
import GuiApi from '../../gui'
|
||||
import fs from 'fs-extra'
|
||||
import { cloneDeep } from 'lodash'
|
||||
|
||||
const handleClipboardUploading = async (): Promise<false | ImgInfo[]> => {
|
||||
const useBuiltinClipboard = db.get('settings.useBuiltinClipboard') === undefined ? true : !!db.get('settings.useBuiltinClipboard')
|
||||
@@ -71,12 +73,21 @@ export const uploadClipboardFiles = async (): Promise<IStringKeyMap> => {
|
||||
|
||||
export const uploadChoosedFiles = async (webContents: WebContents, files: IFileWithPath[]): Promise<IStringKeyMap[]> => {
|
||||
const input = files.map(item => item.path)
|
||||
const rawInput = cloneDeep(input)
|
||||
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 pasteText: string[] = []
|
||||
for (let i = 0; i < imgs.length; i++) {
|
||||
if (deleteLocalFile) {
|
||||
fs.remove(rawInput[i]).then(() => {
|
||||
picgo.log.info(`delete local file: ${rawInput[i]}`)
|
||||
}).catch((err: Error) => {
|
||||
picgo.log.error(err)
|
||||
})
|
||||
}
|
||||
pasteText.push(await (pasteTemplate(pasteStyle, imgs[i], db.get('settings.customLink'))))
|
||||
const notification = new Notification({
|
||||
title: T('UPLOAD_SUCCEED'),
|
||||
|
||||
@@ -18,6 +18,8 @@ import {
|
||||
} from '~/universal/events/constants'
|
||||
import { DBStore } from '@picgo/store'
|
||||
import { T } from '~/main/i18n'
|
||||
import fs from 'fs-extra'
|
||||
import { cloneDeep } from 'lodash'
|
||||
|
||||
// Cross-process support may be required in the future
|
||||
class GuiApi implements IGuiApi {
|
||||
@@ -76,11 +78,16 @@ class GuiApi implements IGuiApi {
|
||||
async upload (input: IUploadOption) {
|
||||
this.windowId = await getWindowId()
|
||||
const webContents = this.getWebcontentsByWindowId(this.windowId)
|
||||
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 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 notification = new Notification({
|
||||
title: T('UPLOAD_SUCCEED'),
|
||||
|
||||
@@ -225,6 +225,16 @@
|
||||
@change="handleDeleteCloudFile"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item
|
||||
:label="$T('SETTINGS_DELETE_LOCAL_FILE_AFTER_UPLOAD')"
|
||||
>
|
||||
<el-switch
|
||||
v-model="form.deleteLocalFile"
|
||||
:active-text="$T('SETTINGS_OPEN')"
|
||||
:inactive-text="$T('SETTINGS_CLOSE')"
|
||||
@change="handleDeleteLocalFile"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item
|
||||
:label="$T('SETTINGS_RENAME_BEFORE_UPLOAD')"
|
||||
>
|
||||
@@ -1073,7 +1083,8 @@ const form = reactive<ISettingForm>({
|
||||
isHideDock: false,
|
||||
encodeOutputURL: true,
|
||||
isAutoListenClipboard: false,
|
||||
useShortUrl: false
|
||||
useShortUrl: false,
|
||||
deleteLocalFile: false
|
||||
})
|
||||
|
||||
const languageList = i18nManager.languageList.map(item => ({
|
||||
@@ -1172,6 +1183,7 @@ async function initData () {
|
||||
form.customMiniIcon = settings.customMiniIcon || ''
|
||||
form.isHideDock = settings.isHideDock || false
|
||||
form.useShortUrl = settings.useShortUrl || false
|
||||
form.deleteLocalFile = settings.deleteLocalFile || false
|
||||
currentLanguage.value = settings.language ?? 'zh-CN'
|
||||
currentStartMode.value = settings.startMode || 'quiet'
|
||||
customLink.value = settings.customLink || ''
|
||||
@@ -1331,6 +1343,12 @@ function handleDeleteCloudFile (val: ICheckBoxValueType) {
|
||||
})
|
||||
}
|
||||
|
||||
function handleDeleteLocalFile (val: ICheckBoxValueType) {
|
||||
saveConfig({
|
||||
'settings.deleteLocalFile': val
|
||||
})
|
||||
}
|
||||
|
||||
function handleRename (val: ICheckBoxValueType) {
|
||||
saveConfig({
|
||||
'settings.rename': val
|
||||
|
||||
@@ -630,7 +630,6 @@ async function getUseShortUrl () {
|
||||
}
|
||||
|
||||
async function handleUseShortUrlChange () {
|
||||
console.log(useShortUrl.value)
|
||||
saveConfig({
|
||||
'settings.useShortUrl': useShortUrl.value
|
||||
})
|
||||
|
||||
1
src/universal/types/i18n.d.ts
vendored
1
src/universal/types/i18n.d.ts
vendored
@@ -193,6 +193,7 @@ interface ILocales {
|
||||
SETTINGS_ENCODE_OUTPUT_URL: string
|
||||
SETTINGS_WATCH_CLIPBOARD: string
|
||||
SETTINGS_SHORT_URL: string
|
||||
SETTINGS_DELETE_LOCAL_FILE_AFTER_UPLOAD: string
|
||||
SHORTCUT_NAME: string
|
||||
SHORTCUT_BIND: string
|
||||
SHORTCUT_STATUS: string
|
||||
|
||||
3
src/universal/types/view.d.ts
vendored
3
src/universal/types/view.d.ts
vendored
@@ -18,7 +18,8 @@ interface ISettingForm {
|
||||
isHideDock: boolean,
|
||||
encodeOutputURL: boolean,
|
||||
isAutoListenClipboard: boolean,
|
||||
useShortUrl: boolean
|
||||
useShortUrl: boolean,
|
||||
deleteLocalFile: boolean
|
||||
}
|
||||
|
||||
interface IShortKeyMap {
|
||||
|
||||
Reference in New Issue
Block a user