mirror of
https://github.com/mollersuite/monofile.git
synced 2024-11-22 05:46:26 -08:00
/api/v1/info
This commit is contained in:
parent
ff46b03026
commit
364c3627a4
|
@ -4,13 +4,10 @@ import { Hono } from "hono"
|
||||||
import fs from "fs"
|
import fs from "fs"
|
||||||
import { readFile } from "fs/promises"
|
import { readFile } from "fs/promises"
|
||||||
import Files from "./lib/files.js"
|
import Files from "./lib/files.js"
|
||||||
import { getAccount } from "./lib/middleware.js"
|
|
||||||
import APIRouter from "./routes/api.js"
|
import APIRouter from "./routes/api.js"
|
||||||
import preview from "./routes/api/web/preview.js"
|
|
||||||
import { fileURLToPath } from "url"
|
import { fileURLToPath } from "url"
|
||||||
import { dirname } from "path"
|
import { dirname } from "path"
|
||||||
import pkg from "../../package.json" assert { type: "json" }
|
import config from "./lib/config.js"
|
||||||
import config, { ClientConfiguration } from "./lib/config.js"
|
|
||||||
|
|
||||||
const app = new Hono()
|
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
|
// funcs
|
||||||
|
|
||||||
// init data
|
// init data
|
||||||
|
@ -87,6 +74,19 @@ apiRouter.loadAPIMethods().then(() => {
|
||||||
console.log("API OK!")
|
console.log("API OK!")
|
||||||
|
|
||||||
// moved here to ensure it's matched last
|
// 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.get("/:fileId", async (ctx) =>
|
||||||
app.fetch(
|
app.fetch(
|
||||||
new Request(
|
new Request(
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
"mount": [
|
"mount": [
|
||||||
"account",
|
"account",
|
||||||
"session",
|
"session",
|
||||||
|
"info",
|
||||||
{
|
{
|
||||||
"file": "file/index",
|
"file": "file/index",
|
||||||
"to": "/file"
|
"to": "/file"
|
||||||
|
|
29
src/server/routes/api/v1/info.ts
Normal file
29
src/server/routes/api/v1/info.ts
Normal 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
|
||||||
|
}
|
Loading…
Reference in a new issue