mirror of
https://github.com/louislam/uptime-kuma.git
synced 2026-03-02 22:47:01 +00:00
fix(edit-monitor): several issues in the edit page (#7011)
This commit is contained in:
3
extra/update-language-files/.gitignore
vendored
3
extra/update-language-files/.gitignore
vendored
@@ -1,3 +0,0 @@
|
||||
package-lock.json
|
||||
test.js
|
||||
languages/
|
||||
@@ -1,105 +0,0 @@
|
||||
// Need to use ES6 to read language files
|
||||
|
||||
import fs from "fs";
|
||||
import util from "util";
|
||||
|
||||
/**
|
||||
* Copy across the required language files
|
||||
* Creates a local directory (./languages) and copies the required files
|
||||
* into it.
|
||||
* @param {string} langCode Code of language to update. A file will be
|
||||
* created with this code if one does not already exist
|
||||
* @param {string} baseLang The second base language file to copy. This
|
||||
* will be ignored if set to "en" as en.js is copied by default
|
||||
* @returns {void}
|
||||
*/
|
||||
function copyFiles(langCode, baseLang) {
|
||||
if (fs.existsSync("./languages")) {
|
||||
fs.rmSync("./languages", {
|
||||
recursive: true,
|
||||
force: true,
|
||||
});
|
||||
}
|
||||
fs.mkdirSync("./languages");
|
||||
|
||||
if (!fs.existsSync(`../../src/languages/${langCode}.js`)) {
|
||||
fs.closeSync(fs.openSync(`./languages/${langCode}.js`, "a"));
|
||||
} else {
|
||||
fs.copyFileSync(`../../src/languages/${langCode}.js`, `./languages/${langCode}.js`);
|
||||
}
|
||||
fs.copyFileSync("../../src/languages/en.js", "./languages/en.js");
|
||||
if (baseLang !== "en") {
|
||||
fs.copyFileSync(`../../src/languages/${baseLang}.js`, `./languages/${baseLang}.js`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified language file
|
||||
* @param {string} langCode Language code to update
|
||||
* @param {string} baseLangCode Second language to copy keys from
|
||||
* @returns {void}
|
||||
*/
|
||||
async function updateLanguage(langCode, baseLangCode) {
|
||||
const en = (await import("./languages/en.js")).default;
|
||||
const baseLang = (await import(`./languages/${baseLangCode}.js`)).default;
|
||||
|
||||
let file = langCode + ".js";
|
||||
console.log("Processing " + file);
|
||||
const lang = await import("./languages/" + file);
|
||||
|
||||
let obj;
|
||||
|
||||
if (lang.default) {
|
||||
obj = lang.default;
|
||||
} else {
|
||||
console.log("Empty file");
|
||||
obj = {
|
||||
languageName: "<Your Language name in your language (not in English)>",
|
||||
};
|
||||
}
|
||||
|
||||
// En first
|
||||
for (const key in en) {
|
||||
if (!obj[key]) {
|
||||
obj[key] = en[key];
|
||||
}
|
||||
}
|
||||
|
||||
if (baseLang !== en) {
|
||||
// Base second
|
||||
for (const key in baseLang) {
|
||||
if (!obj[key]) {
|
||||
obj[key] = key;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const code =
|
||||
"export default " +
|
||||
util.inspect(obj, {
|
||||
depth: null,
|
||||
});
|
||||
|
||||
fs.writeFileSync(`../../src/languages/${file}`, code);
|
||||
}
|
||||
|
||||
// Get command line arguments
|
||||
const baseLangCode = process.env.npm_config_baselang || "en";
|
||||
const langCode = process.env.npm_config_language;
|
||||
|
||||
// We need the file to edit
|
||||
if (langCode == null) {
|
||||
throw new Error("Argument --language=<code> must be provided");
|
||||
}
|
||||
|
||||
console.log("Base Lang: " + baseLangCode);
|
||||
console.log("Updating: " + langCode);
|
||||
|
||||
copyFiles(langCode, baseLangCode);
|
||||
await updateLanguage(langCode, baseLangCode);
|
||||
fs.rmSync("./languages", {
|
||||
recursive: true,
|
||||
force: true,
|
||||
});
|
||||
|
||||
console.log("Done. Fixing formatting by ESLint...");
|
||||
@@ -1,12 +0,0 @@
|
||||
{
|
||||
"name": "update-language-files",
|
||||
"type": "module",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC"
|
||||
}
|
||||
@@ -54,7 +54,6 @@
|
||||
"simple-mongo": "docker run --rm -p 27017:27017 mongo",
|
||||
"simple-postgres": "docker run --rm -p 5432:5432 -e POSTGRES_PASSWORD=postgres postgres",
|
||||
"simple-mariadb": "docker run --rm -p 3306:3306 -e MYSQL_ROOT_PASSWORD=mariadb# mariadb",
|
||||
"update-language-files": "cd extra/update-language-files && node index.js && cross-env-shell eslint ../../src/languages/$npm_config_language.js --fix",
|
||||
"release-final": "node ./extra/release/final.mjs",
|
||||
"release-beta": "node ./extra/release/beta.mjs",
|
||||
"release-nightly": "node ./extra/release/nightly.mjs",
|
||||
|
||||
@@ -39,6 +39,9 @@
|
||||
"General Monitor Type": "General Monitor Type",
|
||||
"Passive Monitor Type": "Passive Monitor Type",
|
||||
"Specific Monitor Type": "Specific Monitor Type",
|
||||
"monitorTypeGameServer": "Game Server",
|
||||
"monitorTypeDatabase": "Database Monitor Type",
|
||||
"monitorTypeSpecial": "Special",
|
||||
"markdownSupported": "Markdown syntax supported. If using HTML, avoid leading spaces to prevent formatting issues.",
|
||||
"pauseDashboardHome": "Pause",
|
||||
"Pause": "Pause",
|
||||
|
||||
@@ -35,18 +35,12 @@
|
||||
class="form-select"
|
||||
data-testid="monitor-type-select"
|
||||
>
|
||||
<!-- Unsorted, since HTTP is commonly used -->
|
||||
<optgroup :label="$t('General Monitor Type')">
|
||||
<option value="group">
|
||||
{{ $t("Group") }}
|
||||
</option>
|
||||
<option value="http">HTTP(s)</option>
|
||||
<option value="keyword">HTTP(s) - {{ $t("Keyword") }}</option>
|
||||
<option value="port">TCP Port</option>
|
||||
<option value="ping">Ping</option>
|
||||
<option value="smtp">SMTP</option>
|
||||
<option value="snmp">SNMP</option>
|
||||
<option value="keyword">HTTP(s) - {{ $t("Keyword") }}</option>
|
||||
<option value="json-query">HTTP(s) - {{ $t("Json Query") }}</option>
|
||||
<option value="grpc-keyword">gRPC(s) - {{ $t("Keyword") }}</option>
|
||||
<option value="dns">DNS</option>
|
||||
<option value="docker">
|
||||
{{ $t("Docker Container") }}
|
||||
@@ -63,7 +57,12 @@
|
||||
<option value="real-browser">
|
||||
HTTP(s) - Browser Engine (Chrome/Chromium) (Beta)
|
||||
</option>
|
||||
<option value="websocket-upgrade">Websocket Upgrade</option>
|
||||
</optgroup>
|
||||
|
||||
<optgroup :label="$t('monitorTypeSpecial')">
|
||||
<option value="group">
|
||||
{{ $t("Group") }}
|
||||
</option>
|
||||
</optgroup>
|
||||
|
||||
<optgroup :label="$t('Passive Monitor Type')">
|
||||
@@ -73,29 +72,43 @@
|
||||
</option>
|
||||
</optgroup>
|
||||
|
||||
<!-- Should sort from A to Z in this category -->
|
||||
<optgroup :label="$t('Specific Monitor Type')">
|
||||
<option value="globalping">
|
||||
{{ $t("Globalping - Access global monitoring probes") }}
|
||||
</option>
|
||||
<option value="steam">
|
||||
{{ $t("Steam Game Server") }}
|
||||
</option>
|
||||
<option value="gamedig">GameDig</option>
|
||||
<option value="grpc-keyword">gRPC(s) - {{ $t("Keyword") }}</option>
|
||||
<option value="json-query">HTTP(s) - {{ $t("Json Query") }}</option>
|
||||
<option value="kafka-producer">Kafka Producer</option>
|
||||
<option value="mqtt">MQTT</option>
|
||||
<option value="rabbitmq">RabbitMQ</option>
|
||||
<option value="kafka-producer">Kafka Producer</option>
|
||||
<option value="sqlserver">Microsoft SQL Server</option>
|
||||
<option value="postgres">PostgreSQL</option>
|
||||
<option value="mysql">MySQL/MariaDB</option>
|
||||
<option value="mongodb">MongoDB</option>
|
||||
<option value="radius">Radius</option>
|
||||
<option value="redis">Redis</option>
|
||||
<option v-if="!$root.info.isContainer" value="sip-options">
|
||||
SIP Options Ping
|
||||
</option>
|
||||
<option value="smtp">SMTP</option>
|
||||
<option value="snmp">SNMP</option>
|
||||
<option v-if="!$root.info.isContainer" value="tailscale-ping">
|
||||
Tailscale Ping
|
||||
</option>
|
||||
<option value="websocket-upgrade">Websocket Upgrade</option>
|
||||
</optgroup>
|
||||
|
||||
<!-- Should sort from A to Z in this category -->
|
||||
<optgroup :label="$t('monitorTypeDatabase')">
|
||||
<option value="sqlserver">Microsoft SQL Server</option>
|
||||
<option value="mongodb">MongoDB</option>
|
||||
<option value="mysql">MySQL/MariaDB</option>
|
||||
<option value="postgres">PostgreSQL</option>
|
||||
<option value="radius">Radius</option>
|
||||
<option value="redis">Redis</option>
|
||||
</optgroup>
|
||||
|
||||
<!-- Should sort from A to Z in this category -->
|
||||
<optgroup :label="$t('monitorTypeGameServer')">
|
||||
<option value="gamedig">GameDig</option>
|
||||
<option value="steam">
|
||||
{{ $t("Steam Game Server") }}
|
||||
</option>
|
||||
</optgroup>
|
||||
</select>
|
||||
<i18n-t
|
||||
@@ -2820,11 +2833,22 @@ const toast = useToast();
|
||||
|
||||
const pushTokenLength = 32;
|
||||
|
||||
const defaultValueList = {
|
||||
http: {
|
||||
url: "https://",
|
||||
accepted_statuscodes: ["200-299"],
|
||||
},
|
||||
"websocket-upgrade": {
|
||||
url: "wss://",
|
||||
accepted_statuscodes: ["1000"],
|
||||
},
|
||||
};
|
||||
|
||||
const monitorDefaults = {
|
||||
type: "http",
|
||||
name: "",
|
||||
parent: null,
|
||||
url: "https://",
|
||||
url: defaultValueList.http.url,
|
||||
wsSubprotocol: "",
|
||||
method: "GET",
|
||||
protocol: null,
|
||||
@@ -2842,7 +2866,7 @@ const monitorDefaults = {
|
||||
expiryNotification: false,
|
||||
domainExpiryNotification: false,
|
||||
maxredirects: 10,
|
||||
accepted_statuscodes: ["200-299"],
|
||||
accepted_statuscodes: defaultValueList.http.accepted_statuscodes,
|
||||
saveResponse: false,
|
||||
saveErrorResponse: true,
|
||||
responseMaxLength: 1024,
|
||||
@@ -3298,9 +3322,36 @@ message HealthCheckResponse {
|
||||
this.monitor.dns_resolve_server = "1.1.1.1";
|
||||
}
|
||||
|
||||
if (oldType && this.monitor.type === "websocket-upgrade") {
|
||||
this.monitor.url = "wss://";
|
||||
this.monitor.accepted_statuscodes = ["1000"];
|
||||
// Change to websocket-upgrade (override http defaults)
|
||||
if (newType === "websocket-upgrade") {
|
||||
if (!this.monitor.url || this.monitor.url === defaultValueList.http.url) {
|
||||
this.monitor.url = defaultValueList["websocket-upgrade"].url;
|
||||
}
|
||||
|
||||
if (
|
||||
!this.monitor.accepted_statuscodes ||
|
||||
(this.monitor.accepted_statuscodes.length === 1 &&
|
||||
this.monitor.accepted_statuscodes[0] === defaultValueList.http.accepted_statuscodes)
|
||||
) {
|
||||
this.monitor.accepted_statuscodes = defaultValueList["websocket-upgrade"].accepted_statuscodes;
|
||||
}
|
||||
}
|
||||
|
||||
// Change to http (override websocket-upgrade defaults)
|
||||
// Because user may see wss:// and default to http code 1000, which is strange for http monitor.
|
||||
if (["http", "keyword", "real-browser"].includes(newType)) {
|
||||
if (!this.monitor.url || this.monitor.url === defaultValueList["websocket-upgrade"].url) {
|
||||
this.monitor.url = defaultValueList.http.url;
|
||||
}
|
||||
|
||||
if (
|
||||
!this.monitor.accepted_statuscodes ||
|
||||
(this.monitor.accepted_statuscodes.length === 1 &&
|
||||
this.monitor.accepted_statuscodes[0] ===
|
||||
defaultValueList["websocket-upgrade"].accepted_statuscodes)
|
||||
) {
|
||||
this.monitor.accepted_statuscodes = defaultValueList.http.accepted_statuscodes;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.monitor.type === "push") {
|
||||
|
||||
Reference in New Issue
Block a user