*Remove use of dynamic imports
This commit is contained in:
parent
5362d83af6
commit
4a4b46df5b
14
src/dht.ts
14
src/dht.ts
|
@ -5,7 +5,11 @@
|
|||
import DHT from "@hyperswarm/dht";
|
||||
import config from "./config.js";
|
||||
import { errorExit } from "./error.js";
|
||||
import { dynImport } from "./util.js";
|
||||
import {
|
||||
deriveMyskyRootKeypair,
|
||||
seedPhraseToSeed,
|
||||
validSeedPhrase,
|
||||
} from "libskynet";
|
||||
|
||||
let node: {
|
||||
ready: () => any;
|
||||
|
@ -16,14 +20,6 @@ let node: {
|
|||
let server: any;
|
||||
|
||||
async function start() {
|
||||
const {
|
||||
deriveMyskyRootKeypair,
|
||||
// @ts-ignore
|
||||
Ed25519Keypair,
|
||||
seedPhraseToSeed,
|
||||
validSeedPhrase,
|
||||
} = await dynImport("libskynet");
|
||||
|
||||
const seed = config.str("seed");
|
||||
|
||||
let err = validSeedPhrase(seed);
|
||||
|
|
14
src/dns.ts
14
src/dns.ts
|
@ -4,14 +4,13 @@ import { Buffer } from "buffer";
|
|||
import { pack } from "msgpackr";
|
||||
import config from "./config.js";
|
||||
import log from "loglevel";
|
||||
import { dynImport } from "./util.js";
|
||||
import fetch from "node-fetch";
|
||||
import { overwriteRegistryEntry } from "libskynetnode";
|
||||
import type { DnsProvider } from "@lumeweb/relay-types";
|
||||
// @ts-ignore
|
||||
import { hashDataKey } from "@lumeweb/kernel-utils";
|
||||
|
||||
let activeIp: string;
|
||||
let fetch: typeof import("node-fetch").default;
|
||||
let overwriteRegistryEntry: typeof import("libskynetnode").overwriteRegistryEntry;
|
||||
let hashDataKey: typeof import("@lumeweb/kernel-utils").hashDataKey;
|
||||
|
||||
const REGISTRY_NODE_KEY = "lumeweb-dht-node";
|
||||
|
||||
let dnsProvider: DnsProvider = async (ip) => {};
|
||||
|
@ -37,11 +36,6 @@ async function ipUpdate() {
|
|||
}
|
||||
|
||||
export async function start() {
|
||||
fetch = (await dynImport("node-fetch")).default;
|
||||
overwriteRegistryEntry = (await dynImport("libskynetnode"))
|
||||
.overwriteRegistryEntry;
|
||||
hashDataKey = (await dynImport("@lumeweb/kernel-utils")).hashDataKey;
|
||||
|
||||
const dht = (await getDHT()) as any;
|
||||
|
||||
await ipUpdate();
|
||||
|
|
71
src/file.ts
71
src/file.ts
|
@ -1,67 +1,40 @@
|
|||
import type { Err, progressiveFetchResult } from "libskynet";
|
||||
// @ts-ignore
|
||||
import { SkynetClient } from "@skynetlabs/skynet-nodejs";
|
||||
import { dynImport } from "./util.js";
|
||||
import type {
|
||||
IndependentFileSmall,
|
||||
IndependentFileSmallMetadata,
|
||||
} from "@lumeweb/relay-types";
|
||||
import {
|
||||
addContextToErr,
|
||||
blake2b,
|
||||
bufToHex,
|
||||
ed25519Sign,
|
||||
encodePrefixedBytes,
|
||||
encodeU64,
|
||||
defaultPortalList,
|
||||
skylinkToResolverEntryData,
|
||||
encryptFileSmall,
|
||||
decryptFileSmall,
|
||||
entryIDToSkylink,
|
||||
deriveRegistryEntryID,
|
||||
taggedRegistryEntryKeys,
|
||||
namespaceInode,
|
||||
deriveChildSeed,
|
||||
bufToB64,
|
||||
} from "libskynet";
|
||||
|
||||
import { readRegistryEntry, progressiveFetch, upload } from "libskynetnode";
|
||||
|
||||
const ERR_NOT_EXISTS = "DNE";
|
||||
const STD_FILENAME = "file";
|
||||
|
||||
let addContextToErr: typeof import("libskynet").addContextToErr,
|
||||
blake2b: typeof import("libskynet").blake2b,
|
||||
bufToHex: typeof import("libskynet").bufToHex,
|
||||
ed25519Sign: typeof import("libskynet").ed25519Sign,
|
||||
encodePrefixedBytes: typeof import("libskynet").encodePrefixedBytes,
|
||||
encodeU64: typeof import("libskynet").encodeU64,
|
||||
progressiveFetch: typeof import("libskynet").progressiveFetch,
|
||||
defaultPortalList: typeof import("libskynet").defaultPortalList,
|
||||
readRegistryEntry: typeof import("libskynetnode/dist/registryread.js").readRegistryEntry,
|
||||
upload: typeof import("libskynetnode").upload,
|
||||
skylinkToResolverEntryData: typeof import("libskynet").skylinkToResolverEntryData,
|
||||
encryptFileSmall: typeof import("libskynet").encryptFileSmall,
|
||||
deriveChildSeed: typeof import("libskynet").deriveChildSeed,
|
||||
bufToB64: typeof import("libskynet").bufToB64,
|
||||
decryptFileSmall: typeof import("libskynet").decryptFileSmall,
|
||||
entryIDToSkylink: typeof import("libskynet").entryIDToSkylink,
|
||||
deriveRegistryEntryID: typeof import("libskynet").deriveRegistryEntryID,
|
||||
taggedRegistryEntryKeys: typeof import("libskynet").taggedRegistryEntryKeys,
|
||||
namespaceInode: typeof import("libskynet").namespaceInode;
|
||||
|
||||
async function loadLibs() {
|
||||
const libskynet = await dynImport("libskynet");
|
||||
addContextToErr = libskynet.addContextToErr;
|
||||
bufToHex = libskynet.bufToHex;
|
||||
ed25519Sign = libskynet.ed25519Sign;
|
||||
encodePrefixedBytes = libskynet.encodePrefixedBytes;
|
||||
encodeU64 = libskynet.encodeU64;
|
||||
defaultPortalList = libskynet.defaultPortalList;
|
||||
skylinkToResolverEntryData = libskynet.skylinkToResolverEntryData;
|
||||
encryptFileSmall = libskynet.encryptFileSmall;
|
||||
deriveChildSeed = libskynet.deriveChildSeed;
|
||||
bufToB64 = libskynet.bufToB64;
|
||||
decryptFileSmall = libskynet.decryptFileSmall;
|
||||
entryIDToSkylink = libskynet.entryIDToSkylink;
|
||||
deriveRegistryEntryID = libskynet.deriveRegistryEntryID;
|
||||
taggedRegistryEntryKeys = libskynet.taggedRegistryEntryKeys;
|
||||
namespaceInode = libskynet.namespaceInode;
|
||||
|
||||
progressiveFetch = (await dynImport("libskynetnode/dist/progressivefetch.js"))
|
||||
.progressiveFetch;
|
||||
readRegistryEntry = (await dynImport("libskynetnode/dist/registryread.js"))
|
||||
.readRegistryEntry;
|
||||
upload = (await dynImport("libskynetnode")).upload;
|
||||
}
|
||||
|
||||
async function overwriteRegistryEntry(
|
||||
keypair: any,
|
||||
datakey: Uint8Array,
|
||||
data: Uint8Array,
|
||||
revision: bigint
|
||||
): Promise<null> {
|
||||
await loadLibs();
|
||||
return new Promise((resolve, reject) => {
|
||||
if (data.length > 86) {
|
||||
reject("provided data is too large to fit in a registry entry");
|
||||
|
@ -122,7 +95,6 @@ async function overwriteRegistryEntry(
|
|||
});
|
||||
}
|
||||
async function verifyRegistryWrite(response: Response): Promise<Err> {
|
||||
await loadLibs();
|
||||
return new Promise((resolve) => {
|
||||
if (!("status" in response)) {
|
||||
resolve("response did not contain a status");
|
||||
|
@ -141,7 +113,6 @@ async function createIndependentFileSmall(
|
|||
userInode: string,
|
||||
fileData: Uint8Array
|
||||
): Promise<[IndependentFileSmall, Err]> {
|
||||
await loadLibs();
|
||||
return new Promise(async (resolve) => {
|
||||
let [inode, errNI] = namespaceInode("IndependentFileSmall", userInode);
|
||||
if (errNI !== null) {
|
||||
|
@ -275,7 +246,6 @@ async function openIndependentFileSmall(
|
|||
seed: Uint8Array,
|
||||
userInode: string
|
||||
): Promise<[IndependentFileSmall, Err]> {
|
||||
await loadLibs();
|
||||
return new Promise(async (resolve) => {
|
||||
let [inode, errNI] = namespaceInode("IndependentFileSmall", userInode);
|
||||
if (errNI !== null) {
|
||||
|
@ -378,7 +348,6 @@ async function overwriteIndependentFileSmall(
|
|||
file: IndependentFileSmall,
|
||||
newData: Uint8Array
|
||||
): Promise<Err> {
|
||||
await loadLibs();
|
||||
return new Promise(async (resolve) => {
|
||||
// Create a new metadata for the file based on the current file
|
||||
// metadata. Need to update the largest historic size.
|
||||
|
|
|
@ -13,8 +13,8 @@ import {
|
|||
setSslContext,
|
||||
} from "./ssl.js";
|
||||
import log from "loglevel";
|
||||
import { getSeed, loadUtilFunctions } from "./util.js";
|
||||
import { getRouter, resetRouter, setRouter } from "./relay";
|
||||
import { getSeed } from "./util.js";
|
||||
import { getRouter, resetRouter, setRouter } from "./relay.js";
|
||||
import {
|
||||
createIndependentFileSmall,
|
||||
openIndependentFileSmall,
|
||||
|
@ -118,7 +118,6 @@ export function getPluginAPI(): PluginApiManager {
|
|||
}
|
||||
|
||||
export async function loadPlugins() {
|
||||
await loadUtilFunctions();
|
||||
for (const plugin of config.array("plugins")) {
|
||||
await getPluginAPI().loadPlugin(plugin);
|
||||
}
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
import config from "./config";
|
||||
|
||||
let seedPhraseToSeed: typeof import("libskynet").seedPhraseToSeed;
|
||||
|
||||
export async function loadUtilFunctions() {
|
||||
seedPhraseToSeed = (await dynImport("libskynet")).seedPhraseToSeed;
|
||||
}
|
||||
import { seedPhraseToSeed } from "libskynet";
|
||||
|
||||
export function dynImport(module: string) {
|
||||
return Function(`return import("${module}")`)() as Promise<any>;
|
||||
|
|
Loading…
Reference in New Issue