aboutsummaryrefslogtreecommitdiff
path: root/html/install.js
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2022-02-16 00:55:04 +0100
committerWojtek Kosior <koszko@koszko.org>2022-02-16 10:12:51 +0100
commit72553a2d8b5fa094a5edd5e6ec15b5125a052016 (patch)
treecfbca085fd54ce482561e65726f825c00b2ac795 /html/install.js
parentb47de554fb01b478b09d9d65b5eac4b05fd903fc (diff)
downloadbrowser-extension-72553a2d8b5fa094a5edd5e6ec15b5125a052016.tar.gz
browser-extension-72553a2d8b5fa094a5edd5e6ec15b5125a052016.zip
assume and use "$schema" properties in item definitions
Diffstat (limited to 'html/install.js')
-rw-r--r--html/install.js37
1 files changed, 21 insertions, 16 deletions
diff --git a/html/install.js b/html/install.js
index 2a72662..7b3f3fe 100644
--- a/html/install.js
+++ b/html/install.js
@@ -47,8 +47,7 @@
#FROM common/browser.js IMPORT browser
#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/entities.js IMPORT item_id_string, version_string, get_files
#FROM common/misc.js IMPORT sha256_async AS compute_sha256
const coll = new Intl.Collator();
@@ -114,6 +113,19 @@ async function init_work() {
new Promise((...cbs) => [work.resolve_cb, work.reject_cb] = cbs)];
}
+function _make_url_reg(item_type) {
+ return new RegExp(
+ `^https://hydrilla\\.koszko\\.org/schemas/api_${item_type}_description-1\\.([1-9][0-9]*\\.)*schema\\.json$`
+ );
+}
+
+const _regexes = {};
+
+function item_schema_url_regex(item_type) {
+ _regexes[item_type] = _regexes[item_type] || _make_url_reg(item_type);
+ return _regexes[item_type];
+}
+
function InstallView(tab_id, on_view_show, on_view_hide) {
Showable.call(this, on_view_show, on_view_hide);
@@ -191,26 +203,19 @@ function InstallView(tab_id, on_view_show, on_view_hide) {
"Repository's response is not valid JSON :(");
}
- if (!is_valid_version(response.json.api_schema_version)) {
- var bad_api_ver = "";
- } else if (response.json.api_schema_version > [1]) {
- var bad_api_ver =
- ` (${version_string(response.json.api_schema_version)})`;
- } else {
- var bad_api_ver = false;
- }
+ const captype = item_type[0].toUpperCase() + item_type.substring(1);
+ const reg = item_schema_url_regex(item_type);
- if (bad_api_ver !== false) {
- const captype = item_type[0].toUpperCase() + item_type.substring(1);
- const msg = `${captype} ${item_id_string(id, ver)} was served using unsupported Hydrilla API version${bad_api_ver}. You might need to update Haketilo.`;
+ if (!response.json["$schema"]) {
+ const msg = `${captype} ${item_id_string(id, ver)} was served using a nonconforming response format.`;
+ return work.err(null, msg);
+ } else if (!reg.test(response.json["$schema"])) {
+ const msg = `${captype} ${item_id_string(id, ver)} was served using unsupported Hydrilla API version. You might need to update Haketilo.`;
return work.err(null, msg);
}
/* TODO: JSON schema validation should be added here. */
- delete response.json.api_schema_version;
- delete response.json.api_schema_revision;
-
const scripts = item_type === "resource" && response.json.scripts;
const files = response.json.source_copyright.concat(scripts || []);