Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e4d4a135 authored by Paula's avatar Paula
Browse files

Merge branch 'feature/#24-add-version-in-header' into 'main'

add eos_installer_version query param when url includes images cloud url

See merge request !68
parents 0be9544e f9f331c4
Loading
Loading
Loading
Loading

app/app.settings.js

0 → 100644
+4 −0
Original line number Diff line number Diff line
/**
 * Application settings loaded from environment variables
 */
export const APP_VERSION = "0.14";
+26 −6
Original line number Diff line number Diff line
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<Blob>} 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<string>} 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<number>} 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;
  }
}
+1 −1
Original line number Diff line number Diff line
@@ -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