import { createRequire } from 'module'; import os from 'os'; import { fileURLToPath } from "url"; const require = createRequire(import.meta.url); const express = require("express"); const fs = require("fs"); const path = require("path"); const crypto = require("crypto"); const bodyParser = require("body-parser"); const app = express(); const PORT = 7860; const fss = fs.promises; import { fileTypeFromBuffer } from "file-type"; let __dirname = path.dirname(fileURLToPath(import.meta.url)); app.use(bodyParser.json()); const SECRET = "Vornshade"; const FILE_DIR = path.join(__dirname, "files"); const FILE_MAP = { "L001": "L_ENTRY_001_SoftSilence.zip", "L018": "L_ENTRY_018_WhiteTears.zip", "L031": "L_ENTRY_031_YourVoiceInStatic.zip", "L042": "L_ENTRY_042_VoidLullaby.zip", "L057": "L_ENTRY_057_LastLoginEcho.zip", "L073": "L_ENTRY_073_FinalSync_2025.zip", "L" : "noted.txt" }; function validateToken(id, token) { const timeWindow = 60; const now = Math.floor(Date.now() / 1000); for (let i = 0; i <= timeWindow; i++) { const time = (now - i).toString(); const validToken = crypto.createHash("sha256").update(id + time + SECRET).digest("hex"); if (token === validToken) return true; } return false; } app.post("/secure-fetch", (req, res) => { const { id, token } = req.body; const filename = FILE_MAP[id]; if (!filename) return res.status(404).json({ error: "Invalid file ID" }); if (!validateToken(id, token)) return res.status(403).json({ error: "Invalid or expired token" }); const filePath = path.join(FILE_DIR, filename); if (!fs.existsSync(filePath)) return res.status(404).json({ error: "File not found" }); res.setHeader("Content-Disposition", `attachment; filename=${filename}`); fs.createReadStream(filePath).pipe(res); }); app.listen(PORT, () => console.log(`File DB server running on port ${PORT}`));