Revision 72553a2d
Added by koszko over 1 year ago
| html/repo_query.js | ||
|---|---|---|
| 45 | 45 |
|
| 46 | 46 |
#FROM common/browser.js IMPORT browser |
| 47 | 47 |
#FROM html/DOM_helpers.js IMPORT clone_template, Showable |
| 48 |
#FROM common/entities.js IMPORT item_id_string, version_string, \ |
|
| 49 |
is_valid_version |
|
| 48 |
#FROM common/entities.js IMPORT item_id_string, version_string |
|
| 50 | 49 |
#FROM html/install.js IMPORT InstallView |
| 51 | 50 |
|
| 52 | 51 |
const coll = new Intl.Collator(); |
| ... | ... | |
| 69 | 68 |
this.install_but.addEventListener("click", cb);
|
| 70 | 69 |
} |
| 71 | 70 |
|
| 71 |
const query_schema_url_regex = new RegExp( |
|
| 72 |
"^https://hydrilla\\.koszko\\.org/schemas/api_query_result-1\\.([1-9][0-9]*\\.)*schema\\.json$" |
|
| 73 |
); |
|
| 74 |
|
|
| 72 | 75 |
function RepoEntry(query_view, repo_url) {
|
| 73 | 76 |
Object.assign(this, clone_template("repo_query_single_repo"));
|
| 74 | 77 |
Object.assign(this, {query_view, repo_url});
|
| ... | ... | |
| 91 | 94 |
if ("error_json" in response)
|
| 92 | 95 |
throw "Repository's response is not valid JSON :(";
|
| 93 | 96 |
|
| 94 |
if (!is_valid_version(response.json.api_schema_version)) {
|
|
| 95 |
var bad_api_ver = ""; |
|
| 96 |
} else if (response.json.api_schema_version > [1]) {
|
|
| 97 |
var bad_api_ver = |
|
| 98 |
` (${version_string(response.json.api_schema_version)})`;
|
|
| 99 |
} else {
|
|
| 100 |
var bad_api_ver = false; |
|
| 101 |
} |
|
| 102 |
|
|
| 103 |
if (bad_api_ver !== false) |
|
| 104 |
throw `Results were served using unsupported Hydrilla API version${bad_api_ver}. You might need to update Haketilo.`;
|
|
| 97 |
if (!response.json["$schema"]) |
|
| 98 |
throw "Results were served using a nonconforming response format."; |
|
| 99 |
if (!query_schema_url_regex.test(response.json["$schema"])) |
|
| 100 |
throw "Results were served using unsupported Hydrilla API version. You might need to update Haketilo."; |
|
| 105 | 101 |
|
| 106 | 102 |
/* TODO: here we should perform JSON schema validation! */ |
| 107 | 103 |
|
| ... | ... | |
| 114 | 110 |
try {
|
| 115 | 111 |
var results = await query_results(); |
| 116 | 112 |
} catch(e) {
|
| 117 |
this.info_span.innerText = e;
|
|
| 113 |
this.info_div.innerText = e;
|
|
| 118 | 114 |
return; |
| 119 | 115 |
} |
| 120 | 116 |
|
| ... | ... | |
| 122 | 118 |
|
| 123 | 119 |
if (this.result_entries.length > 0) {
|
| 124 | 120 |
this.results_list.classList.remove("hide");
|
| 125 |
this.info_span.remove();
|
|
| 121 |
this.info_div.remove();
|
|
| 126 | 122 |
|
| 127 | 123 |
const to_append = this.result_entries.map(re => re.main_li); |
| 128 | 124 |
this.results_list.append(...to_append); |
| 129 | 125 |
} else {
|
| 130 |
this.info_span.innerText = "No results :(";
|
|
| 126 |
this.info_div.innerText = "No results :(";
|
|
| 131 | 127 |
} |
| 132 | 128 |
} |
| 133 | 129 |
|
Also available in: Unified diff
assume and use "$schema" properties in item definitions