mirror of
https://github.com/streamwall/streamwall.git
synced 2026-04-13 17:22:04 -04:00
Implement standalone control server
This commit is contained in:
31
packages/streamwall-control-server/src/storage.ts
Normal file
31
packages/streamwall-control-server/src/storage.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import type { Low } from 'lowdb'
|
||||
import { JSONFilePreset } from 'lowdb/node'
|
||||
import process from 'node:process'
|
||||
import type { AuthToken } from './auth.ts'
|
||||
|
||||
export interface StoredData {
|
||||
auth: {
|
||||
salt: string | null
|
||||
tokens: AuthToken[]
|
||||
}
|
||||
streamwallToken: null | {
|
||||
tokenId: string
|
||||
secret: string
|
||||
}
|
||||
}
|
||||
|
||||
const defaultData: StoredData = {
|
||||
auth: {
|
||||
salt: null,
|
||||
tokens: [],
|
||||
},
|
||||
streamwallToken: null,
|
||||
}
|
||||
|
||||
export type StorageDB = Low<StoredData>
|
||||
|
||||
export async function loadStorage() {
|
||||
const dbPath = process.env.DB_PATH || 'storage.json'
|
||||
const db = await JSONFilePreset<StoredData>(dbPath, defaultData)
|
||||
return db
|
||||
}
|
||||
Reference in New Issue
Block a user