mirror of https://github.com/requarks/wiki
parent
dc78af9156
commit
68e6a2787a
@ -1,5 +1,5 @@
|
||||
{
|
||||
"$schema": "./node_modules/oxfmt/configuration_schema.json",
|
||||
"$schema": "./backend/node_modules/oxfmt/configuration_schema.json",
|
||||
"semi": false,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "none",
|
||||
@ -1,14 +1,14 @@
|
||||
{
|
||||
"eslint.enable": false,
|
||||
"editor.formatOnSave": false,
|
||||
"editor.tabSize": 2,
|
||||
"i18n-ally.localesPaths": [
|
||||
"backend/locales",
|
||||
],
|
||||
"i18n-ally.localesPaths": ["backend/locales"],
|
||||
"i18n-ally.pathMatcher": "{locale}.json",
|
||||
"i18n-ally.keystyle": "flat",
|
||||
"i18n-ally.sortKeys": true,
|
||||
"i18n-ally.enabledFrameworks": [
|
||||
"vue"
|
||||
]
|
||||
"i18n-ally.enabledFrameworks": ["vue"],
|
||||
"[javascript]": {
|
||||
"editor.defaultFormatter": "oxc.oxc-vscode",
|
||||
"editor.formatOnSave": true,
|
||||
"editor.formatOnSaveMode": "file"
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,24 +1,74 @@
|
||||
import path from 'node:path'
|
||||
import os from 'node:os'
|
||||
import { DateTime } from 'luxon'
|
||||
import { filesize } from 'filesize'
|
||||
import { isNil } from 'es-toolkit/predicate'
|
||||
import { gte, sql } from 'drizzle-orm'
|
||||
import {
|
||||
groups as groupsTable,
|
||||
pages as pagesTable,
|
||||
tags as tagsTable,
|
||||
users as usersTable
|
||||
} from '../db/schema.mjs'
|
||||
|
||||
/**
|
||||
* System API Routes
|
||||
*/
|
||||
async function routes(app, options) {
|
||||
app.get('/info', {
|
||||
app.get(
|
||||
'/info',
|
||||
{
|
||||
config: {
|
||||
permissions: ['read:dashboard', 'manage:sites']
|
||||
},
|
||||
schema: {
|
||||
summary: 'System Info',
|
||||
tags: ['System']
|
||||
}
|
||||
}, async (request, reply) => {
|
||||
return { hello: 'world' }
|
||||
})
|
||||
},
|
||||
async (request, reply) => {
|
||||
return {
|
||||
configFile: path.join(process.cwd(), 'config.yml'),
|
||||
cpuCores: os.cpus().length,
|
||||
currentVersion: WIKI.version,
|
||||
dbHost: WIKI.config.db.host,
|
||||
dbVersion: WIKI.dbManager.VERSION,
|
||||
groupsTotal: await WIKI.db.$count(groupsTable),
|
||||
hostname: os.hostname(),
|
||||
httpPort: 0,
|
||||
isMailConfigured: WIKI.config?.mail?.host?.length > 2,
|
||||
isSchedulerHealthy: true,
|
||||
latestVersion: WIKI.config.update.version,
|
||||
latestVersionReleaseDate: DateTime.fromISO(WIKI.config.update.versionDate).toJSDate(),
|
||||
loginsPastDay: await WIKI.db.$count(
|
||||
usersTable,
|
||||
gte(usersTable.lastLoginAt, sql`NOW() - INTERVAL '1 DAY'`)
|
||||
),
|
||||
nodeVersion: process.version.substring(1),
|
||||
operatingSystem: `${os.type()} (${os.platform()}) ${os.release()} ${os.arch()}`,
|
||||
pagesTotal: await WIKI.db.$count(pagesTable),
|
||||
platform: os.platform(),
|
||||
ramTotal: filesize(os.totalmem()),
|
||||
tagsTotal: await WIKI.db.$count(tagsTable),
|
||||
upgradeCapable: !isNil(process.env.UPGRADE_COMPANION),
|
||||
usersTotal: await WIKI.db.$count(usersTable),
|
||||
workingDirectory: process.cwd()
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
app.get('/flags', {
|
||||
app.get(
|
||||
'/flags',
|
||||
{
|
||||
schema: {
|
||||
summary: 'System Flags',
|
||||
tags: ['System']
|
||||
}
|
||||
}, async (request, reply) => {
|
||||
return { hello: 'world' }
|
||||
})
|
||||
},
|
||||
async (request, reply) => {
|
||||
return WIKI.config.flags
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
export default routes
|
||||
|
||||
@ -0,0 +1,85 @@
|
||||
import { eq, sql } from 'drizzle-orm'
|
||||
import { sessions as sessionsTable } from '../db/schema.mjs'
|
||||
|
||||
/**
|
||||
* Sessions model
|
||||
*/
|
||||
class Sessions {
|
||||
/**
|
||||
* Fetch all sessions from a single user
|
||||
*
|
||||
* @param {String} userId User ID
|
||||
* @returns Promise<Array> User Sessions
|
||||
*/
|
||||
async getByUser(userId) {
|
||||
return WIKI.db.select().from(sessionsTable).where(eq(sessionsTable.userId, userId))
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch a single session by id
|
||||
*
|
||||
* @param {String} id Session ID
|
||||
* @returns Promise<Object> Session data
|
||||
*/
|
||||
async get(id) {
|
||||
const res = await WIKI.db.select().from(sessionsTable).where(eq(sessionsTable.id, id))
|
||||
return res?.[0]?.data ?? null
|
||||
}
|
||||
|
||||
/**
|
||||
* Set / Update a session
|
||||
*
|
||||
* @param {String} id Session ID
|
||||
* @param {Object} data Session Data
|
||||
*/
|
||||
async set(id, data) {
|
||||
await WIKI.db
|
||||
.insert(sessionsTable)
|
||||
.values([
|
||||
{
|
||||
id,
|
||||
userId: data?.user?.id ?? null,
|
||||
data
|
||||
}
|
||||
])
|
||||
.onConflictDoUpdate({
|
||||
target: sessionsTable.id,
|
||||
set: {
|
||||
data,
|
||||
userId: data?.user?.id ?? null,
|
||||
updatedAt: sql`now()`
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a session
|
||||
*
|
||||
* @param {String} id Session ID
|
||||
* @returns Promise<void>
|
||||
*/
|
||||
async destroy(id) {
|
||||
return WIKI.db.delete(sessionsTable).where(eq(sessionsTable.id, id))
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all sessions from all users
|
||||
*
|
||||
* @returns Promise<void>
|
||||
*/
|
||||
async clearAllSessions() {
|
||||
return WIKI.db.delete(sessionsTable)
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all sessions from a single user
|
||||
*
|
||||
* @param {String} userId User ID
|
||||
* @returns Promise<void>
|
||||
*/
|
||||
async clearSessionsFromUser(userId) {
|
||||
return WIKI.db.delete(sessionsTable).where(eq(sessionsTable.userId, userId))
|
||||
}
|
||||
}
|
||||
|
||||
export const sessions = new Sessions()
|
||||
@ -1,9 +0,0 @@
|
||||
{
|
||||
"$schema": "./node_modules/oxfmt/configuration_schema.json",
|
||||
"semi": false,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "none",
|
||||
"bracketSameLine": true,
|
||||
"endOfLine": "lf",
|
||||
"insertFinalNewline": true
|
||||
}
|
||||
Loading…
Reference in new issue