Spaces:
Paused
Paused
File size: 2,555 Bytes
afc104e d145b59 afc104e d145b59 afc104e d145b59 d00e379 afc104e de913e8 afc104e d145b59 afc104e 3f67505 63bcacd c7cfc1f d00e379 63bcacd afc104e a8838d0 |
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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
const express = require("express");
const cors = require("cors");
const path = require("path");
const fs = require("fs");
require("dotenv").config();
const bodyParser = require("body-parser");
const apis = require("./fnc/apis");
const downloadf = require("./fnc/download");
const app = express();
const port = process.env.PORT || 7860;
app.use(express.json({
limit: "500mb"
}));
app.use(express.urlencoded({
limit: "500mb",
extended: true
}));
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}));
app.use("/cdn", express.static(path.join(__dirname, "cdn")));
app.use("/tmp", express.static(path.join(__dirname, "tmp")));
app.use(async (req, res, next) => {
const _req = Date.now()
const ip = req?.ip?.replace("::ffff:", "") || req?.ip;
req._ip = ip;
res.on("finish", () => {
const _end = Date.now();
const total = _end - _req;
const _date = formatDate(new Date(_req));
const date = `${_date.YYYY}-${_date.MM}-${_date.DD}`;
const time = `${_date.hh}:${_date.mm}:${_date.ss}`;
console.log(
"\x1b[36;1m[\x1b[32;1m" + req.method + "\x1b[36;1m]\x1b[0;0m\n",
"Path:", req.originalUrl + "\n",
"Host:", req.get("host") + "\n",
"Status: \x1b[33m" + res.statusCode + "\x1b[0;0m\n",
"Time:", total + "ms\n",
"Length:", res.getHeaders()["content-length"] + "\n",
"User-Agent:", req.get("user-agent") + "\n",
"IP:", ip + "\n",
"Date:", date + "\n",
"Time:", time
);
});
next();
});
app.get("/", (req, res) => {
res.send({ status: 401, message: "You don't have access to this!"})
});
app.post("/api", apis);
app.get("/download", downloadf);
const apiStatusFile = path.join(__dirname, "/tmp","api.json");
// Endpoint untuk membaca api.json
app.get("/api-checker", (req, res) => {
res.send(`
<html>
<head>
<meta http-equiv="refresh" content="3;url=https://fullpwerr-hutatools.hf.space/tmp/api.json" />
</head>
<body>
</body>
</html>
`)
})
let server
app.listen(port, () => {
console.log("listening on localhost:", port);
})
function formatDate(date) {
const YYYY = String(date.getFullYear());
const MM = String(date.getMonth() + 1).padStart(2, "0");
const DD = String(date.getDate()).padStart(2, "0");
const hh = String(date.getHours()).padStart(2, "0");
const mm = String(date.getMinutes()).padStart(2, "0");
const ss = String(date.getSeconds()).padStart(2, "0");
return {
YYYY,
MM,
DD,
hh,
mm,
ss
}
} |