fix: fix open attachment

This commit is contained in:
purocean
2021-12-16 21:47:54 +08:00
parent 6706a93b1d
commit cb55b8690e
2 changed files with 6 additions and 7 deletions
+1 -1
View File
@@ -24,7 +24,7 @@ async function uploadFile (file: any, asImage: boolean) {
if (asImage) {
insert(`![Img](${encodeMarkdownLink(assetPath)})\n`)
} else {
insert(`[${dayjs().format('YYYY-MM-DD HH:mm')}] [${file.name} (${(file.size / 1024).toFixed(2)}KiB)](${encodeMarkdownLink(assetPath)}){class=open target=_blank}\n`)
insert(`[${dayjs().format('YYYY-MM-DD HH:mm')}] [${file.name} (${(file.size / 1024).toFixed(2)}KiB)](${encodeMarkdownLink(assetPath)}){.open}\n`)
}
refreshTree()
+5 -6
View File
@@ -6,7 +6,7 @@ import { sleep } from '@fe/utils'
import { isElectron } from '@fe/support/env'
import { basename, dirname, join, resolve } from '@fe/utils/path'
import { switchDoc } from '@fe/services/document'
import { openExternal, openPath } from '@fe/services/base'
import { getRepo, openExternal, openPath } from '@fe/services/base'
const handleLink = (link: HTMLAnchorElement, view: HTMLElement) => {
const { currentFile } = store.state
@@ -17,11 +17,6 @@ const handleLink = (link: HTMLAnchorElement, view: HTMLElement) => {
const { repo: fileRepo, path: filePath } = currentFile
// open attachment in os
if (link.classList.contains('open')) {
fetch(link.href.replace('api/attachment', 'api/open'))
return true
}
const href = link.getAttribute('href') || ''
if (/^(http:|https:|ftp:)\/\//i.test(href)) { // external link
@@ -32,6 +27,10 @@ const handleLink = (link: HTMLAnchorElement, view: HTMLElement) => {
} else if (/^file:\/\//i.test(href)) {
openPath(decodeURI(href.replace(/^file:\/\//i, '')))
return true
} else if (link.classList.contains('open')) {
const path = link.getAttribute('origin-href') || decodeURI(href)
openPath(join(getRepo(fileRepo)?.path || '/', path))
return true
} else { // relative link
// better scrollIntoView
const scrollIntoView = (el: HTMLElement) => {