add poketranslate :3

This commit is contained in:
Ashley 2024-01-13 20:56:59 +00:00
parent 944bb0e1c7
commit a057666701

View file

@ -71,6 +71,31 @@ module.exports = function (app, config, renderTemplate) {
renderTemplate(res, req, "rewind.ejs"); renderTemplate(res, req, "rewind.ejs");
}); });
app.get("/translate", async function (req, res) {
const { fetch } = await import("undici");
const api_url = "https://simplytranslate.org/api/translate";
// Fetch translation data
const translationResponse = await fetch(
`${api_url}?from=${req.query.from_language}&to=${req.query.to_language}&text=${req.query.input}&engine=google`
);
// Check if the request was successful (status code 200)
const translationData = await translationResponse.json();
// Extract translated_text from the response
const translatedText = translationData.translated_text;
// Render the template with the translated text
renderTemplate(res, req, "translate.ejs", {
translation: translatedText,
text: req.query.input || "enter text here",
from_language: req.query.from_language,
to_language: req.query.to_language,
});
});
app.get("/domains", function (req, res) { app.get("/domains", function (req, res) {
renderTemplate(res, req, "domains.ejs"); renderTemplate(res, req, "domains.ejs");
}); });
@ -133,27 +158,27 @@ module.exports = function (app, config, renderTemplate) {
} }
}); });
app.get("/game-hub", function (req, res) { app.get("/game-hub", function (req, res) {
renderTemplate(res, req, "gamehub.ejs", { renderTemplate(res, req, "gamehub.ejs", {
game:req.query.game game: req.query.game,
}); });
}); });
app.get("/static/:id", (req, res) => { app.get("/static/:id", (req, res) => {
const id = req.params.id; const id = req.params.id;
if (id.endsWith(".css")) { if (id.endsWith(".css")) {
res.redirect("/css/" + id); res.redirect("/css/" + id);
} else if (id.endsWith(".js")) { } else if (id.endsWith(".js")) {
if (id.endsWith(".bundle.js")) { if (id.endsWith(".bundle.js")) {
const jsFiles = ['app.js', 'custom-css.js', 'emojis.js']; const jsFiles = ["app.js", "custom-css.js", "emojis.js"];
const combinedContent = jsFiles const combinedContent = jsFiles
.map((fileName) => { .map((fileName) => {
const filePath = path.join(html_location, fileName); const filePath = path.join(html_location, fileName);
return fs.existsSync(filePath) ? fs.readFileSync(filePath, 'utf-8') : ''; return fs.existsSync(filePath)
? fs.readFileSync(filePath, "utf-8")
: "";
}) })
.join('\n'); .join("\n");
const minimizedJs = require("uglify-js").minify(combinedContent).code; const minimizedJs = require("uglify-js").minify(combinedContent).code;
@ -192,7 +217,5 @@ app.get("/static/:id", (req, res) => {
} else { } else {
res.sendFile(id, { root: html_location }); res.sendFile(id, { root: html_location });
} }
}); });
}; };