mirror of
https://codeberg.org/ashley/poke.git
synced 2024-11-22 15:17:55 +01:00
add poketranslate :3
This commit is contained in:
parent
944bb0e1c7
commit
a057666701
1 changed files with 83 additions and 60 deletions
|
@ -71,6 +71,31 @@ module.exports = function (app, config, renderTemplate) {
|
|||
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) {
|
||||
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", {
|
||||
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;
|
||||
|
||||
if (id.endsWith(".css")) {
|
||||
res.redirect("/css/" + id);
|
||||
} else if (id.endsWith(".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
|
||||
.map((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;
|
||||
|
||||
|
@ -192,7 +217,5 @@ app.get("/static/:id", (req, res) => {
|
|||
} else {
|
||||
res.sendFile(id, { root: html_location });
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue