Spaces:
Sleeping
Sleeping
File size: 1,878 Bytes
00cd155 d3287ae f9e1471 00cd155 76d5c60 00cd155 d3287ae 00cd155 3380a84 00cd155 485cf40 3380a84 00cd155 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
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}`));
|