fix: fix some datauri download bug
This commit is contained in:
@@ -30,11 +30,7 @@ export default function pakeCliDevPlugin() {
|
|||||||
console.log(chalk.yellow(`cli running end with code: ${code}`));
|
console.log(chalk.yellow(`cli running end with code: ${code}`));
|
||||||
if (devHasStarted) return;
|
if (devHasStarted) return;
|
||||||
devHasStarted = true;
|
devHasStarted = true;
|
||||||
|
devChildProcess = await exec('npm run tauri dev -- --config ./src-tauri/.pake/tauri.conf.json --features cli-build');
|
||||||
const devCommand = 'npm';
|
|
||||||
const devArgs = ['run', 'tauri', 'dev', '--', '--config', './src-tauri/.pake/tauri.conf.json', '--features', 'cli-build'];
|
|
||||||
devChildProcess = spawn(devCommand, devArgs, {detached: true});
|
|
||||||
|
|
||||||
|
|
||||||
devChildProcess.stdout.on('data', (data) => {
|
devChildProcess.stdout.on('data', (data) => {
|
||||||
console.log(chalk.green(data.toString()));
|
console.log(chalk.green(data.toString()));
|
||||||
|
|||||||
11
src-tauri/src/inject/event.js
vendored
11
src-tauri/src/inject/event.js
vendored
@@ -137,6 +137,8 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const specialDownloadProtocal = ['blob', 'data'];
|
||||||
|
|
||||||
const detectAnchorElementClick = (e) => {
|
const detectAnchorElementClick = (e) => {
|
||||||
const anchorElement = e.target.closest('a');
|
const anchorElement = e.target.closest('a');
|
||||||
if (anchorElement && anchorElement.href) {
|
if (anchorElement && anchorElement.href) {
|
||||||
@@ -164,7 +166,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
e.metaKey ||
|
e.metaKey ||
|
||||||
e.ctrlKey ||
|
e.ctrlKey ||
|
||||||
isDownloadLink(absoluteUrl)) &&
|
isDownloadLink(absoluteUrl)) &&
|
||||||
!externalDownLoadLink() && !url.startsWith("blob")
|
!externalDownLoadLink() && specialDownloadProtocal.every(protocal => !absoluteUrl.startsWith(protocal))
|
||||||
) {
|
) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
invoke('download_file', {
|
invoke('download_file', {
|
||||||
@@ -262,7 +264,7 @@ function convertBlobUrlToBinary(blobUrl) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function downladFromDataUri(dataURI) {
|
function downladFromDataUri(dataURI, filename) {
|
||||||
const byteString = atob(dataURI.split(',')[1]);
|
const byteString = atob(dataURI.split(',')[1]);
|
||||||
// write the bytes of the string to an ArrayBuffer
|
// write the bytes of the string to an ArrayBuffer
|
||||||
const bufferArray = new ArrayBuffer(byteString.length);
|
const bufferArray = new ArrayBuffer(byteString.length);
|
||||||
@@ -305,11 +307,12 @@ function detectDownloadByCreateAnchor() {
|
|||||||
// use addEventListener to avoid overriding the original click event.
|
// use addEventListener to avoid overriding the original click event.
|
||||||
anchorEle.addEventListener('click', () => {
|
anchorEle.addEventListener('click', () => {
|
||||||
const url = anchorEle.href;
|
const url = anchorEle.href;
|
||||||
|
const filename = anchorEle.download || getFilenameFromUrl(url);
|
||||||
if (window.blobToUrlCaches.has(url)) {
|
if (window.blobToUrlCaches.has(url)) {
|
||||||
downloadFromBlobUrl(url, anchorEle.download || getFilenameFromUrl(url));
|
downloadFromBlobUrl(url, filename);
|
||||||
// case: downoload from dataURL -> convert dataURL ->
|
// case: downoload from dataURL -> convert dataURL ->
|
||||||
} else if (url.startsWith('data:')) {
|
} else if (url.startsWith('data:')) {
|
||||||
downladFromDataUri(url);
|
downladFromDataUri(url, filename);
|
||||||
}
|
}
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user