feat: nový způsob zobrazování novinek
All checks were successful
ci/woodpecker/push/workflow Pipeline was successful
All checks were successful
ci/woodpecker/push/workflow Pipeline was successful
fix: oprava kopírování changelogů do Docker image fix: oprava kopírování changelogů do Docker image
This commit is contained in:
@@ -18,6 +18,7 @@ import statsRoutes from "./routes/statsRoutes";
|
||||
import notificationRoutes from "./routes/notificationRoutes";
|
||||
import qrRoutes from "./routes/qrRoutes";
|
||||
import devRoutes from "./routes/devRoutes";
|
||||
import changelogRoutes from "./routes/changelogRoutes";
|
||||
|
||||
const ENVIRONMENT = process.env.NODE_ENV ?? 'production';
|
||||
dotenv.config({ path: path.resolve(__dirname, `../.env.${ENVIRONMENT}`) });
|
||||
@@ -165,6 +166,7 @@ app.use("/api/stats", statsRoutes);
|
||||
app.use("/api/notifications", notificationRoutes);
|
||||
app.use("/api/qr", qrRoutes);
|
||||
app.use("/api/dev", devRoutes);
|
||||
app.use("/api/changelogs", changelogRoutes);
|
||||
|
||||
app.use('/stats', express.static('public'));
|
||||
app.use(express.static('public'));
|
||||
|
||||
50
server/src/routes/changelogRoutes.ts
Normal file
50
server/src/routes/changelogRoutes.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import express, { Request, Response } from "express";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
const CHANGELOGS_DIR = path.resolve(__dirname, "../../changelogs");
|
||||
|
||||
// In-memory cache: datum → seznam změn
|
||||
const cache: Record<string, string[]> = {};
|
||||
|
||||
function loadAllChangelogs(): Record<string, string[]> {
|
||||
let files: string[];
|
||||
try {
|
||||
files = fs.readdirSync(CHANGELOGS_DIR).filter(f => f.endsWith(".json"));
|
||||
} catch {
|
||||
return {};
|
||||
}
|
||||
|
||||
for (const file of files) {
|
||||
const date = file.replace(".json", "");
|
||||
if (!cache[date]) {
|
||||
const content = fs.readFileSync(path.join(CHANGELOGS_DIR, file), "utf-8");
|
||||
cache[date] = JSON.parse(content);
|
||||
}
|
||||
}
|
||||
|
||||
return cache;
|
||||
}
|
||||
|
||||
router.get("/", (req: Request, res: Response) => {
|
||||
const all = loadAllChangelogs();
|
||||
const since = typeof req.query.since === "string" ? req.query.since : undefined;
|
||||
|
||||
// Seřazení od nejnovějšího po nejstarší
|
||||
const sortedDates = Object.keys(all).sort((a, b) => b.localeCompare(a));
|
||||
|
||||
const filteredDates = since
|
||||
? sortedDates.filter(date => date > since)
|
||||
: sortedDates;
|
||||
|
||||
const result: Record<string, string[]> = {};
|
||||
for (const date of filteredDates) {
|
||||
result[date] = all[date];
|
||||
}
|
||||
|
||||
res.status(200).json(result);
|
||||
});
|
||||
|
||||
export default router;
|
||||
Reference in New Issue
Block a user