Revision 72553a2d
Added by koszko over 1 year ago
html/install.js | ||
---|---|---|
47 | 47 |
|
48 | 48 |
#FROM common/browser.js IMPORT browser |
49 | 49 |
#FROM html/DOM_helpers.js IMPORT clone_template, Showable |
50 |
#FROM common/entities.js IMPORT item_id_string, version_string, get_files, \ |
|
51 |
is_valid_version |
|
50 |
#FROM common/entities.js IMPORT item_id_string, version_string, get_files |
|
52 | 51 |
#FROM common/misc.js IMPORT sha256_async AS compute_sha256 |
53 | 52 |
|
54 | 53 |
const coll = new Intl.Collator(); |
... | ... | |
114 | 113 |
new Promise((...cbs) => [work.resolve_cb, work.reject_cb] = cbs)]; |
115 | 114 |
} |
116 | 115 |
|
116 |
function _make_url_reg(item_type) { |
|
117 |
return new RegExp( |
|
118 |
`^https://hydrilla\\.koszko\\.org/schemas/api_${item_type}_description-1\\.([1-9][0-9]*\\.)*schema\\.json$` |
|
119 |
); |
|
120 |
} |
|
121 |
|
|
122 |
const _regexes = {}; |
|
123 |
|
|
124 |
function item_schema_url_regex(item_type) { |
|
125 |
_regexes[item_type] = _regexes[item_type] || _make_url_reg(item_type); |
|
126 |
return _regexes[item_type]; |
|
127 |
} |
|
128 |
|
|
117 | 129 |
function InstallView(tab_id, on_view_show, on_view_hide) { |
118 | 130 |
Showable.call(this, on_view_show, on_view_hide); |
119 | 131 |
|
... | ... | |
191 | 203 |
"Repository's response is not valid JSON :("); |
192 | 204 |
} |
193 | 205 |
|
194 |
if (!is_valid_version(response.json.api_schema_version)) { |
|
195 |
var bad_api_ver = ""; |
|
196 |
} else if (response.json.api_schema_version > [1]) { |
|
197 |
var bad_api_ver = |
|
198 |
` (${version_string(response.json.api_schema_version)})`; |
|
199 |
} else { |
|
200 |
var bad_api_ver = false; |
|
201 |
} |
|
206 |
const captype = item_type[0].toUpperCase() + item_type.substring(1); |
|
207 |
const reg = item_schema_url_regex(item_type); |
|
202 | 208 |
|
203 |
if (bad_api_ver !== false) { |
|
204 |
const captype = item_type[0].toUpperCase() + item_type.substring(1); |
|
205 |
const msg = `${captype} ${item_id_string(id, ver)} was served using unsupported Hydrilla API version${bad_api_ver}. You might need to update Haketilo.`; |
|
209 |
if (!response.json["$schema"]) { |
|
210 |
const msg = `${captype} ${item_id_string(id, ver)} was served using a nonconforming response format.`; |
|
211 |
return work.err(null, msg); |
|
212 |
} else if (!reg.test(response.json["$schema"])) { |
|
213 |
const msg = `${captype} ${item_id_string(id, ver)} was served using unsupported Hydrilla API version. You might need to update Haketilo.`; |
|
206 | 214 |
return work.err(null, msg); |
207 | 215 |
} |
208 | 216 |
|
209 | 217 |
/* TODO: JSON schema validation should be added here. */ |
210 | 218 |
|
211 |
delete response.json.api_schema_version; |
|
212 |
delete response.json.api_schema_revision; |
|
213 |
|
|
214 | 219 |
const scripts = item_type === "resource" && response.json.scripts; |
215 | 220 |
const files = response.json.source_copyright.concat(scripts || []); |
216 | 221 |
|
Also available in: Unified diff
assume and use "$schema" properties in item definitions