Rename mod hash field to sha1

The Factorio Mod Portal uses and provides SHA1 hashes of mods, so it
makes sense to align the ModPack and ModInfo structures to sha1 by
renaming the genericly named hash property to sha1.
This commit is contained in:
Hornwitser committed 2022-09-24 21:43:07 +02:00
1 parent bddde30be4
commit 9b4ca86650
9 files changed
+21 -22

No files matched your search

+2 -2
View File
@@ -875,7 +875,7 @@ modPackCommands.add(new libCommand.Command({
if (field === "mods") {
print(`${field}:`);
for (let entry of value) {
print(` ${entry.name} ${entry.version}${entry.hash ? ` (${entry.hash})` : ""}`);
print(` ${entry.name} ${entry.version}${entry.sha1 ? ` (${entry.sha1})` : ""}`);
}
} else if (field === "settings") {
print(`${field}:`);
@@ -958,7 +958,7 @@ function setModPackMods(modPack, mods) {
if (sha1 && !/^[0-9a-f]{40}$/.test(sha1)) {
throw new libErrors.CommandError("sha1 must be a 40 digit lower case hex string");
}
modPack.mods.set(name, { name, version, hash: sha1 ? `sha1:${sha1}` : undefined });
modPack.mods.set(name, { name, version, sha1 });
}
}
+6 -7
View File
@@ -111,10 +111,10 @@ class ModInfo {
size = 0;
/**
* Hash of this mod
* SHA1 hash of this mod
* @type {string=}
*/
hash;
sha1;
/**
* True if this mod has been deleted
@@ -147,7 +147,7 @@ class ModInfo {
...this.infoJsonSchema.properties,
"filename": { type: "string" },
"size": { type: "integer" },
"hash": { type: "string" },
"sha1": { type: "string" },
"is_deleted": { type: "boolean" },
},
};
@@ -169,7 +169,7 @@ class ModInfo {
// Additional data
if (json.filename) { this.filename = json.filename; }
if (json.size) { this.size = json.size; }
if (json.hash) { this.hash = json.hash; }
if (json.sha1) { this.sha1 = json.sha1; }
if (json.is_deleted) { this.isDeleted = json.is_deleted; }
}
@@ -189,7 +189,7 @@ class ModInfo {
}
if (this.filename) { json.filename = this.filename; }
if (this.size) { json.size = this.size; }
if (this.hash) { json.hash = this.hash; }
if (this.sha1) { json.sha1 = this.sha1; }
if (this.isDeleted) { json.is_deleted = this.isDeleted; }
return json;
}
@@ -215,13 +215,12 @@ class ModInfo {
throw new Error("Mod's info.json is not valid");
}
let hash = `sha1:${await libHash.hashFile(modPath)}`;
return new this({
...modInfo,
filename: path.basename(modPath),
size: (await fs.stat(modPath)).size,
hash,
sha1: await libHash.hashFile(modPath),
is_deleted: false,
});
}
+3 -3
View File
@@ -28,7 +28,7 @@ const ModSettingsJsonSchema = {
* @typedef {object} module:lib/data/ModPack~ModRecord
* @property {string} name - name of the mod.
* @property {string} version - version of the mod.
* @property {string} hash - hash of the zip file.
* @property {string} sha1 - SHA1 hash of the zip file.
*/
const ModRecordJsonSchema = {
type: "object",
@@ -37,7 +37,7 @@ const ModRecordJsonSchema = {
properties: {
"name": { type: "string" },
"version": { type: "string" },
"hash": { type: "string" },
"sha1": { type: "string" },
},
};
@@ -176,7 +176,7 @@ class ModPack {
if (json.mods && !includeHash) {
json.mods = json.mods.map(m => {
m = { ...m };
delete m.hash;
delete m.sha1;
return m;
});
}
+1 -1
View File
@@ -576,7 +576,7 @@ class ControlConnection extends BaseConnection {
// dependencies
filename: "word",
// size
hash: "word",
sha1: "word",
});
let factorioVersion = message.data.factorio_version;
@@ -33,7 +33,7 @@ export default function ModDetails(props) {
{mod.size !== undefined
&& <Descriptions.Item label="Size">{libHelpers.formatBytes(mod.size)}</Descriptions.Item>
}
{mod.hash && <Descriptions.Item label="Hash" span={2}>{mod.hash}</Descriptions.Item>}
{mod.sha1 && <Descriptions.Item label="SHA1" span={2}>{mod.sha1}</Descriptions.Item>}
{mod.dependencies && mod.dependencies.length
&& <Descriptions.Item label="Dependencies" span={2}>
{mod.dependencies
@@ -95,7 +95,7 @@ function SearchModsTable(props) {
props.onChange({
type: "mods.set",
name: mod.name,
value: { name: mod.name, version: mod.version, hash: mod.hash },
value: { name: mod.name, version: mod.version, sha1: mod.sha1 },
});
}}
>{props.modPack.mods.has(mod.name) ? "change" : "add"}</Typography.Link>
@@ -107,7 +107,7 @@ function SearchModsTable(props) {
props.onChange({
type: "mods.delete",
name: mod.name,
value: { name: mod.name, version: mod.version, hash: mod.hash },
value: { name: mod.name, version: mod.version, sha1: mod.sha1 },
});
}}
>remove</Typography.Link>
+1 -1
View File
@@ -917,7 +917,7 @@ describe("Integration of Clusterio", function() {
"dependencies:\n" +
"filename: empty_mod_1.0.0.zip\n" +
`size: ${stat.size}\n` +
`hash: sha1:${hash}\n`,
`sha1: ${hash}\n`,
);
});
});
+3 -3
View File
@@ -34,7 +34,7 @@ describe("lib/data/ModInfo", function() {
check(new ModInfo({ dependencies: ["UltraMod", "SuperLib >= 1.00", "! bad-mod"] }));
check(new ModInfo({ filename: "MyMod_1.0.0.zip" }));
check(new ModInfo({ size: 1024 }));
check(new ModInfo({ hash: "sha5:verified-as-MyMod" }));
check(new ModInfo({ sha1: "verified-as-MyMod" }));
check(new ModInfo({ is_deleted: true }));
// All at once
@@ -50,7 +50,7 @@ describe("lib/data/ModInfo", function() {
dependencies: ["UltraMod", "SuperLib >= 1.00", "! bad-mod"],
filename: "MyMod_1.0.0.zip",
size: 1024,
hash: "sha5:verified-as-MyMod",
sha1: "verified-as-MyMod",
is_deleted: true,
}));
});
@@ -93,7 +93,7 @@ describe("lib/data/ModInfo", function() {
dependencies: [],
filename: "empty_mod_1.0.0.zip",
size: stat.size,
hash: `sha1:${hash}`,
sha1: hash,
})
);
});
+2 -2
View File
@@ -27,7 +27,7 @@ describe("lib/data/ModPack", function() {
check(new ModPack({ factorio_version: "2.0" }));
check(new ModPack({ mods: [
{ name: "subspace_storage", version: "1.99.8" },
{ name: "clusterio_lib", version: "0.1.2", hash: "sha1:012345abcd" },
{ name: "clusterio_lib", version: "0.1.2", sha1: "012345abcd" },
]}));
check(new ModPack({ settings: {
"startup": {
@@ -47,7 +47,7 @@ describe("lib/data/ModPack", function() {
factorio_version: "2.0",
mods: [
{ name: "subspace_storage", version: "1.99.8" },
{ name: "clusterio_lib", version: "0.1.2", hash: "sha1:012345abcd" },
{ name: "clusterio_lib", version: "0.1.2", sha1: "012345abcd" },
],
settings: {
"startup": {