fix: ensure db path exists, create if not
This commit is contained in:
parent
908aacdae6
commit
632eb1351c
14
src/index.ts
14
src/index.ts
|
@ -4,14 +4,20 @@ import { Level } from "level";
|
||||||
import { PROTOCOL } from "./constants.js";
|
import { PROTOCOL } from "./constants.js";
|
||||||
import HyperTransportPeer from "./hyperTransport.js";
|
import HyperTransportPeer from "./hyperTransport.js";
|
||||||
import { NodeId } from "@lumeweb/libs5";
|
import { NodeId } from "@lumeweb/libs5";
|
||||||
import { string } from "micro-packed";
|
import * as fs from "fs/promises";
|
||||||
|
|
||||||
const plugin = {
|
const plugin = {
|
||||||
name: "s5",
|
name: "s5",
|
||||||
async plugin(api: PluginAPI) {
|
async plugin(api: PluginAPI) {
|
||||||
const db = new Level<string, Uint8Array>(
|
const dbPath = api.pluginConfig.str("db") as string;
|
||||||
api.pluginConfig.str("db") as string,
|
|
||||||
);
|
try {
|
||||||
|
await fs.access(dbPath);
|
||||||
|
} catch {
|
||||||
|
await fs.mkdir(dbPath, { recursive: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
const db = new Level<string, Uint8Array>(dbPath);
|
||||||
await db.open();
|
await db.open();
|
||||||
let config = {
|
let config = {
|
||||||
keyPair: createKeyPair(api.identity.publicKeyRaw),
|
keyPair: createKeyPair(api.identity.publicKeyRaw),
|
||||||
|
|
Loading…
Reference in New Issue