mirror of
https://github.com/cupcakearmy/ora.git
synced 2026-04-02 12:05:23 +00:00
progress
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
import dj from 'dayjs'
|
||||
import Dexie from 'dexie'
|
||||
import RelativeTime from 'dayjs/plugin/relativeTime'
|
||||
import Duration from 'dayjs/plugin/duration'
|
||||
|
||||
import { checkForErrors, DBValidator } from './validation'
|
||||
import Dexie from 'dexie'
|
||||
import 'dexie-export-import'
|
||||
|
||||
dj.extend(Duration)
|
||||
dj.extend(RelativeTime)
|
||||
@@ -38,31 +37,5 @@ export async function insertLog({ timestamp, host, seconds }) {
|
||||
}
|
||||
|
||||
export async function clear() {
|
||||
await DB.limits.clear()
|
||||
await DB.logs.clear()
|
||||
}
|
||||
|
||||
export async function dump() {
|
||||
return {
|
||||
limits: await DB.limits.toArray(),
|
||||
logs: await DB.logs.toArray(),
|
||||
}
|
||||
}
|
||||
|
||||
export async function load(data) {
|
||||
if (!checkForErrors(DBValidator, data)) throw new Error('Invalid data')
|
||||
|
||||
await clear()
|
||||
await DB.limits.bulkAdd(data.limits)
|
||||
await DB.logs.bulkAdd(
|
||||
data.logs.map((log) => ({
|
||||
...log,
|
||||
timestamp: new Date(log.timestamp),
|
||||
}))
|
||||
)
|
||||
}
|
||||
|
||||
export async function updateOrSet(table, key, value) {
|
||||
// const updated = await table.update(key, value)
|
||||
// if(updated === 0) await table.
|
||||
return Promise.allSettled(DB.tables.map((table) => DB.table(table.name).clear()))
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import { groupBy, orderBy, sum } from 'lodash'
|
||||
import dj from 'dayjs'
|
||||
|
||||
import { DB } from './db.js'
|
||||
import { SettingsValidator } from './validation.js'
|
||||
|
||||
export async function data({ start, end }) {
|
||||
const logs = await getLogsBetweenDates({ start, end })
|
||||
@@ -60,3 +61,9 @@ export function percentagesToBool(percentages) {
|
||||
const blocked = percentages.map((p) => p >= 100).includes(true)
|
||||
return blocked
|
||||
}
|
||||
|
||||
export async function getSettingsWithDefaults() {
|
||||
const values = await DB.settings.toArray()
|
||||
const fromDB = Object.fromEntries(values.map((v) => [v.key, v.value]))
|
||||
return SettingsValidator.validate(fromDB).value
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user