mirror of
https://codeberg.org/ashley/poke.git
synced 2024-12-25 17:48:41 +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");
|
||||
});
|
||||
|
@ -79,26 +104,26 @@ module.exports = function (app, config, renderTemplate) {
|
|||
renderTemplate(res, req, "license.ejs");
|
||||
});
|
||||
|
||||
app.get("/map", function (req, res) {
|
||||
app.get("/map", function (req, res) {
|
||||
renderTemplate(res, req, "map.ejs");
|
||||
});
|
||||
|
||||
|
||||
app.get("/credits", function (req, res) {
|
||||
renderTemplate(res, req, "want-you-gone.ejs");
|
||||
});
|
||||
|
||||
|
||||
app.get("/settings", function (req, res) {
|
||||
renderTemplate(res, req, "content-settings.ejs");
|
||||
});
|
||||
|
||||
|
||||
app.get("/offline", function (req, res) {
|
||||
res.sendFile("offline.html", { root: location_pwa });
|
||||
});
|
||||
|
||||
|
||||
app.get("/manifest.json", function (req, res) {
|
||||
res.sendFile("manifest.json", { root: location_pwa });
|
||||
});
|
||||
|
||||
|
||||
app.get("/customize", function (req, res) {
|
||||
const tab = req.query.tab;
|
||||
|
||||
|
@ -133,66 +158,64 @@ 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) => {
|
||||
const id = req.params.id;
|
||||
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 combinedContent = jsFiles
|
||||
.map((fileName) => {
|
||||
const filePath = path.join(html_location, fileName);
|
||||
return fs.existsSync(filePath) ? fs.readFileSync(filePath, 'utf-8') : '';
|
||||
})
|
||||
.join('\n');
|
||||
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 combinedContent = jsFiles
|
||||
.map((fileName) => {
|
||||
const filePath = path.join(html_location, fileName);
|
||||
return fs.existsSync(filePath)
|
||||
? fs.readFileSync(filePath, "utf-8")
|
||||
: "";
|
||||
})
|
||||
.join("\n");
|
||||
|
||||
const minimizedJs = require("uglify-js").minify(combinedContent).code;
|
||||
const minimizedJs = require("uglify-js").minify(combinedContent).code;
|
||||
|
||||
res.header("Content-Type", "text/javascript");
|
||||
res.send(
|
||||
"// @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-3.0-or-later" +
|
||||
`\n` +
|
||||
`// Includes app.js, emojis.js, and custom-css.js. Source code can be found for these 3 files in https://codeberg.org/Ashley/poketube/src/branch/main/css/` +
|
||||
`\n` +
|
||||
minimizedJs +
|
||||
`\n` +
|
||||
"// @license-end"
|
||||
);
|
||||
} else {
|
||||
const filePath = path.join(html_location, id);
|
||||
res.header("Content-Type", "text/javascript");
|
||||
res.send(
|
||||
"// @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-3.0-or-later" +
|
||||
`\n` +
|
||||
`// Includes app.js, emojis.js, and custom-css.js. Source code can be found for these 3 files in https://codeberg.org/Ashley/poketube/src/branch/main/css/` +
|
||||
`\n` +
|
||||
minimizedJs +
|
||||
`\n` +
|
||||
"// @license-end"
|
||||
);
|
||||
} else {
|
||||
const filePath = path.join(html_location, id);
|
||||
|
||||
if (!fs.existsSync(filePath)) {
|
||||
res.status(404).send("File not found");
|
||||
return;
|
||||
if (!fs.existsSync(filePath)) {
|
||||
res.status(404).send("File not found");
|
||||
return;
|
||||
}
|
||||
|
||||
const js = fs.readFileSync(filePath, "utf8");
|
||||
const minimizedJs = require("uglify-js").minify(js).code;
|
||||
|
||||
res.header("Content-Type", "text/javascript");
|
||||
res.send(
|
||||
"// @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-3.0-or-later" +
|
||||
`\n` +
|
||||
`// Source code can be found in: https://codeberg.org/Ashley/poketube/src/branch/main/css/${id}` +
|
||||
`\n` +
|
||||
minimizedJs +
|
||||
`\n` +
|
||||
"// @license-end"
|
||||
);
|
||||
}
|
||||
|
||||
const js = fs.readFileSync(filePath, "utf8");
|
||||
const minimizedJs = require("uglify-js").minify(js).code;
|
||||
|
||||
res.header("Content-Type", "text/javascript");
|
||||
res.send(
|
||||
"// @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-3.0-or-later" +
|
||||
`\n` +
|
||||
`// Source code can be found in: https://codeberg.org/Ashley/poketube/src/branch/main/css/${id}` +
|
||||
`\n` +
|
||||
minimizedJs +
|
||||
`\n` +
|
||||
"// @license-end"
|
||||
);
|
||||
} else {
|
||||
res.sendFile(id, { root: html_location });
|
||||
}
|
||||
} else {
|
||||
res.sendFile(id, { root: html_location });
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue