mirror of
https://github.com/Kuingsmile/PicList.git
synced 2025-01-23 06:38:13 -05:00
✨ Feature: add delete local file after uploading, fix compatibility with auto-delete
ISSUES CLOSED: #40
This commit is contained in:
parent
34997f58aa
commit
6b49198d19
@ -68,7 +68,7 @@
|
||||
"mime-types": "^2.1.35",
|
||||
"mitt": "^3.0.0",
|
||||
"nodejs-file-downloader": "^4.10.6",
|
||||
"piclist": "^0.5.1",
|
||||
"piclist": "^0.5.2",
|
||||
"pinia": "^2.0.32",
|
||||
"pinia-plugin-persistedstate": "^3.1.0",
|
||||
"qiniu": "^7.8.0",
|
||||
|
@ -197,6 +197,7 @@ SETTINGS_ISHIDEDOCK_TIPS: Not support hide dock and tray at the same time
|
||||
SETTINGS_ENCODE_OUTPUT_URL: Encode Output(or Copyed) URL
|
||||
SETTINGS_WATCH_CLIPBOARD: Watch clipboard when software start
|
||||
SETTINGS_SHORT_URL: Use short url
|
||||
SETTINGS_DELETE_LOCAL_FILE_AFTER_UPLOAD: Delete local file after upload
|
||||
# shortcut-page
|
||||
|
||||
BUILTIN_CLIPBOARD_TIPS: Use builtin clipboard function to upload instead of using scripts
|
||||
|
@ -199,6 +199,7 @@ SETTINGS_ISHIDEDOCK_TIPS: 不支持同时隐藏dock和托盘
|
||||
SETTINGS_ENCODE_OUTPUT_URL: 输出(复制) URL 时进行转义
|
||||
SETTINGS_WATCH_CLIPBOARD: 软件启动时自动监听剪贴板上传
|
||||
SETTINGS_SHORT_URL: 使用短链接
|
||||
SETTINGS_DELETE_LOCAL_FILE_AFTER_UPLOAD: 上传后删除本地文件
|
||||
# shortcut-page
|
||||
|
||||
SHORTCUT_NAME: 快捷键名称
|
||||
|
@ -197,6 +197,7 @@ SETTINGS_ISHIDEDOCK_TIPS: 不支持同時隱藏dock和托盘
|
||||
SETTINGS_ENCODE_OUTPUT_URL: 輸出(複製) URL 時進行轉義
|
||||
SETTINGS_WATCH_CLIPBOARD: 軟體啟動時自動監聽剪貼簿上傳
|
||||
SETTINGS_SHORT_URL: 使用短網址
|
||||
SETTINGS_DELETE_LOCAL_FILE_AFTER_UPLOAD: 上傳後刪除本地檔案
|
||||
# shortcut-page
|
||||
|
||||
SHORTCUT_NAME: 快捷鍵名稱
|
||||
|
@ -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 || '![$fileName]($url)'
|
||||
@ -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 {
|
||||
|
@ -11044,10 +11044,10 @@ performance-now@^2.1.0:
|
||||
resolved "https://registry.npmmirror.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b"
|
||||
integrity sha512-7EAHlyLHI56VEIdK57uwHdHKIaAGbnXPiw0yWbarQZOKaKpvUIgW0jWRVLiatnM+XXlSwsanIBH/hzGMJulMow==
|
||||
|
||||
piclist@^0.5.1:
|
||||
version "0.5.1"
|
||||
resolved "https://registry.npmjs.org/piclist/-/piclist-0.5.1.tgz#0d2b48c503e3a9eba73b26863c162642b0351b34"
|
||||
integrity sha512-miF3+vunzE7uzAMuTaPoGYjgSrQWBrVLUOYa+V2NK2Y02CZ1d9AiFQMz73DsrQuch8GCXyDoauTpLZFQjbR5Bg==
|
||||
piclist@^0.5.2:
|
||||
version "0.5.2"
|
||||
resolved "https://registry.npmjs.org/piclist/-/piclist-0.5.2.tgz#bb366e7c07f93b4dbe615ad5e1489647eb8508c7"
|
||||
integrity sha512-j3s92ZzalSNjG1xu8doBjojTjWs8o1iRtAUqb0BLFnrtpWZ+91zcp6zb3wTMyKbH7WTXR+X35yYIvoNF/E0cvw==
|
||||
dependencies:
|
||||
"@picgo/i18n" "^1.0.0"
|
||||
"@picgo/store" "^2.0.4"
|
||||
|
Loading…
Reference in New Issue
Block a user