From 632eb1351c92825c10681487efc7cfa3f5cebac6 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Thu, 31 Aug 2023 12:14:28 -0400 Subject: [PATCH] fix: ensure db path exists, create if not --- src/index.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index a96ca57..902b2bb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,14 +4,20 @@ import { Level } from "level"; import { PROTOCOL } from "./constants.js"; import HyperTransportPeer from "./hyperTransport.js"; import { NodeId } from "@lumeweb/libs5"; -import { string } from "micro-packed"; +import * as fs from "fs/promises"; const plugin = { name: "s5", async plugin(api: PluginAPI) { - const db = new Level( - api.pluginConfig.str("db") as string, - ); + const dbPath = api.pluginConfig.str("db") as string; + + try { + await fs.access(dbPath); + } catch { + await fs.mkdir(dbPath, { recursive: true }); + } + + const db = new Level(dbPath); await db.open(); let config = { keyPair: createKeyPair(api.identity.publicKeyRaw),