update into /connect, start work on /connect-area

This commit is contained in:
FullGreaM 2025-02-06 15:42:13 +03:00
parent a324a9edad
commit 941db4aa36
5 changed files with 91 additions and 8 deletions

View File

@ -0,0 +1,19 @@
module.exports = function (req, res) {
const serverAddress = req.query.server;
res.send(`<!DOCTYPE html>
<html>
<head>
<title>Connection: ${serverAddress}</title>
<meta charset="utf-8">
</head>
<body class="bg text-white">
<div id="js-required">
<h1>Error: Javascript off</h1><hr/>
<p>Javascript is required for the site to work, enable it in your browser settings</p>
</div>
<script>
document.getElementById("js-required").innerHTML = "<p>Loading...</p>";
</script>
</body>
</html>`);
}

View File

@ -3,6 +3,7 @@ const path = require("path");
const logger = require("../logger");
const flDir = require("./fldir-router");
const connectArea = require("./connect-router");
const api = require("./web-api/api-router");
module.exports = (address, port) => {
@ -18,7 +19,9 @@ module.exports = (address, port) => {
app.use("/fl_dir", flDir);
app.use("/api", api);
app.get("/connect-area", connectArea);
app.use("/*", (req, res) => {
res.send(`<!DOCTYPE html>
<html>

View File

@ -36,7 +36,7 @@
<div class="modal-content text-light bg-dark">
<!-- <img src="https://warhammerart.com/wp-content/uploads/2021/08/Adeptus-Mechanicus.jpg"> -->
<div class="modal-header">
<h1 class="modal-title fs-5 translate" id="titleDenial"><i class="fas fa-triangle-exclamation"></i> Denial of responsibility</h1>
<h1 class="modal-title fs-5 translate" id="titleDenial"><i class="fas fa-exclamation-triangle"></i> Denial of responsibility</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
@ -51,4 +51,32 @@
</center></div>
</div>
</div>
</div>
<div class="modal fade text-light" id="connectModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg modal-img-view modal-dialog-centered modal-dialog-scrollable">
<!-- <div class="modal-dialog modal-img-view"> -->
<div class="modal-content text-light bg-dark">
<!-- <img src="https://warhammerart.com/wp-content/uploads/2021/08/Adeptus-Mechanicus.jpg"> -->
<div class="modal-header">
<h1 class="modal-title fs-5 translate" id="titleCustomServerConnect"><i class="fas fa-wifi"></i> Connect to remote server</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<center>
<h5 class="translate" id="titleCustomConnect">Connection data</h5><hr/>
</center>
<p><b class="translate" id="addressCustomConnect">Enter address of server (without ws(s):// and port)</b></p>
<p><input class="bg-dark text-white form-control" type="text" placeholder="ai.example.org" id="custom-conn-address"></p>
<p><b class="translate" id="portCustomConnect">Enter port of server</b></p>
<p><input class="bg-dark text-white form-control" type="number" value="80" min="1" max="25565" placeholder="80" id="custom-conn-port"></p>
<p><b class="translate" id="tlsCustomConnect">Check this if server use TLS (wss:// connection):</b>
<input class="bg-dark text-white form-check-input" type="checkbox" id="custom-conn-encryption"></p>
</div>
<div class="modal-footer"><center>
<button type="button" class="btn btn-primary translate" data-bs-dismiss="modal" id="accept-denial-btn">Accept</button>
<!-- <button type="button" class="btn btn-primary">Сохранить изменения</button> -->
</center></div>
</div>
</div>
</div>

View File

@ -81,7 +81,10 @@ fl.bindLoad("/connect", () => {
xhr.onload = async () => {
if (xhr.status === 200) {
const servers = JSON.parse(xhr.response).result;
const localServers = JSON.parse(localStorage.getItem("savedServers") ?? "null") ?? [];
const servers = localServers.concat(JSON.parse(xhr.response).result);
const serversByItemID = new Object();
const items = [];
const itemIDs = [];
const mp = servers.map(async serverItem => {
@ -98,6 +101,7 @@ fl.bindLoad("/connect", () => {
...data,
itemID: `con-btn-to:${data.tag}:${serverItem.address}:${serverItem.port}`
});
serversByItemID[`con-btn-to:${data.tag}:${serverItem.address}:${serverItem.port}`] = { data, serverItem };
resolve(items.push(`<tr${!data.secureMode ? ' style="background-color: #7F6003"' : ""}>
<td${!data.secureMode ? ' style="background-color: #7F6003"' : ""}>${data.name}</td>
<td${!data.secureMode ? ' style="background-color: #7F6003"' : ""}>${serverItem.address}:${serverItem.port}</td>
@ -125,7 +129,7 @@ fl.bindLoad("/connect", () => {
});
await Promise.all(mp);
items.push(`<tr><td colspan="5"><center><button class="btn btn-primary">${tr("/connect", "add-custon-server") ?? "Connect to custom server"}</button></center></td></tr>`);
items.push(`<tr><td colspan="5"><center><button class="btn btn-primary" id="conn-to-custom">${tr("/connect", "add-custon-server") ?? "Connect to custom server"}</button></center></td></tr>`);
document.getElementById("loading-servers").innerHTML = `<table class="table table-dark">
<thead>
<th scope="col">${tr("/connect", "server-name-tbl") ?? "Name"}</th>
@ -141,9 +145,17 @@ fl.bindLoad("/connect", () => {
itemIDs.forEach(btn => {
document.getElementById(btn.itemID).onclick = () => {
checkContentWarning();
checkContentWarning(() => {
const serverInfo = serversByItemID[btn.itemID].serverItem;
window.open(`/connect-area?server=${serverInfo.address}:${serverInfo.port}`);
});
};
});
document.getElementById("conn-to-custom").onclick = function () {
const connectModal = new bootstrap.Modal(document.getElementById('connectModal'), {});
connectModal.show();
}
}
};

View File

@ -52,10 +52,16 @@ const translationTree = {
"accept-cookie-btn": "Accept",
loading: "Loading of servers...",
titleDenial: '<i class="fas fa-triangle-exclamation"></i> Denial of responsibility',
titleDenial: '<i class="fas fa-exclamation-triangle"></i> Denial of responsibility',
denialText: 'The server data does not belong to a centrally moderated foundation, community or individual, as well as to the developer of the software, program interface (protocol client), or protocol developer. Any content posted on servers is posted by the server administrator and can be absolutely anything. <b>You assume all risks for the content and connect to the server at your own peril and risk!</b>',
"accept-denial-btn": "Accept",
titleCustomServerConnect: '<i class="fas fa-wifi"></i> Connect to remote server',
titleCustomConnect: 'Connection Data',
addressCustomConnect: 'Enter address of server (without ws(s):// and port)',
portCustomConnect: 'Enter port of server',
tlsCustomConnect: 'Check this if server use TLS (wss:// connection):',
"server-name-tbl": "Name",
"server-address": "Address",
"server-encryption": "Encryprtion",
@ -78,10 +84,16 @@ const translationTree = {
"accept-cookie-btn": "Принять",
loading: "Загрузка серверов...",
titleDenial: '<i class="fas fa-triangle-exclamation"></i> Отказ от отвественности',
titleDenial: '<i class="fas fa-exclamation-triangle"></i> Отказ от отвественности',
denialText: 'Данные сервера не принадлежат централизованно-модерируемому фонду, сообществу или частному лицу, а также разработчику программного обеспечения, програмного интерфейса (клиента протокола), разработчику протокола. Любой размещённый на серверах контент размещается администратором сервера и может быть абсолютно любым. <b>Все риски за контент вы берёте полностью на себя и подключаетесь к серверу на свой страх и риск!</b>',
"accept-denial-btn": "Принять",
titleCustomServerConnect: '<i class="fas fa-wifi"></i> Прямое подключение к серверу',
titleCustomConnect: 'Данные подключения',
addressCustomConnect: 'Адрес сервера (без порта и ws(s)://)',
portCustomConnect: 'Порт сервера',
tlsCustomConnect: 'Использовать защищённое соединение (TLS) (wss://):',
"server-name-tbl": "Имя сервера",
"server-address": "Адрес",
"server-encryption": "Шифрование",
@ -104,8 +116,17 @@ Object.entries(translationTree).forEach(([page, langs]) => {
console.log(translationTree);
const simpleLangTags = {
"ru": "ru-RU",
"en": "en-US",
};
function tr (page, id) {
const lang = navigator.language || navigator.userLanguage;
let lang = navigator.language || navigator.userLanguage;
lang = lang.split("-").length === 1 ? (simpleLangTags[lang] ?? "en-US") : lang;
// Britains sucks, Sir Keir Starmer (Sir Dicksucker) is faggot, he is sucking a muslim's dicks.
if (lang === "en-UK")
lang = "en-US";
// console.log("lang is", lang);
return (translationTree[page]?.[lang]?.[id] ?? translationTree[page]?.["en-US"][id]) ?? null
}