diff options
Diffstat (limited to 'html/install.js')
-rw-r--r-- | html/install.js | 30 |
1 files changed, 13 insertions, 17 deletions
diff --git a/html/install.js b/html/install.js index e972924..68033bc 100644 --- a/html/install.js +++ b/html/install.js @@ -49,7 +49,7 @@ #FROM html/DOM_helpers.js IMPORT clone_template, Showable #FROM common/entities.js IMPORT item_id_string, version_string, get_files, \ is_valid_version -#FROM common/misc.js IMPORT sha256_async AS sha256 +#FROM common/misc.js IMPORT sha256_async AS compute_sha256 const coll = new Intl.Collator(); @@ -134,7 +134,7 @@ function InstallView(tab_id, on_view_show, on_view_hide) { /* Make a link to view a file from the repository. */ const make_file_link = (preview_ctx, file_ref) => { const a = document.createElement("a"); - a.href = `${this.repo_url}file/${file_ref.hash_key}`; + a.href = `${this.repo_url}file/sha256/${file_ref.sha256}`; a.innerText = file_ref.file; return a; @@ -213,10 +213,6 @@ function InstallView(tab_id, on_view_show, on_view_hide) { const files = response.json.source_copyright .concat(item_type === "resource" ? response.json.scripts : []); - for (const file of files) { - file.hash_key = `sha256-${file.sha256}`; - delete file.sha256; - } if (item_type === "mapping") { for (const res_ref of Object.values(response.json.payloads)) @@ -294,7 +290,7 @@ function InstallView(tab_id, on_view_show, on_view_hide) { dialog.close(this.dialog_ctx); } - const process_file = async (work, hash_key) => { + const process_file = async (work, sha256) => { if (!work.is_ok) return; @@ -302,7 +298,7 @@ function InstallView(tab_id, on_view_show, on_view_hide) { try { var file_uses = await haketilodb.idb_get(work.file_uses_transaction, - "file_uses", hash_key); + "file_uses", sha256); if (!work.is_ok) return; } catch(e) { @@ -311,7 +307,7 @@ function InstallView(tab_id, on_view_show, on_view_hide) { } if (!file_uses) { - const url = `${this.repo_url}file/${hash_key}`; + const url = `${this.repo_url}file/sha256/${sha256}`; try { var response = await fetch(url); @@ -336,15 +332,15 @@ function InstallView(tab_id, on_view_show, on_view_hide) { return work.err(e, msg); } - const digest = await sha256(text); + const digest = await compute_sha256(text); if (!work.is_ok) return; - if (`sha256-${digest}` !== hash_key) { + if (digest !== sha256) { const msg = `${url} served a file with different SHA256 cryptographic sum :(`; return work.err(null, msg); } - work.result.push([hash_key, text]); + work.result.push([sha256, text]); } if (--work.waiting === 0) @@ -359,9 +355,9 @@ function InstallView(tab_id, on_view_show, on_view_hide) { for (const item_def of item_defs) { for (const file of get_files(item_def)) { - if (!processed_files.has(file.hash_key)) { - processed_files.add(file.hash_key); - process_file(work, file.hash_key); + if (!processed_files.has(file.sha256)) { + processed_files.add(file.sha256); + process_file(work, file.sha256); } } } @@ -379,13 +375,13 @@ function InstallView(tab_id, on_view_show, on_view_hide) { try { var files = (await get_missing_files(item_defs)) - .reduce((ac, [hk, txt]) => Object.assign(ac, {[hk]: txt}), {}); + .reduce((ac, [h, txt]) => Object.assign(ac, {[h]: txt}), {}); } catch(e) { var dialog_prom = dialog.error(this.dialog_ctx, e); } if (files !== undefined) { - const data = {files}; + const data = {file: {sha256: files}}; const names = [["mappings", "mapping"], ["resources", "resource"]]; for (const [set_name, type] of names) { |