refactor: errtuples are no longer used, and switch to using the CID class
This commit is contained in:
parent
3eda1bbc37
commit
e8b3e03e7b
32
src/index.ts
32
src/index.ts
|
@ -5,8 +5,6 @@ import * as process from "process";
|
||||||
import fs from "fs/promises";
|
import fs from "fs/promises";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import {
|
import {
|
||||||
encodeRegistryCid,
|
|
||||||
encodeRegistryValue,
|
|
||||||
equalBytes,
|
equalBytes,
|
||||||
hexToBytes,
|
hexToBytes,
|
||||||
maybeInitDefaultPortals,
|
maybeInitDefaultPortals,
|
||||||
|
@ -22,6 +20,7 @@ import { HDKey } from "ed25519-keygen/hdkey";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
BOOTSTRAP_NODES,
|
BOOTSTRAP_NODES,
|
||||||
|
CID,
|
||||||
createKeyPair,
|
createKeyPair,
|
||||||
createNode,
|
createNode,
|
||||||
S5NodeConfig,
|
S5NodeConfig,
|
||||||
|
@ -108,13 +107,16 @@ maybeInitDefaultPortals();
|
||||||
|
|
||||||
const fd = await fs.open(file as string);
|
const fd = await fs.open(file as string);
|
||||||
|
|
||||||
const [cid, err] = await uploadObject(
|
let cid;
|
||||||
|
|
||||||
|
try {
|
||||||
|
cid = await uploadObject(
|
||||||
fd.createReadStream(),
|
fd.createReadStream(),
|
||||||
BigInt((await fd.stat()).size),
|
BigInt((await fd.stat()).size),
|
||||||
);
|
);
|
||||||
|
} catch (e) {
|
||||||
if (err) {
|
console.error("Failed to publish: ", e.message);
|
||||||
console.error("Failed to publish: ", err);
|
process.exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
|
@ -174,10 +176,12 @@ await peerDefer.promise;
|
||||||
revision = ret.revision + 1;
|
revision = ret.revision + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
let [newEntry, err] = encodeRegistryValue(cid);
|
let newEntry;
|
||||||
|
try {
|
||||||
if (err) {
|
newEntry = CID.decode(cid).toRegistryEntry();
|
||||||
throw new Error(err);
|
} catch (e) {
|
||||||
|
console.error("Failed to publish: ", e.message);
|
||||||
|
process.exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!equalBytes(ret?.data ?? new Uint8Array(), newEntry)) {
|
if (!equalBytes(ret?.data ?? new Uint8Array(), newEntry)) {
|
||||||
|
@ -193,10 +197,12 @@ await peerDefer.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
let resolverCid;
|
let resolverCid;
|
||||||
[resolverCid, err] = encodeRegistryCid(sre.pk);
|
|
||||||
|
|
||||||
if (err) {
|
try {
|
||||||
throw new Error(err);
|
resolverCid = CID.fromRegistryPublicKey(sre.pk);
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Failed to publish: ", e.message);
|
||||||
|
process.exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
|
|
Loading…
Reference in New Issue