Revision 1c65dd5c
Added by koszko over 1 year ago
| html/install.js | ||
|---|---|---|
| 49 | 49 |
#FROM html/DOM_helpers.js IMPORT clone_template, Showable |
| 50 | 50 |
#FROM common/entities.js IMPORT item_id_string, version_string, get_files, \ |
| 51 | 51 |
is_valid_version |
| 52 |
#FROM common/misc.js IMPORT sha256_async AS sha256 |
|
| 52 |
#FROM common/misc.js IMPORT sha256_async AS compute_sha256
|
|
| 53 | 53 |
|
| 54 | 54 |
const coll = new Intl.Collator(); |
| 55 | 55 |
|
| ... | ... | |
| 134 | 134 |
/* Make a link to view a file from the repository. */ |
| 135 | 135 |
const make_file_link = (preview_ctx, file_ref) => {
|
| 136 | 136 |
const a = document.createElement("a");
|
| 137 |
a.href = `${this.repo_url}file/${file_ref.hash_key}`;
|
|
| 137 |
a.href = `${this.repo_url}file/sha256/${file_ref.sha256}`;
|
|
| 138 | 138 |
a.innerText = file_ref.file; |
| 139 | 139 |
|
| 140 | 140 |
return a; |
| ... | ... | |
| 213 | 213 |
|
| 214 | 214 |
const files = response.json.source_copyright |
| 215 | 215 |
.concat(item_type === "resource" ? response.json.scripts : []); |
| 216 |
for (const file of files) {
|
|
| 217 |
file.hash_key = `sha256-${file.sha256}`;
|
|
| 218 |
delete file.sha256; |
|
| 219 |
} |
|
| 220 | 216 |
|
| 221 | 217 |
if (item_type === "mapping") {
|
| 222 | 218 |
for (const res_ref of Object.values(response.json.payloads)) |
| ... | ... | |
| 294 | 290 |
dialog.close(this.dialog_ctx); |
| 295 | 291 |
} |
| 296 | 292 |
|
| 297 |
const process_file = async (work, hash_key) => {
|
|
| 293 |
const process_file = async (work, sha256) => {
|
|
| 298 | 294 |
if (!work.is_ok) |
| 299 | 295 |
return; |
| 300 | 296 |
|
| ... | ... | |
| 302 | 298 |
|
| 303 | 299 |
try {
|
| 304 | 300 |
var file_uses = await haketilodb.idb_get(work.file_uses_transaction, |
| 305 |
"file_uses", hash_key);
|
|
| 301 |
"file_uses", sha256);
|
|
| 306 | 302 |
if (!work.is_ok) |
| 307 | 303 |
return; |
| 308 | 304 |
} catch(e) {
|
| ... | ... | |
| 311 | 307 |
} |
| 312 | 308 |
|
| 313 | 309 |
if (!file_uses) {
|
| 314 |
const url = `${this.repo_url}file/${hash_key}`;
|
|
| 310 |
const url = `${this.repo_url}file/sha256/${sha256}`;
|
|
| 315 | 311 |
|
| 316 | 312 |
try {
|
| 317 | 313 |
var response = await fetch(url); |
| ... | ... | |
| 336 | 332 |
return work.err(e, msg); |
| 337 | 333 |
} |
| 338 | 334 |
|
| 339 |
const digest = await sha256(text); |
|
| 335 |
const digest = await compute_sha256(text);
|
|
| 340 | 336 |
if (!work.is_ok) |
| 341 | 337 |
return; |
| 342 |
if (`sha256-${digest}` !== hash_key) {
|
|
| 338 |
if (digest !== sha256) {
|
|
| 343 | 339 |
const msg = `${url} served a file with different SHA256 cryptographic sum :(`;
|
| 344 | 340 |
return work.err(null, msg); |
| 345 | 341 |
} |
| 346 | 342 |
|
| 347 |
work.result.push([hash_key, text]);
|
|
| 343 |
work.result.push([sha256, text]);
|
|
| 348 | 344 |
} |
| 349 | 345 |
|
| 350 | 346 |
if (--work.waiting === 0) |
| ... | ... | |
| 359 | 355 |
|
| 360 | 356 |
for (const item_def of item_defs) {
|
| 361 | 357 |
for (const file of get_files(item_def)) {
|
| 362 |
if (!processed_files.has(file.hash_key)) {
|
|
| 363 |
processed_files.add(file.hash_key);
|
|
| 364 |
process_file(work, file.hash_key);
|
|
| 358 |
if (!processed_files.has(file.sha256)) {
|
|
| 359 |
processed_files.add(file.sha256);
|
|
| 360 |
process_file(work, file.sha256);
|
|
| 365 | 361 |
} |
| 366 | 362 |
} |
| 367 | 363 |
} |
| ... | ... | |
| 379 | 375 |
|
| 380 | 376 |
try {
|
| 381 | 377 |
var files = (await get_missing_files(item_defs)) |
| 382 |
.reduce((ac, [hk, txt]) => Object.assign(ac, {[hk]: txt}), {});
|
|
| 378 |
.reduce((ac, [h, txt]) => Object.assign(ac, {[h]: txt}), {});
|
|
| 383 | 379 |
} catch(e) {
|
| 384 | 380 |
var dialog_prom = dialog.error(this.dialog_ctx, e); |
| 385 | 381 |
} |
| 386 | 382 |
|
| 387 | 383 |
if (files !== undefined) {
|
| 388 |
const data = {files};
|
|
| 384 |
const data = {file: {sha256: files}};
|
|
| 389 | 385 |
const names = [["mappings", "mapping"], ["resources", "resource"]]; |
| 390 | 386 |
|
| 391 | 387 |
for (const [set_name, type] of names) {
|
Also available in: Unified diff
adapt to changes in file path format
From now on we assume Hydrilla serves file contents at 'file/sha256/' instead of 'file/sha256-'.
With this commit we also stop using the "hash_key" property internally.