diff --git a/app/app.settings.js b/app/app.settings.js new file mode 100644 index 0000000000000000000000000000000000000000..bd08239a4666b5d914d696dab221ccf4f982c318 --- /dev/null +++ b/app/app.settings.js @@ -0,0 +1,4 @@ +/** + * Application settings loaded from environment variables + */ +export const APP_VERSION = "0.14"; diff --git a/app/src/controller/utils/http-fetcher.class.js b/app/src/controller/utils/http-fetcher.class.js index 777ac906fb737391b9a6d3dd2fb7b2e290f6c250..94d03fd71deca15ae9e57354c7e548e633924a10 100644 --- a/app/src/controller/utils/http-fetcher.class.js +++ b/app/src/controller/utils/http-fetcher.class.js @@ -1,5 +1,6 @@ import ky from "ky"; import { createSHA256 } from "hash-wasm"; +import { APP_VERSION } from "../../../app.settings.js"; const SHA256_CHUNK_SIZE = 16 * 1024 * 1024; // 16 MB const DOWNLOAD_CHUNK_SIZE = 16 * 1024 * 1024; // 16 MB @@ -11,20 +12,21 @@ export class HttpFetcher { /** * Downloads a file in sequential Range chunks and returns a Blob. * - * @param {string} path File URL to download. + * @param {string} url File URL to download. * @param {(loaded:number,total:number)=>void} onProgress Progress callback. * @returns {Promise} Downloaded file blob. */ - async download(path, onProgress) { - const contentLength = await this.getContentLength(path); + async download(url, onProgress) { + const contentLength = await this.getContentLength(url); const totalChunks = Math.ceil(contentLength / DOWNLOAD_CHUNK_SIZE); const buffers = []; + const urlObj = this.formatUrl(url); for (let i = 0; i < totalChunks; i++) { const start = i * DOWNLOAD_CHUNK_SIZE; const end = Math.min(start + DOWNLOAD_CHUNK_SIZE - 1, contentLength - 1); try { - const response = await ky.get(path, { + const response = await ky.get(urlObj, { headers: { Range: `bytes=${start}-${end}` }, }); if (!response.ok) { @@ -51,7 +53,8 @@ export class HttpFetcher { * @returns {Promise} Parsed lowercase SHA-256 hash. */ async fetchChecksum(url) { - const res = await ky.get(url); + const urlObj = this.formatUrl(url); + const res = await ky.get(urlObj); if (!res.ok) { throw new Error(`Cannot fetch checksum (${res.status})`); } @@ -90,7 +93,24 @@ export class HttpFetcher { * @returns {Promise} Content length in bytes. */ async getContentLength(url) { - const response = await ky.head(url); + const urlObj = this.formatUrl(url); + const response = await ky.head(urlObj); return parseInt(response.headers.get("content-length"), 10); } + + /** + * Formats a URL with optional query parameters. + * + * @param {string} url Base URL. + * @param {Object} opts Query parameters as key-value pairs. + * @returns {URL} Formatted URL object. + */ + formatUrl(url, opts = {}) { + const urlObj = new URL(url); + for (const [key, value] of Object.entries(opts)) { + urlObj.searchParams.set(key, String(value)); + } + urlObj.searchParams.set("eos_installer_version", APP_VERSION); + return urlObj; + } } diff --git a/scripts/version.sh b/scripts/version.sh index 687cc02f4a177031cad55923efb137a9985c1af0..7cc2cabf057e8a3707067eeab8d77df775fcd510 100755 --- a/scripts/version.sh +++ b/scripts/version.sh @@ -6,7 +6,7 @@ function bump() { cd $ROOT_DIR local old=$1 local new=$2 - sed -i 's!'$old'!'$new'!g' app/index.html app/package.json + sed -i 's!'$old'!'$new'!g' app/index.html app/package.json app/app.settings.js cd $ROOT_DIR/app npm install exit 0