/api/v1/info

This commit is contained in:
May 2024-04-30 17:24:50 -07:00
parent ff46b03026
commit 364c3627a4
3 changed files with 44 additions and 14 deletions

View file

@ -4,13 +4,10 @@ import { Hono } from "hono"
import fs from "fs"
import { readFile } from "fs/promises"
import Files from "./lib/files.js"
import { getAccount } from "./lib/middleware.js"
import APIRouter from "./routes/api.js"
import preview from "./routes/api/web/preview.js"
import { fileURLToPath } from "url"
import { dirname } from "path"
import pkg from "../../package.json" assert { type: "json" }
import config, { ClientConfiguration } from "./lib/config.js"
import config from "./lib/config.js"
const app = new Hono()
@ -60,16 +57,6 @@ if (config.forceSSL) {
})
}
app.get("/server", (ctx) =>
ctx.json({
version: pkg.version,
files: Object.keys(files.files).length,
maxDiscordFiles: config.maxDiscordFiles,
maxDiscordFileSize: config.maxDiscordFileSize,
accounts: config.accounts,
} as ClientConfiguration)
)
// funcs
// init data
@ -87,6 +74,19 @@ apiRouter.loadAPIMethods().then(() => {
console.log("API OK!")
// moved here to ensure it's matched last
app.get("/server", async (ctx) =>
app.fetch(
new Request(
new URL(
"/api/v1/info",
ctx.req.raw.url
).href,
ctx.req.raw
),
ctx.env
)
)
app.get("/:fileId", async (ctx) =>
app.fetch(
new Request(

View file

@ -4,6 +4,7 @@
"mount": [
"account",
"session",
"info",
{
"file": "file/index",
"to": "/file"

View file

@ -0,0 +1,29 @@
import { Hono } from "hono"
import * as Accounts from "../../../lib/accounts.js"
import { HttpBindings } from "@hono/node-server"
import pkg from "../../../../../package.json" assert {type: "json"}
import config, { ClientConfiguration } from "../../../lib/config.js"
import type Files from "../../../lib/files.js"
const router = new Hono<{
Variables: {
account: Accounts.Account
},
Bindings: HttpBindings
}>()
export default function(files: Files) {
router.get("/", async (ctx) =>
ctx.json({
version: pkg.version,
files: Object.keys(files.files).length,
totalSize: Object.values(files.files).filter(e => e.sizeInBytes).reduce((acc,cur)=>acc+cur.sizeInBytes!,0),
maxDiscordFiles: config.maxDiscordFiles,
maxDiscordFileSize: config.maxDiscordFileSize,
accounts: config.accounts
} as ClientConfiguration)
)
return router
}