fix(fs): support asset filenames with percent encoding

Fix #10188
This commit is contained in:
Andelf
2023-09-11 19:26:54 +08:00
parent 5f4c06b28b
commit 8f5b1da36f

View File

@@ -116,15 +116,21 @@ contextBridge.exposeInMainWorld('apis', {
const dest = path.join(repoPathRoot, to)
const assetsRoot = path.dirname(dest)
await fs.promises.mkdir(assetsRoot, { recursive: true })
from = from && decodeURIComponent(from || getFilePathFromClipboard())
from = from || getFilePathFromClipboard()
if (from) {
// console.debug('copy file: ', from, dest)
await fs.promises.copyFile(from, dest)
return path.basename(from)
try {
// console.debug('copy file: ', from, dest)
await fs.promises.copyFile(from, dest)
return path.basename(from)
} catch (e) {
from = decodeURIComponent(from)
await fs.promises.copyFile(from, dest)
return path.basename(from)
}
}
// support image