Skip to content

Commit

Permalink
feat: add nodeRed custom storage based on Unstorage
Browse files Browse the repository at this point in the history
  • Loading branch information
becem-gharbi committed May 17, 2023
1 parent 2b14d08 commit 0d30cbf
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 12 deletions.
11 changes: 11 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@ import type { LocalSettings } from "@node-red/runtime";
import { dirname, resolve } from "path";
import { fileURLToPath } from "url";
import { storageModule } from "./storage.js";
import { createStorage } from "unstorage";
import fsDriver from "unstorage/drivers/fs";

const cwd = dirname(fileURLToPath(import.meta.url));

const storage = createStorage({
//@ts-ignore
driver: fsDriver({ base: "./tmp" }),
});

export const settings: LocalSettings = {
httpAdminRoot: "/",
httpNodeRoot: "/api",
Expand All @@ -16,4 +23,8 @@ export const settings: LocalSettings = {
credentialSecret: "secret",
//@ts-ignore
storageModule: storageModule,
storageSettings: {
storage: storage,
appName: process.env.APP_NAME || "default",
},
};
13 changes: 4 additions & 9 deletions src/storage.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
//@ts-nocheck
import type { StorageModule } from "@node-red/runtime";
import { createStorage, prefixStorage, Storage } from "unstorage";
import fsDriver from "unstorage/drivers/fs";
import { prefixStorage, Storage } from "unstorage";

var appname: string;

var appStorage: Storage;
var libraryStorage: Storage;

export const storageModule: StorageModule = {
init: () => {
appname = "app0";
init: ({ storageSettings }) => {
appname = storageSettings.appName;

const unstorage = createStorage({
driver: fsDriver({ base: "./tmp" }),
});

appStorage = prefixStorage(unstorage, appname);
appStorage = prefixStorage(storageSettings.storage, appname);

libraryStorage = prefixStorage(appStorage, "library");
},
Expand Down
1 change: 0 additions & 1 deletion tmp/app0/credentials

This file was deleted.

1 change: 0 additions & 1 deletion tmp/app0/flows

This file was deleted.

1 change: 1 addition & 0 deletions tmp/default/flows
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"id":"6dfb4bdf1ac54c22","type":"tab","label":"Flow 1","disabled":false,"info":"","env":[]},{"id":"0887201e20338fb8","type":"inject","z":"6dfb4bdf1ac54c22","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":240,"y":140,"wires":[["f18a2a6ae94cd838"]]},{"id":"f18a2a6ae94cd838","type":"debug","z":"6dfb4bdf1ac54c22","name":"debug 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":560,"y":140,"wires":[]}]
Loading

0 comments on commit 0d30cbf

Please sign in to comment.