aboutsummaryrefslogtreecommitdiff
path: root/html/install.js
diff options
context:
space:
mode:
Diffstat (limited to 'html/install.js')
-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