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");
|
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");
|
||||||
});
|
});
|
||||||
|
@ -79,26 +104,26 @@ module.exports = function (app, config, renderTemplate) {
|
||||||
renderTemplate(res, req, "license.ejs");
|
renderTemplate(res, req, "license.ejs");
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get("/map", function (req, res) {
|
app.get("/map", function (req, res) {
|
||||||
renderTemplate(res, req, "map.ejs");
|
renderTemplate(res, req, "map.ejs");
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get("/credits", function (req, res) {
|
app.get("/credits", function (req, res) {
|
||||||
renderTemplate(res, req, "want-you-gone.ejs");
|
renderTemplate(res, req, "want-you-gone.ejs");
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get("/settings", function (req, res) {
|
app.get("/settings", function (req, res) {
|
||||||
renderTemplate(res, req, "content-settings.ejs");
|
renderTemplate(res, req, "content-settings.ejs");
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get("/offline", function (req, res) {
|
app.get("/offline", function (req, res) {
|
||||||
res.sendFile("offline.html", { root: location_pwa });
|
res.sendFile("offline.html", { root: location_pwa });
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get("/manifest.json", function (req, res) {
|
app.get("/manifest.json", function (req, res) {
|
||||||
res.sendFile("manifest.json", { root: location_pwa });
|
res.sendFile("manifest.json", { root: location_pwa });
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get("/customize", function (req, res) {
|
app.get("/customize", function (req, res) {
|
||||||
const tab = req.query.tab;
|
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", {
|
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;
|
||||||
|
|
||||||
res.header("Content-Type", "text/javascript");
|
res.header("Content-Type", "text/javascript");
|
||||||
res.send(
|
res.send(
|
||||||
"// @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-3.0-or-later" +
|
"// @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-3.0-or-later" +
|
||||||
`\n` +
|
`\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/` +
|
`// 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` +
|
`\n` +
|
||||||
minimizedJs +
|
minimizedJs +
|
||||||
`\n` +
|
`\n` +
|
||||||
"// @license-end"
|
"// @license-end"
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
const filePath = path.join(html_location, id);
|
const filePath = path.join(html_location, id);
|
||||||
|
|
||||||
if (!fs.existsSync(filePath)) {
|
if (!fs.existsSync(filePath)) {
|
||||||
res.status(404).send("File not found");
|
res.status(404).send("File not found");
|
||||||
return;
|
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"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
const js = fs.readFileSync(filePath, "utf8");
|
res.sendFile(id, { root: html_location });
|
||||||
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 });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue