Skip to content

Commit c59e2bc

Browse files
committed
✨ Feature: add file-name for customurl
add $fileName arg for customUrl ISSUES CLOSED: Molunerfinn#173
1 parent 3c6b329 commit c59e2bc

File tree

5 files changed

+29
-18
lines changed

5 files changed

+29
-18
lines changed

src/main/index.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,7 @@ function createTray () {
170170
const imgs = await new Uploader(files, window.webContents).upload()
171171
if (imgs !== false) {
172172
for (let i in imgs) {
173-
const url = imgs[i].url || imgs[i].imgUrl
174-
clipboard.writeText(pasteTemplate(pasteStyle, url))
173+
clipboard.writeText(pasteTemplate(pasteStyle, imgs[i]))
175174
const notification = new Notification({
176175
title: '上传成功',
177176
body: imgs[i].imgUrl,
@@ -343,8 +342,7 @@ const uploadClipboardFiles = async () => {
343342
if (img !== false) {
344343
if (img.length > 0) {
345344
const pasteStyle = db.read().get('settings.pasteStyle').value() || 'markdown'
346-
const url = img[0].url || img[0].imgUrl
347-
clipboard.writeText(pasteTemplate(pasteStyle, url))
345+
clipboard.writeText(pasteTemplate(pasteStyle, img[0]))
348346
const notification = new Notification({
349347
title: '上传成功',
350348
body: img[0].imgUrl,
@@ -374,8 +372,7 @@ const uploadChoosedFiles = async (webContents, files) => {
374372
const pasteStyle = db.read().get('settings.pasteStyle').value() || 'markdown'
375373
let pasteText = ''
376374
for (let i in imgs) {
377-
const url = imgs[i].url || imgs[i].imgUrl
378-
pasteText += pasteTemplate(pasteStyle, url) + '\r\n'
375+
pasteText += pasteTemplate(pasteStyle, imgs[i]) + '\r\n'
379376
const notification = new Notification({
380377
title: '上传成功',
381378
body: imgs[i].imgUrl,
@@ -401,8 +398,7 @@ ipcMain.on('uploadClipboardFiles', async (evt, file) => {
401398
const img = await new Uploader(undefined, window.webContents).upload()
402399
if (img !== false) {
403400
const pasteStyle = db.read().get('settings.pasteStyle').value() || 'markdown'
404-
const url = img[0].url || img[0].imgUrl
405-
clipboard.writeText(pasteTemplate(pasteStyle, url))
401+
clipboard.writeText(pasteTemplate(pasteStyle, img[0]))
406402
const notification = new Notification({
407403
title: '上传成功',
408404
body: img[0].imgUrl,

src/main/utils/guiApi.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ class GuiApi {
6363
const pasteStyle = db.read().get('settings.pasteStyle').value() || 'markdown'
6464
let pasteText = ''
6565
for (let i in imgs) {
66-
const url = imgs[i].url || imgs[i].imgUrl
67-
pasteText += pasteTemplate(pasteStyle, url) + '\r\n'
66+
pasteText += pasteTemplate(pasteStyle, imgs[i]) + '\r\n'
6867
const notification = new Notification({
6968
title: '上传成功',
7069
body: imgs[i].imgUrl,

src/main/utils/pasteTemplate.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,31 @@
11
import db from '../../datastore'
22

3-
export default (style, url) => {
3+
const formatCustomLink = (customLink, item) => {
4+
let fileName = item.fileName.replace(new RegExp(`\\${item.extname}$`), '')
5+
let url = item.url || item.imgUrl
6+
let formatObj = {
7+
url,
8+
fileName
9+
}
10+
let keys = Object.keys(formatObj)
11+
keys.forEach(item => {
12+
if (customLink.indexOf(`$${item}`) !== -1) {
13+
let reg = new RegExp(`\\$${item}`, 'g')
14+
customLink = customLink.replace(reg, formatObj[item])
15+
}
16+
})
17+
return customLink
18+
}
19+
20+
export default (style, item) => {
21+
let url = item.url || item.imgUrl
422
const customLink = db.read().get('settings.customLink').value() || '$url'
523
const tpl = {
624
'markdown': `![](${url})`,
725
'HTML': `<img src="${url}"/>`,
826
'URL': url,
927
'UBB': `[IMG]${url}[/IMG]`,
10-
'Custom': customLink.replace(/\$url/g, url)
28+
'Custom': formatCustomLink(customLink, item)
1129
}
1230
return tpl[style]
1331
}

src/renderer/pages/Gallery.vue

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,12 @@ export default {
213213
this.changeZIndexForGallery(false)
214214
},
215215
copy (item) {
216-
const url = item.url || item.imgUrl
217216
const style = this.$db.read().get('settings.pasteStyle').value() || 'markdown'
218-
const copyLink = pasteStyle(style, url)
217+
const copyLink = pasteStyle(style, item)
219218
const obj = {
220219
title: '复制链接成功',
221220
body: copyLink,
222-
icon: url
221+
icon: item.url || item.imgUrl
223222
}
224223
const myNotification = new window.Notification(obj.title, obj)
225224
this.$electron.clipboard.writeText(copyLink)
@@ -325,8 +324,7 @@ export default {
325324
Object.keys(this.choosedList).forEach(key => {
326325
if (this.choosedList[key]) {
327326
const item = this.$db.read().get('uploaded').getById(key).value()
328-
const url = item.url || item.imgUrl
329-
copyString += pasteStyle(style, url) + '\n'
327+
copyString += pasteStyle(style, item) + '\n'
330328
this.choosedList[key] = false
331329
}
332330
})

src/renderer/pages/TrayPage.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
this.notification.icon = item.imgUrl
8585
const myNotification = new window.Notification(this.notification.title, this.notification)
8686
const pasteStyle = this.$db.read().get('settings.pasteStyle').value() || 'markdown'
87-
this.$electron.clipboard.writeText(pasteTemplate(pasteStyle, item.imgUrl))
87+
this.$electron.clipboard.writeText(pasteTemplate(pasteStyle, item))
8888
myNotification.onclick = () => {
8989
return true
9090
}

0 commit comments

Comments
 (0)