From 06a91b1c2df15866bc51f3275d10fae8a7c24651 Mon Sep 17 00:00:00 2001 From: Xmader Date: Wed, 27 Jan 2021 14:03:58 -0500 Subject: [PATCH] v0.23.8 --- dist/main.js | 35 +++++++++++++++++++---------------- package-lock.json | 2 +- package.json | 2 +- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/dist/main.js b/dist/main.js index ca6ad6e..c682276 100644 --- a/dist/main.js +++ b/dist/main.js @@ -5,7 +5,7 @@ // @supportURL https://github.com/Xmader/musescore-downloader/issues // @updateURL https://msdl.librescore.org/install.user.js // @downloadURL https://msdl.librescore.org/install.user.js -// @version 0.23.7 +// @version 0.23.8 // @description download sheet music from musescore.com for free, no login or Musescore Pro required | 免登录、免 Musescore Pro,免费下载 musescore.com 上的曲谱 // @author Xmader // @match https://musescore.com/*/* @@ -26439,7 +26439,7 @@ Please pipe the document into a Node stream.\ }); /// - const getDataURL = (blob) => { + const readData = (blob, type) => { return new Promise((resolve, reject) => { const reader = new FileReader(); reader.onload = () => { @@ -26447,19 +26447,21 @@ Please pipe the document into a Node stream.\ resolve(result); }; reader.onerror = reject; - reader.readAsDataURL(blob); + if (type === 'dataUrl') { + reader.readAsDataURL(blob); + } + else { + reader.readAsText(blob); + } }); }; - const fetchDataURL = (imgUrl) => __awaiter(void 0, void 0, void 0, function* () { - const r = yield fetch(imgUrl); - const blob = yield r.blob(); - return getDataURL(blob); + const fetchBlob = (imgUrl) => __awaiter(void 0, void 0, void 0, function* () { + const r = yield fetch(imgUrl, { + cache: 'no-cache', + }); + return r.blob(); }); - const fetchText = (imgUrl) => __awaiter(void 0, void 0, void 0, function* () { - const r = yield fetch(imgUrl); - return r.text(); - }); - const generatePDF = (imgURLs, imgType, width, height) => __awaiter(void 0, void 0, void 0, function* () { + const generatePDF = (imgBlobs, imgType, width, height) => __awaiter(void 0, void 0, void 0, function* () { // @ts-ignore const pdf = new PDFDocument({ // compress: true, @@ -26469,7 +26471,7 @@ Please pipe the document into a Node stream.\ layout: 'portrait', }); if (imgType === 'png') { - const imgDataUrlList = yield Promise.all(imgURLs.map(fetchDataURL)); + const imgDataUrlList = yield Promise.all(imgBlobs.map(b => readData(b, 'dataUrl'))); imgDataUrlList.forEach((data) => { pdf.addPage(); pdf.image(data, { @@ -26479,7 +26481,7 @@ Please pipe the document into a Node stream.\ }); } else { // imgType == "svg" - const svgList = yield Promise.all(imgURLs.map(fetchText)); + const svgList = yield Promise.all(imgBlobs.map(b => readData(b, 'text'))); svgList.forEach((svg) => { pdf.addPage(); source(pdf, svg, 0, 0, { @@ -26492,8 +26494,9 @@ Please pipe the document into a Node stream.\ return buf.buffer; }); onmessage = (e) => __awaiter(void 0, void 0, void 0, function* () { - const [imgURLs, imgType, width, height,] = e.data; - const pdfBuf = yield generatePDF(imgURLs, imgType, width, height); + const [imgUrls, imgType, width, height,] = e.data; + const imgBlobs = yield Promise.all(imgUrls.map(url => fetchBlob(url))); + const pdfBuf = yield generatePDF(imgBlobs, imgType, width, height); postMessage(pdfBuf, [pdfBuf]); }); diff --git a/package-lock.json b/package-lock.json index 6098691..4de4757 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "musescore-downloader", - "version": "0.23.7", + "version": "0.23.8", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 8a9f72d..87f4e04 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "musescore-downloader", - "version": "0.23.7", + "version": "0.23.8", "description": "download sheet music from musescore.com for free, no login or Musescore Pro required | 免登录、免 Musescore Pro,免费下载 musescore.com 上的曲谱", "main": "dist/main.js", "bin": "dist/cli.js",