ci: use Gitea API for releases #2
+16
-4
@@ -10,6 +10,19 @@ function errMsg(err) {
|
|||||||
return String((err && err.message) || err);
|
return String((err && err.message) || err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Build a download URL from PDF bytes. Chrome MV3 runs the background as a
|
||||||
|
// service worker, where URL.createObjectURL is NOT available, so we use a
|
||||||
|
// base64 data URL (works in both Firefox and Chrome). PDFs here are small
|
||||||
|
// (~150KB), well within data-URL length limits.
|
||||||
|
function pdfDataUrl(bytes) {
|
||||||
|
let binary = '';
|
||||||
|
const chunk = 0x8000;
|
||||||
|
for (let i = 0; i < bytes.length; i += chunk) {
|
||||||
|
binary += String.fromCharCode.apply(null, bytes.subarray(i, i + chunk));
|
||||||
|
}
|
||||||
|
return 'data:application/pdf;base64,' + btoa(binary);
|
||||||
|
}
|
||||||
|
|
||||||
browser.runtime.onMessage.addListener((msg, sender, sendResponse) => {
|
browser.runtime.onMessage.addListener((msg, sender, sendResponse) => {
|
||||||
if (msg && msg.type === 'generate-pdf') {
|
if (msg && msg.type === 'generate-pdf') {
|
||||||
generatePdf(msg.data)
|
generatePdf(msg.data)
|
||||||
@@ -32,8 +45,9 @@ function formatPeriod(period) {
|
|||||||
|
|
||||||
async function generatePdf(data) {
|
async function generatePdf(data) {
|
||||||
const bytes = await ISMIStools.buildStudyLoadPdf(data);
|
const bytes = await ISMIStools.buildStudyLoadPdf(data);
|
||||||
const blob = new Blob([bytes], { type: 'application/pdf' });
|
// Chrome MV3 background is a service worker (no URL.createObjectURL), so we
|
||||||
const url = URL.createObjectURL(blob);
|
// use a base64 data URL that works in both browsers.
|
||||||
|
const url = pdfDataUrl(bytes);
|
||||||
const header = data.header || {};
|
const header = data.header || {};
|
||||||
const year = parseInt(data.year, 10);
|
const year = parseInt(data.year, 10);
|
||||||
const period = formatPeriod(data.period || header.semester || '');
|
const period = formatPeriod(data.period || header.semester || '');
|
||||||
@@ -55,12 +69,10 @@ async function generatePdf(data) {
|
|||||||
const onChanged = (delta) => {
|
const onChanged = (delta) => {
|
||||||
if (delta.id === id && delta.state && (delta.state.current === 'complete' || delta.state.current === 'interrupted')) {
|
if (delta.id === id && delta.state && (delta.state.current === 'complete' || delta.state.current === 'interrupted')) {
|
||||||
browser.downloads.onChanged.removeListener(onChanged);
|
browser.downloads.onChanged.removeListener(onChanged);
|
||||||
URL.revokeObjectURL(url);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
browser.downloads.onChanged.addListener(onChanged);
|
browser.downloads.onChanged.addListener(onChanged);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
URL.revokeObjectURL(url);
|
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user