aboutsummaryrefslogtreecommitdiff
path: root/html
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2022-02-09 17:09:13 +0100
committerWojtek Kosior <koszko@koszko.org>2022-02-09 18:00:16 +0100
commit1c65dd5ca24052ccf9a92939eecd0966c9635c50 (patch)
tree7575157ccd729b4ad79f6c04501023ccb0532a63 /html
parent830d22d8931a4e5f0606d401f24d7cd937f8697e (diff)
downloadbrowser-extension-1c65dd5ca24052ccf9a92939eecd0966c9635c50.tar.gz
browser-extension-1c65dd5ca24052ccf9a92939eecd0966c9635c50.zip
adapt to changes in file path format
From now on we assume Hydrilla serves file contents at 'file/sha256/<hash>' instead of 'file/sha256-<hash>'. With this commit we also stop using the "hash_key" property internally.
Diffstat (limited to 'html')
-rw-r--r--html/install.js30
-rw-r--r--html/item_preview.js2
-rw-r--r--html/payload_create.js11
3 files changed, 20 insertions, 23 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) {
diff --git a/html/item_preview.js b/html/item_preview.js
index c55183c..bd4fd68 100644
--- a/html/item_preview.js
+++ b/html/item_preview.js
@@ -63,7 +63,7 @@ const file_preview_link = browser.runtime.getURL("html/file_preview.html");
*/
function make_file_link(preview_object, file_ref) {
const a = document.createElement("a");
- a.href = `${file_preview_link}#${file_ref.hash_key}`;
+ a.href = `${file_preview_link}#${file_ref.sha256}`;
a.innerText = file_ref.file;
a.target = "_blank";
return a;
diff --git a/html/payload_create.js b/html/payload_create.js
index 8828809..7782299 100644
--- a/html/payload_create.js
+++ b/html/payload_create.js
@@ -45,7 +45,7 @@
#IMPORT common/indexeddb.js AS haketilodb
#FROM html/DOM_helpers.js IMPORT clone_template
-#FROM common/sha256.js IMPORT sha256
+#FROM common/sha256.js IMPORT sha256 AS compute_sha256
#FROM common/patterns.js IMPORT validate_normalize_url_pattern, \
patterns_doc_url
@@ -94,7 +94,7 @@ function collect_form_data(form_ctx)
const script = form_ctx.script.value;
if (!script)
throw "The 'script' field is required!";
- const hash_key = `sha256-${sha256(script)}`;
+ const sha256 = compute_sha256(script);
const resource = {
source_name: identifier,
@@ -106,7 +106,7 @@ function collect_form_data(form_ctx)
version: [1],
description,
dependencies: [],
- scripts: [{file: "payload.js", hash_key}]
+ scripts: [{file: "payload.js", sha256}]
};
const mapping = {
@@ -121,7 +121,7 @@ function collect_form_data(form_ctx)
payloads
};
- return {identifier, resource, mapping, files: {[hash_key]: script}};
+ return {identifier, resource, mapping, files_by_sha256: {[sha256]: script}};
}
function clear_form(form_ctx)
@@ -137,7 +137,8 @@ async function save_payload(saving)
{
const db = await haketilodb.get();
const tx_starter = haketilodb.start_items_transaction;
- const tx_ctx = await tx_starter(["resource", "mapping"], saving.files);
+ const files = {sha256: saving.files_by_sha256};
+ const tx_ctx = await tx_starter(["resource", "mapping"], files);
for (const type of ["resource", "mapping"]) {
if (!saving[`override_${type}`] &&