Add asset type limit

Add basic logging
This commit is contained in:
Christopher Cookman 2024-09-05 11:20:45 -06:00
parent c5421e76f2
commit d7fa61679e
Signed by: ChrisChrome
GPG key ID: A023A26E42C33A42

View file

@ -6,6 +6,11 @@ const port = process.env.SERVER_PORT || 3000;
app.use(express.json()); app.use(express.json());
app.set("trust proxy", 1); app.set("trust proxy", 1);
app.use((req, res, next) => {
console.log(`[${new Date().toLocaleString()}] ${req.ip} ${req.method} ${req.url}`);
next();
})
var rateLimits = {}; var rateLimits = {};
@ -14,6 +19,7 @@ app.get("/", (req, res) => {
res.sendFile(__dirname + "/static/index.html") res.sendFile(__dirname + "/static/index.html")
}); });
app.post("/", async (req, res) => { app.post("/", async (req, res) => {
// Impliment a rate limit of 25 requests per minute // Impliment a rate limit of 25 requests per minute
const ip = req.ip; const ip = req.ip;
@ -108,6 +114,7 @@ app.post("/", async (req, res) => {
try { try {
let response = await fetch("https://assetdelivery.roblox.com/v1/assets/batch", options); let response = await fetch("https://assetdelivery.roblox.com/v1/assets/batch", options);
let json = await response.json(); let json = await response.json();
//console.log(JSON.stringify(json, null, 2));
// Build the response object // Build the response object
const responses = req.body.data.reduce((acc, item, index) => { const responses = req.body.data.reduce((acc, item, index) => {
const assetId = item; const assetId = item;
@ -119,6 +126,14 @@ app.post("/", async (req, res) => {
message: codes[errorCode].message, message: codes[errorCode].message,
additional: codes[errorCode].description additional: codes[errorCode].description
}; };
} else if (json[index].assetTypeId !== 3) {
// Return 415, the asset isnt audio
acc[assetId] = {
status: "failure",
code: 415,
message: codes[415].message,
additional: codes[415].description
};
} else { } else {
acc[assetId] = { acc[assetId] = {
status: "success", status: "success",