mirror of
https://github.com/cupcakearmy/ora.git
synced 2026-04-02 12:05:23 +00:00
v0.3
This commit is contained in:
@@ -2,6 +2,7 @@ import dj from 'dayjs'
|
||||
import Dexie from 'dexie'
|
||||
import RelativeTime from 'dayjs/plugin/relativeTime'
|
||||
import Duration from 'dayjs/plugin/duration'
|
||||
import Joi from 'joi'
|
||||
|
||||
dj.extend(Duration)
|
||||
dj.extend(RelativeTime)
|
||||
@@ -29,3 +30,56 @@ export async function insertLog({ timestamp, host, seconds }) {
|
||||
data.seconds += seconds
|
||||
await DB.logs.put(data)
|
||||
}
|
||||
|
||||
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 function validate(data) {
|
||||
const schema = Joi.object({
|
||||
limits: Joi.array().items(
|
||||
Joi.object({
|
||||
host: Joi.string(),
|
||||
id: Joi.number(),
|
||||
rules: Joi.array().items(
|
||||
Joi.object({
|
||||
limit: Joi.array().items(Joi.string(), Joi.number()),
|
||||
every: Joi.array().items(Joi.string(), Joi.number()),
|
||||
})
|
||||
),
|
||||
})
|
||||
),
|
||||
logs: Joi.array().items(
|
||||
Joi.object({
|
||||
host: Joi.string(),
|
||||
id: Joi.number(),
|
||||
seconds: Joi.number(),
|
||||
timestamp: Joi.string(),
|
||||
})
|
||||
),
|
||||
})
|
||||
|
||||
const validated = schema.validate(data, { presence: 'required' })
|
||||
return !validated.error
|
||||
}
|
||||
|
||||
export async function load(data) {
|
||||
if (!validate(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),
|
||||
}))
|
||||
)
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link href="../../node_modules/spectre.css/dist/spectre.min.css" rel="stylesheet" />
|
||||
<link href="../../node_modules/tailwindcss/dist/tailwind.css" rel="stylesheet" />
|
||||
<link href="../../node_modules/tailwindcss/dist/tailwind.min.css" rel="stylesheet" />
|
||||
<style>
|
||||
#root {
|
||||
width: 100vw;
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import browser from 'webextension-polyfill'
|
||||
|
||||
export const dashboard = browser.runtime.getURL('./src/dashboard/index.html')
|
||||
|
||||
export const isDev = process.env.NODE_ENV !== 'production'
|
||||
Reference in New Issue
Block a user