Branchwell

PulseCanvas / website · pulsecanvas.ai / download.js

Raw 1.9 KB on 0cef5bc007bcecc69010c0ad24efe67f29d0dada
1import './page.js';
2import { validateCreatorsRelease } from './installer-release.js';
3
4const status = document.querySelector('#installer-status');
5const button = document.querySelector('#installer-download');
6const retry = document.querySelector('#installer-retry');
7
8async function configureInstaller() {
9 retry.hidden = true;
10 retry.disabled = true;
11 try {
12 const response = await fetch('/mac-release.json', { cache: 'no-store' });
13 // Keep the finished page neutral until the owner supplies the release files.
14 if (response.status === 404) return;
15 // Vite serves HTML for an absent JSON file during local previews.
16 if (!response.headers.get('content-type')?.includes('application/json')) return;
17 if (!response.ok) throw new Error('Release lookup failed');
18 const release = validateCreatorsRelease(await response.json(), location.origin);
19 button.href = release.downloadUrl;
20 button.hidden = false;
21 document.querySelector('#installer-placeholder').hidden = true;
22 const fileName = new URL(release.downloadUrl).pathname.split('/').pop();
23 document.querySelector('#installer-details').textContent = `Version ${release.version} (${release.build}) · ${(release.bytes / 1048576).toFixed(1)} MB · ${fileName}`;
24 const sourceLink = document.querySelector('#installer-source');
25 sourceLink.href = release.sourceUrl;
26 sourceLink.hidden = false;
27 document.querySelector('#installer-trust').hidden = false;
28 document.querySelector('#installer-checksum').hidden = false;
29 document.querySelector('#installer-sha').textContent = release.sha256;
30 status.textContent = 'Click below to download the installer, then follow the steps below.';
31 } catch {
32 status.textContent = 'The download details could not be loaded. Try again.';
33 retry.hidden = false;
34 } finally {
35 retry.disabled = false;
36 }
37}
38retry.addEventListener('click', configureInstaller);
39configureInstaller();