diff options
author | Wojtek Kosior <koszko@koszko.org> | 2022-02-16 00:55:04 +0100 |
---|---|---|
committer | Wojtek Kosior <koszko@koszko.org> | 2022-02-16 10:12:51 +0100 |
commit | 72553a2d8b5fa094a5edd5e6ec15b5125a052016 (patch) | |
tree | cfbca085fd54ce482561e65726f825c00b2ac795 /html/repo_query.js | |
parent | b47de554fb01b478b09d9d65b5eac4b05fd903fc (diff) | |
download | browser-extension-72553a2d8b5fa094a5edd5e6ec15b5125a052016.tar.gz browser-extension-72553a2d8b5fa094a5edd5e6ec15b5125a052016.zip |
assume and use "$schema" properties in item definitions
Diffstat (limited to 'html/repo_query.js')
-rw-r--r-- | html/repo_query.js | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/html/repo_query.js b/html/repo_query.js index a4b8890..d2f0e9b 100644 --- a/html/repo_query.js +++ b/html/repo_query.js @@ -45,8 +45,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, \ - is_valid_version +#FROM common/entities.js IMPORT item_id_string, version_string #FROM html/install.js IMPORT InstallView const coll = new Intl.Collator(); @@ -69,6 +68,10 @@ 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}); @@ -91,17 +94,10 @@ function RepoEntry(query_view, repo_url) { if ("error_json" in response) throw "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; - } - - if (bad_api_ver !== false) - throw `Results were served using unsupported Hydrilla API version${bad_api_ver}. You might need to update Haketilo.`; + 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."; /* TODO: here we should perform JSON schema validation! */ @@ -114,7 +110,7 @@ function RepoEntry(query_view, repo_url) { try { var results = await query_results(); } catch(e) { - this.info_span.innerText = e; + this.info_div.innerText = e; return; } @@ -122,12 +118,12 @@ function RepoEntry(query_view, repo_url) { if (this.result_entries.length > 0) { this.results_list.classList.remove("hide"); - this.info_span.remove(); + this.info_div.remove(); const to_append = this.result_entries.map(re => re.main_li); this.results_list.append(...to_append); } else { - this.info_span.innerText = "No results :("; + this.info_div.innerText = "No results :("; } } |