1
0

feat: Added viewer

This commit is contained in:
2026-02-12 17:45:47 +01:00
parent 5ac84e3690
commit cea8cdf4ee
44 changed files with 16005 additions and 9 deletions

View File

@@ -19,6 +19,8 @@ import fs from "fs/promises";
import { getCurrentInterval } from "./scheduleRules.js";
import bodyParser from "body-parser";
import cors from "cors";
import next from "next";
import { fileURLToPath } from "url";
const DB_FOLDER = path.join(process.cwd(), "volume", "db");
const WEB_FOLDER = path.join(process.cwd(), "web", "public");
@@ -82,6 +84,10 @@ app.get("/status", async (_: Request, res: Response) => {
}
})
app.get("/posts/viewer/redirect", (_: Request, res: Response) => {
res.redirect(302, "/viewer");
})
app.post("/report", async (req: Request, res: Response): Promise<any> => {
const { class: className, location, content } = req.body;
if (!className || !location || !content) {
@@ -121,10 +127,27 @@ app.post("/report", async (req: Request, res: Response): Promise<any> => {
});
if (SERVE_WEB) {
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const dev = process.env.NODE_ENV !== 'production'
const nextApp = next({
dev,
dir: path.join(__dirname, 'viewer')
})
const handle = nextApp.getRequestHandler()
await nextApp.prepare()
app.all(/^\/viewer(?:$|\/.*)/, (req, res) => {
return handle(req, res)
})
app.use(express.static(path.join(process.cwd(), 'web/public'), {
index: 'index.html',
extensions: ['html'],
}));
}))
}
app.listen(PORT, () => {