Remove duplicate code

This commit is contained in:
2026-10-13 11:57:43 -03:00
parent dfc6a6d77b
commit 5165698fe3
50 changed files with 307 additions and 812 deletions
+4 -8
View File
@@ -7,6 +7,7 @@ import { join } from "@std/path";
import { type Bmod, BMOD_EXTENSION, client_copy, read_bmod, write_bmod } from "$/common/bmod.ts";
import { check_references, load_order, type LoadedMod } from "$/common/mod_check.ts";
import type { ModListing } from "$/common/mod_loader.ts";
import { sha256 } from "$/common/utils.ts";
export interface ServerMod {
bmod: Bmod;
@@ -74,7 +75,7 @@ export async function load_bmods(dir: string, engine_textures: Iterable<string>)
return await Promise.all(ordered.map(async (mod) => {
const bmod = by_id.get(mod.id)!.bmod;
const client_bytes = write_bmod(client_copy(bmod));
const sha256 = await hex_sha256(client_bytes);
const hash = await sha256(client_bytes);
return {
bmod,
client_bytes,
@@ -82,8 +83,8 @@ export async function load_bmods(dir: string, engine_textures: Iterable<string>)
id: bmod.manifest.id,
name: bmod.manifest.name,
version: bmod.manifest.version,
sha256,
file: `mods/${sha256}${BMOD_EXTENSION}`,
sha256: hash,
file: `mods/${hash}${BMOD_EXTENSION}`,
size: client_bytes.length,
...(bmod.manifest.engine_access ? { engine_access: true } : {}),
},
@@ -121,8 +122,3 @@ function as_loaded_mod(file: string, bmod: Bmod): LoadedMod {
texture_json: new Map(bmod.texture_json),
};
}
async function hex_sha256(bytes: Uint8Array<ArrayBuffer>) {
const digest = await crypto.subtle.digest("SHA-256", bytes);
return [...new Uint8Array(digest)].map((b) => b.toString(16).padStart(2, "0")).join("");
}