pake-cli 2.0.7 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -156,6 +156,7 @@ document.addEventListener('DOMContentLoaded', () => {
156
156
  }
157
157
 
158
158
  let filename = anchorElement.download || getFilenameFromUrl(absoluteUrl);
159
+
159
160
  // Process download links for Rust to handle.
160
161
  // If the download attribute is set, the download attribute is used as the file name.
161
162
  if (
@@ -261,29 +262,32 @@ function convertBlobUrlToBinary(blobUrl) {
261
262
  });
262
263
  }
263
264
 
265
+ function downloadFromBlobUrl(blobUrl, filename) {
266
+ const tauri = window.__TAURI__;
267
+ convertBlobUrlToBinary(blobUrl).then((binary) => {
268
+ console.log('binary', binary);
269
+ tauri.fs.writeBinaryFile(filename, binary, {
270
+ dir: tauri.fs.BaseDirectory.Download,
271
+ }).then(() => {
272
+ window.pakeToast('Download successful, saved to download directory~');
273
+ });
274
+ });
275
+ }
276
+
264
277
  // detect blob download by createElement("a")
265
278
  function detectDownloadByCreateAnchor() {
266
279
  const createEle = document.createElement;
267
280
  document.createElement = (el) => {
268
281
  if (el !== "a") return createEle.call(document, el);
269
282
  const anchorEle = createEle.call(document, el);
270
- const anchorClick = anchorEle.click;
271
-
272
- Object.defineProperties(anchorEle, {
273
- click: {
274
- get: () => {
275
- if (anchorEle.href && anchorEle.href.includes('blob:')) {
276
- const url = anchorEle.href;
277
- convertBlobUrlToBinary(url).then((binary) => {
278
- tauri.fs.writeBinaryFile(anchorEle.download || getFilenameFromUrl(url), binary, {
279
- dir: tauri.fs.BaseDirectory.Download,
280
- });
281
- });
282
- }
283
- return anchorClick.bind(anchorEle);
284
- }
283
+
284
+ // use addEventListener to avoid overriding the original click event.
285
+ anchorEle.addEventListener('click', () => {
286
+ const url = anchorEle.href;
287
+ if (window.blobToUrlCaches.has(url)) {
288
+ downloadFromBlobUrl(url, anchorEle.download || getFilenameFromUrl(url));
285
289
  }
286
- })
290
+ });
287
291
 
288
292
  return anchorEle;
289
293
  }
File without changes