aboutsummaryrefslogtreecommitdiff
path: root/html
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2022-06-01 14:29:37 +0200
committerWojtek Kosior <koszko@koszko.org>2022-06-01 14:29:37 +0200
commit9bee4afaab8b89613e5e504829bdd4fae204e134 (patch)
treedb8e133b7c61ab7ddf9e4096a391e5fd2965f060 /html
parent6cce03018786fe1f82014f82525770cca43808d8 (diff)
downloadbrowser-extension-9bee4afaab8b89613e5e504829bdd4fae204e134.tar.gz
browser-extension-9bee4afaab8b89613e5e504829bdd4fae204e134.zip
support schema v2 and dependencies on mappings
Diffstat (limited to 'html')
-rw-r--r--html/install.js37
1 files changed, 25 insertions, 12 deletions
diff --git a/html/install.js b/html/install.js
index a066b9b..5fcf879 100644
--- a/html/install.js
+++ b/html/install.js
@@ -49,7 +49,8 @@
#FROM html/DOM_helpers.js IMPORT clone_template, Showable
#FROM common/entities.js IMPORT item_id_string, version_string, get_files
#FROM common/misc.js IMPORT sha256_async AS compute_sha256
-#FROM common/jsonschema.js IMPORT haketilo_validator, haketilo_schemas
+#FROM common/jsonschema.js IMPORT haketilo_validator, haketilo_schemas, \
+ haketilo_schema_name_regex
#FROM html/repo_query_cacher_client.js IMPORT indirect_fetch
@@ -203,21 +204,28 @@ function InstallView(tab_id, on_view_show, on_view_hide) {
const captype = item_type[0].toUpperCase() + item_type.substring(1);
- const $id =
- `https://hydrilla.koszko.org/schemas/api_${item_type}_description-1.0.1.schema.json`;
- const schema = haketilo_schemas[$id];
- const result = haketilo_validator.validate(json, schema);
- if (result.errors.length > 0) {
- const reg = new RegExp(schema.allOf[2].properties.$schema.pattern);
- if (json.$schema && !reg.test(json.$schema)) {
+ const nonconforming_format_error_msg =
+ `${captype} ${item_id_string(id, ver)} was served using a nonconforming response format.`;
+
+ try {
+ const match = haketilo_schema_name_regex.exec(json.$schema);
+ var major_schema_version = match.groups.major;
+
+ if (!["1", "2"].includes(major_schema_version)) {
const msg = `${captype} ${item_id_string(id, ver)} was served using unsupported Hydrilla API version. You might need to update Haketilo.`;
- return work.err(result.errors, msg);
+ return work.err(null, msg);
}
-
- const msg = `${captype} ${item_id_string(id, ver)} was served using a nonconforming response format.`;
- return work.err(result.errors, msg);
+ } catch(e) {
+ return work.err(e, nonconforming_format_error_msg);
}
+ const schema_name = `api_${item_type}_description-${major_schema_version}.schema.json`;
+
+ const schema = haketilo_schemas[schema_name];
+ const result = haketilo_validator.validate(json, schema);
+ if (result.errors.length > 0)
+ return work.err(result.errors, nonconforming_format_error_msg);
+
const scripts = item_type === "resource" && json.scripts;
const files = json.source_copyright.concat(scripts || []);
@@ -229,6 +237,11 @@ function InstallView(tab_id, on_view_show, on_view_hide) {
process_item(work, "resource", res_ref.identifier);
}
+ if (major_schema_version >= 2) {
+ for (const map_ref of (json.required_mappings || []))
+ process_item(work, "mapping", map_ref.identifier);
+ }
+
/*
* At this point we already have JSON definition of the item and we
* triggered processing of its dependencies. We now have to verify if