mirror of
https://codeberg.org/ashley/poke.git
synced 2024-11-22 17:37:51 +01:00
add hash requriment for ryd :3
This commit is contained in:
parent
1154824a21
commit
85db2f4d84
1 changed files with 35 additions and 36 deletions
65
p/server.js
65
p/server.js
|
@ -30,7 +30,7 @@ const URL_WHITELIST = [
|
||||||
"vid.puffyan.us",
|
"vid.puffyan.us",
|
||||||
"invidious.lidarshield.cloud",
|
"invidious.lidarshield.cloud",
|
||||||
"invidious.epicsite.xyz",
|
"invidious.epicsite.xyz",
|
||||||
"invidious.esmailelbob.xyz"
|
"invidious.esmailelbob.xyz",
|
||||||
];
|
];
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
@ -90,15 +90,14 @@ const listener = (req, res) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
app.get("/", (req, res) => {
|
app.get("/", (req, res) => {
|
||||||
|
|
||||||
var json = {
|
var json = {
|
||||||
status:"200",
|
status: "200",
|
||||||
version:"1.0.0",
|
version: "1.0.0",
|
||||||
URL_WHITELIST,
|
URL_WHITELIST,
|
||||||
cache:"max-age-1848",
|
cache: "max-age-1848",
|
||||||
}
|
};
|
||||||
|
|
||||||
res.json(json)
|
res.json(json);
|
||||||
});
|
});
|
||||||
|
|
||||||
const apiUrl = "https://returnyoutubedislikeapi.com/votes?videoId=";
|
const apiUrl = "https://returnyoutubedislikeapi.com/votes?videoId=";
|
||||||
|
@ -106,37 +105,37 @@ const apiUrl = "https://returnyoutubedislikeapi.com/votes?videoId=";
|
||||||
// Define a cache object
|
// Define a cache object
|
||||||
const cache = {};
|
const cache = {};
|
||||||
|
|
||||||
app.get('/api', async (req, res) => {
|
app.get("/api", async (req, res) => {
|
||||||
|
if (req.query.hash && req.query.hash === "d0550b6e28c8f93533a569c314d5b4e2") {
|
||||||
|
try {
|
||||||
|
const cacheKey = req.query.v;
|
||||||
|
|
||||||
try {
|
// Check if the result is already cached
|
||||||
const cacheKey = req.query.v;
|
if (cache[cacheKey] && Date.now() - cache[cacheKey].timestamp < 3600000) {
|
||||||
|
// If the cached result is less than 1 hour old, return it
|
||||||
|
const cachedData = cache[cacheKey].data;
|
||||||
|
const cachedDate = new Date(cache[cacheKey].timestamp);
|
||||||
|
return res.json({ data: cachedData, cachedDate });
|
||||||
|
}
|
||||||
|
|
||||||
// Check if the result is already cached
|
// If the result is not cached or is older than 1 hour, fetch it from the API
|
||||||
if (cache[cacheKey] && Date.now() - cache[cacheKey].timestamp < 3600000) {
|
const engagement = await fetch(apiUrl + req.query.v).then((res) =>
|
||||||
// If the cached result is less than 1 hour old, return it
|
res.json()
|
||||||
const cachedData = cache[cacheKey].data;
|
);
|
||||||
const cachedDate = new Date(cache[cacheKey].timestamp);
|
|
||||||
return res.json({ data: cachedData, cachedDate });
|
// Cache the result for future requests
|
||||||
|
cache[cacheKey] = {
|
||||||
|
data: engagement,
|
||||||
|
timestamp: Date.now(),
|
||||||
|
};
|
||||||
|
|
||||||
|
res.json({ data: engagement, cachedDate: new Date() });
|
||||||
|
} catch {}
|
||||||
|
} else {
|
||||||
|
return res.send("no hash query found");
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the result is not cached or is older than 1 hour, fetch it from the API
|
|
||||||
const engagement = await fetch(apiUrl + req.query.v).then((res) => res.json());
|
|
||||||
|
|
||||||
// Cache the result for future requests
|
|
||||||
cache[cacheKey] = {
|
|
||||||
data: engagement,
|
|
||||||
timestamp: Date.now()
|
|
||||||
};
|
|
||||||
|
|
||||||
res.json({ data: engagement, cachedDate: new Date() });
|
|
||||||
|
|
||||||
} catch {
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
app.all("/*", listener);
|
app.all("/*", listener);
|
||||||
|
|
||||||
app.listen(3000, () => console.log("Listening on 0.0.0.0:3000"));
|
app.listen(3000, () => console.log("Listening on 0.0.0.0:3000"));
|
||||||
|
|
Loading…
Reference in a new issue