diff options
Diffstat (limited to 'html/repo_query.js')
-rw-r--r-- | html/repo_query.js | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/html/repo_query.js b/html/repo_query.js index d2f0e9b..61f4b10 100644 --- a/html/repo_query.js +++ b/html/repo_query.js @@ -43,10 +43,11 @@ #IMPORT common/indexeddb.js AS haketilodb -#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 -#FROM html/install.js IMPORT InstallView +#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 +#FROM html/install.js IMPORT InstallView +#FROM common/jsonschema.js IMPORT haketilo_validator, haketilo_schemas const coll = new Intl.Collator(); @@ -68,10 +69,6 @@ function ResultEntry(repo_entry, mapping_ref) { this.install_but.addEventListener("click", cb); } -const query_schema_url_regex = new RegExp( - "^https://hydrilla\\.koszko\\.org/schemas/api_query_result-1\\.([1-9][0-9]*\\.)*schema\\.json$" -); - function RepoEntry(query_view, repo_url) { Object.assign(this, clone_template("repo_query_single_repo")); Object.assign(this, {query_view, repo_url}); @@ -94,12 +91,19 @@ function RepoEntry(query_view, repo_url) { if ("error_json" in response) throw "Repository's response is not valid JSON :("; - if (!response.json["$schema"]) - throw "Results were served using a nonconforming response format."; - if (!query_schema_url_regex.test(response.json["$schema"])) - throw "Results were served using unsupported Hydrilla API version. You might need to update Haketilo."; + const $id = + `https://hydrilla.koszko.org/schemas/api_query_result-1.0.1.schema.json`; + const schema = haketilo_schemas[$id]; + const result = haketilo_validator.validate(response.json, schema); + if (result.errors.length > 0) { + console.error(result.errors); + + const reg = new RegExp(schema.properties.$schema.pattern); + if (response.json.$schema && !reg.test(response.json.$schema)) + throw "Results were served using unsupported Hydrilla API version. You might need to update Haketilo."; - /* TODO: here we should perform JSON schema validation! */ + throw "Results were served using a nonconforming response format."; + } return response.json.mappings; } |