Skip to content

Commit

Permalink
✨ Feature: support short url now
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuingsmile committed Apr 17, 2023
1 parent ef917ce commit d554581
Show file tree
Hide file tree
Showing 20 changed files with 151 additions and 75 deletions.
58 changes: 0 additions & 58 deletions .github/workflows/manually.yml

This file was deleted.

4 changes: 3 additions & 1 deletion public/i18n/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ UPLOAD_PAGE_IMAGE_PROCESS_POSITION_TOP_RIGHT: top right
UPLOAD_PAGE_IMAGE_PROCESS_POSITION_BOTTOM_LEFT: bottom left
UPLOAD_PAGE_IMAGE_PROCESS_POSITION_BOTTOM_RIGHT: bottom right
UPLOAD_PAGE_IMAGE_PROCESS_POSITION_CENTER: center

UPLOAD_SHORT_URL: 短链接
UPLOAD_NORMAL_URL: 长链接
# settings

SETTINGS: Settings
Expand Down Expand Up @@ -195,6 +196,7 @@ SETTINGS_ISHIDEDOCK: Hide Dock Icon
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
# shortcut-page

BUILTIN_CLIPBOARD_TIPS: Use builtin clipboard function to upload instead of using scripts
Expand Down
4 changes: 4 additions & 0 deletions public/i18n/zh-CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ UPLOAD_PAGE_IMAGE_PROCESS_POSITION_TOP_RIGHT: 右上
UPLOAD_PAGE_IMAGE_PROCESS_POSITION_BOTTOM_LEFT: 左下
UPLOAD_PAGE_IMAGE_PROCESS_POSITION_BOTTOM_RIGHT: 右下
UPLOAD_PAGE_IMAGE_PROCESS_POSITION_CENTER:
UPLOAD_SHORT_URL: 短链接
UPLOAD_NORMAL_URL: 长链接


# settings

Expand Down Expand Up @@ -195,6 +198,7 @@ SETTINGS_ISHIDEDOCK: 是否隐藏dock图标
SETTINGS_ISHIDEDOCK_TIPS: 不支持同时隐藏dock和托盘
SETTINGS_ENCODE_OUTPUT_URL: 输出(复制) URL 时进行转义
SETTINGS_WATCH_CLIPBOARD: 软件启动时自动监听剪贴板上传
SETTINGS_SHORT_URL: 使用短链接
# shortcut-page

SHORTCUT_NAME: 快捷键名称
Expand Down
4 changes: 3 additions & 1 deletion public/i18n/zh-TW.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ UPLOAD_PAGE_IMAGE_PROCESS_POSITION_TOP_RIGHT: 右上
UPLOAD_PAGE_IMAGE_PROCESS_POSITION_BOTTOM_LEFT: 左下
UPLOAD_PAGE_IMAGE_PROCESS_POSITION_BOTTOM_RIGHT: 右下
UPLOAD_PAGE_IMAGE_PROCESS_POSITION_CENTER:

UPLOAD_SHORT_URL: 短链接
UPLOAD_NORMAL_URL: 长链接
# settings

SETTINGS: 設定
Expand Down Expand Up @@ -195,6 +196,7 @@ SETTINGS_ISHIDEDOCK: 是否隱藏dock圖示
SETTINGS_ISHIDEDOCK_TIPS: 不支持同時隱藏dock和托盘
SETTINGS_ENCODE_OUTPUT_URL: 輸出(複製) URL 時進行轉義
SETTINGS_WATCH_CLIPBOARD: 軟體啟動時自動監聽剪貼簿上傳
SETTINGS_SHORT_URL: 使用短網址
# shortcut-page

SHORTCUT_NAME: 快捷鍵名稱
Expand Down
2 changes: 1 addition & 1 deletion src/main/apis/app/system/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ export function createTray () {
if (imgs !== false) {
const pasteText: string[] = []
for (let i = 0; i < imgs.length; i++) {
pasteText.push(pasteTemplate(pasteStyle, imgs[i], db.get('settings.customLink')))
pasteText.push(await (pasteTemplate(pasteStyle, imgs[i], db.get('settings.customLink'))))
const notification = new Notification({
title: T('UPLOAD_SUCCEED'),
body: imgs[i].imgUrl!
Expand Down
4 changes: 2 additions & 2 deletions src/main/apis/app/uploader/apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const uploadClipboardFiles = async (): Promise<IStringKeyMap> => {
if (img.length > 0) {
const trayWindow = windowManager.get(IWindowList.TRAY_WINDOW)
const pasteStyle = db.get('settings.pasteStyle') || 'markdown'
handleCopyUrl(pasteTemplate(pasteStyle, img[0], db.get('settings.customLink')))
handleCopyUrl(await (pasteTemplate(pasteStyle, img[0], db.get('settings.customLink'))))
const notification = new Notification({
title: T('UPLOAD_SUCCEED'),
body: img[0].imgUrl!
Expand Down Expand Up @@ -77,7 +77,7 @@ export const uploadChoosedFiles = async (webContents: WebContents, files: IFileW
const pasteStyle = db.get('settings.pasteStyle') || 'markdown'
const pasteText: string[] = []
for (let i = 0; i < imgs.length; i++) {
pasteText.push(pasteTemplate(pasteStyle, imgs[i], db.get('settings.customLink')))
pasteText.push(await (pasteTemplate(pasteStyle, imgs[i], db.get('settings.customLink'))))
const notification = new Notification({
title: T('UPLOAD_SUCCEED'),
body: imgs[i].imgUrl!
Expand Down
2 changes: 1 addition & 1 deletion src/main/apis/gui/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class GuiApi implements IGuiApi {
const pasteStyle = db.get('settings.pasteStyle') || 'markdown'
const pasteText: string[] = []
for (let i = 0; i < imgs.length; i++) {
pasteText.push(pasteTemplate(pasteStyle, imgs[i], db.get('settings.customLink')))
pasteText.push(await (pasteTemplate(pasteStyle, imgs[i], db.get('settings.customLink'))))
const notification = new Notification({
title: T('UPLOAD_SUCCEED'),
body: imgs[i].imgUrl as string
Expand Down
2 changes: 1 addition & 1 deletion src/main/events/ipcList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default {
const img = await uploader.setWebContents(trayWindow.webContents).uploadWithBuildInClipboard()
if (img !== false) {
const pasteStyle = db.get('settings.pasteStyle') || 'markdown'
handleCopyUrl(pasteTemplate(pasteStyle, img[0], db.get('settings.customLink')))
handleCopyUrl(await (pasteTemplate(pasteStyle, img[0], db.get('settings.customLink'))))
const notification = new Notification({
title: T('UPLOAD_SUCCEED'),
body: img[0].imgUrl!
Expand Down
2 changes: 1 addition & 1 deletion src/main/events/picgoCoreIPC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ 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 txt = pasteTemplate(pasteStyle, item, customLink)
const txt = await pasteTemplate(pasteStyle, item, customLink)
if (copy) {
clipboard.writeText(txt)
}
Expand Down
8 changes: 6 additions & 2 deletions src/main/utils/pasteTemplate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IPasteStyle } from '#/types/enum'
import { handleUrlEncode } from '#/utils/common'
import { handleUrlEncode, generateShortUrl } from '#/utils/common'
import db from '~/main/apis/core/datastore'

export const formatCustomLink = (customLink: string, item: ImgInfo) => {
Expand All @@ -21,11 +21,15 @@ export const formatCustomLink = (customLink: string, item: ImgInfo) => {
return customLink
}

export default (style: IPasteStyle, item: ImgInfo, customLink: string | undefined) => {
export default async (style: IPasteStyle, item: ImgInfo, customLink: string | undefined) => {
let url = item.url || item.imgUrl
if (db.get('settings.encodeOutputURL') !== false) {
url = handleUrlEncode(url)
}
const useShortUrl = db.get('settings.useShortUrl') || false
if (useShortUrl) {
url = await generateShortUrl(url)
}
const _customLink = customLink || '![$fileName]($url)'
const tpl = {
markdown: `![](${url})`,
Expand Down
1 change: 0 additions & 1 deletion src/main/utils/privacyManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class PrivacyManager {
return false
} else {
db.set('settings.privacyEnsure', true)
return true
}
}
return true
Expand Down
40 changes: 37 additions & 3 deletions src/renderer/pages/Gallery.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
class="handle-bar"
:gutter="16"
>
<el-col :span="6">
<el-col :span="5">
<el-select
v-model="choosedPicBed"
multiple
Expand Down Expand Up @@ -66,7 +66,7 @@
border-style="hidden"
/>
</el-col>
<el-col :span="5">
<el-col :span="3">
<el-select
v-model="pasteStyle"
size="small"
Expand All @@ -82,6 +82,22 @@
/>
</el-select>
</el-col>
<el-col :span="3">
<el-select
v-model="useShortUrl"
size="small"
style="width: 100%"
placeholder="Choose"
@change="handleUseShortUrlChange"
>
<el-option
v-for="(value, key) in shortURLMap"
:key="key"
:label="key"
:value="value"
/>
</el-select>
</el-col>
<el-col :span="2">
<el-dropdown>
<el-button
Expand Down Expand Up @@ -112,7 +128,7 @@
class="handle-bar"
:gutter="16"
>
<el-col :span="6">
<el-col :span="5">
<el-input
v-model="searchText"
:placeholder="$T('GALLERY_SEARCH_FILENAME')"
Expand Down Expand Up @@ -146,6 +162,13 @@
</template>
</el-input>
</el-col>
<el-col :span="1">
<el-divider
direction="vertical"
style="height: 100%;"
border-style="hidden"
/>
</el-col>
<el-col :span="3">
<div
class="item-base copy round"
Expand Down Expand Up @@ -439,6 +462,11 @@ const pasteStyleMap = {
UBB: 'UBB',
Custom: 'Custom'
}
const useShortUrl = ref<string>('')
const shortURLMap = {
[$T('UPLOAD_SHORT_URL')]: $T('UPLOAD_SHORT_URL'),
[$T('UPLOAD_NORMAL_URL')]: $T('UPLOAD_NORMAL_URL')
}
const fileSortNameReverse = ref(false)
const fileSortTimeReverse = ref(false)
const fileSortExtReverse = ref(false)
Expand Down Expand Up @@ -835,6 +863,11 @@ async function handlePasteStyleChange (val: string) {
pasteStyle.value = val
}
function handleUseShortUrlChange (value: string) {
saveConfig('settings.useShortUrl', value === $T('UPLOAD_SHORT_URL'))
useShortUrl.value = value
}
function sortFile (type: 'name' | 'time' | 'ext' | 'check') {
switch (type) {
case 'name':
Expand Down Expand Up @@ -954,6 +987,7 @@ onBeforeUnmount(() => {
onActivated(async () => {
pasteStyle.value = (await getConfig('settings.pasteStyle')) || 'markdown'
useShortUrl.value = (await getConfig('settings.useShortUrl') ? $T('UPLOAD_SHORT_URL') : $T('UPLOAD_NORMAL_URL'))
initDeleteCloud()
})
Expand Down
24 changes: 23 additions & 1 deletion src/renderer/pages/PicGoSetting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,16 @@
@change="handleAutoCopyUrl"
/>
</el-form-item>
<el-form-item
:label="$T('SETTINGS_SHORT_URL')"
>
<el-switch
v-model="form.useShortUrl"
:active-text="$T('SETTINGS_OPEN')"
:inactive-text="$T('SETTINGS_CLOSE')"
@change="handleUseShortUrl"
/>
</el-form-item>
<el-form-item>
<template #label>
<el-row align="middle">
Expand Down Expand Up @@ -1062,7 +1072,8 @@ const form = reactive<ISettingForm>({
customMiniIcon: '',
isHideDock: false,
encodeOutputURL: true,
isAutoListenClipboard: false
isAutoListenClipboard: false,
useShortUrl: false
})
const languageList = i18nManager.languageList.map(item => ({
Expand Down Expand Up @@ -1160,6 +1171,7 @@ async function initData () {
form.isCustomMiniIcon = settings.isCustomMiniIcon || false
form.customMiniIcon = settings.customMiniIcon || ''
form.isHideDock = settings.isHideDock || false
form.useShortUrl = settings.useShortUrl || false
currentLanguage.value = settings.language ?? 'zh-CN'
currentStartMode.value = settings.startMode || 'quiet'
customLink.value = settings.customLink || '![$fileName]($url)'
Expand Down Expand Up @@ -1414,6 +1426,16 @@ function handleAutoCopyUrl (val: ICheckBoxValueType) {
}
}
function handleUseShortUrl (val: ICheckBoxValueType) {
saveConfig('settings.useShortUrl', val)
const successNotification = new Notification($T('SETTINGS_SHORT_URL'), {
body: $T('TIPS_SET_SUCCEED')
})
successNotification.onclick = () => {
return true
}
}
function confirmLogLevelSetting () {
if (form.logLevel.length === 0) {
return $message.error($T('TIPS_PLEASE_CHOOSE_LOG_LEVEL'))
Expand Down
6 changes: 5 additions & 1 deletion src/renderer/pages/TrayPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ import { IResult } from '@picgo/store/dist/types'
import { OPEN_WINDOW } from '#/events/constants'
import { IPasteStyle, IWindowList } from '#/types/enum'
import { getConfig, sendToMain } from '@/utils/dataSender'
import { handleUrlEncode } from '#/utils/common'
import { handleUrlEncode, generateShortUrl } from '#/utils/common'
const files = ref<IResult<ImgInfo>[]>([])
const notification = reactive({
Expand Down Expand Up @@ -127,6 +127,10 @@ async function pasteTemplate (style: IPasteStyle, item: ImgInfo, customLink: str
if ((await getConfig('settings.encodeOutputURL')) !== false) {
url = handleUrlEncode(url)
}
const useShortUrl = await getConfig('settings.useShortUrl') || false
if (useShortUrl) {
url = await generateShortUrl(url)
}
const _customLink = customLink || '![$fileName]($url)'
const tpl = {
markdown: `![](${url})`,
Expand Down
Loading

0 comments on commit d554581

Please sign in to comment.