mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-09-14 23:47:00 +08:00
Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
243726b03c | ||
|
936665aac3 | ||
|
1185b259c2 | ||
|
a81f949f98 | ||
|
59f10d542b | ||
|
2778929f74 | ||
|
f71d35e53e | ||
|
1490443618 | ||
|
add5c128ce |
6411
package-lock.json
generated
6411
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
14
package.json
14
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "uptime-kuma",
|
"name": "uptime-kuma",
|
||||||
"version": "1.23.12",
|
"version": "1.23.14",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -42,7 +42,7 @@
|
|||||||
"build-docker-nightly-amd64": "docker buildx build -f docker/dockerfile --platform linux/amd64 -t louislam/uptime-kuma:nightly-amd64 --target nightly . --push --progress plain",
|
"build-docker-nightly-amd64": "docker buildx build -f docker/dockerfile --platform linux/amd64 -t louislam/uptime-kuma:nightly-amd64 --target nightly . --push --progress plain",
|
||||||
"build-docker-pr-test": "docker buildx build -f docker/dockerfile --platform linux/amd64,linux/arm64 -t louislam/uptime-kuma:pr-test --target pr-test . --push",
|
"build-docker-pr-test": "docker buildx build -f docker/dockerfile --platform linux/amd64,linux/arm64 -t louislam/uptime-kuma:pr-test --target pr-test . --push",
|
||||||
"upload-artifacts": "docker buildx build -f docker/dockerfile --platform linux/amd64 -t louislam/uptime-kuma:upload-artifact --build-arg VERSION --build-arg GITHUB_TOKEN --target upload-artifact . --progress plain",
|
"upload-artifacts": "docker buildx build -f docker/dockerfile --platform linux/amd64 -t louislam/uptime-kuma:upload-artifact --build-arg VERSION --build-arg GITHUB_TOKEN --target upload-artifact . --progress plain",
|
||||||
"setup": "git checkout 1.23.12 && npm ci --production && npm run download-dist",
|
"setup": "git checkout 1.23.14 && npm ci --production && npm run download-dist",
|
||||||
"download-dist": "node extra/download-dist.js",
|
"download-dist": "node extra/download-dist.js",
|
||||||
"mark-as-nightly": "node extra/mark-as-nightly.js",
|
"mark-as-nightly": "node extra/mark-as-nightly.js",
|
||||||
"reset-password": "node extra/reset-password.js",
|
"reset-password": "node extra/reset-password.js",
|
||||||
@@ -78,7 +78,7 @@
|
|||||||
"start-server-node14-win": "private\\node14\\node.exe server/server.js"
|
"start-server-node14-win": "private\\node14\\node.exe server/server.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@grpc/grpc-js": "~1.7.3",
|
"@grpc/grpc-js": "~1.8.22",
|
||||||
"@louislam/ping": "~0.4.4-mod.1",
|
"@louislam/ping": "~0.4.4-mod.1",
|
||||||
"@louislam/sqlite3": "15.1.6",
|
"@louislam/sqlite3": "15.1.6",
|
||||||
"args-parser": "~1.3.0",
|
"args-parser": "~1.3.0",
|
||||||
@@ -97,7 +97,7 @@
|
|||||||
"croner": "~6.0.5",
|
"croner": "~6.0.5",
|
||||||
"dayjs": "~1.11.5",
|
"dayjs": "~1.11.5",
|
||||||
"dotenv": "~16.0.3",
|
"dotenv": "~16.0.3",
|
||||||
"express": "~4.19.2",
|
"express": "~4.21.0",
|
||||||
"express-basic-auth": "~1.2.1",
|
"express-basic-auth": "~1.2.1",
|
||||||
"express-static-gzip": "~2.1.7",
|
"express-static-gzip": "~2.1.7",
|
||||||
"form-data": "~4.0.0",
|
"form-data": "~4.0.0",
|
||||||
@@ -138,8 +138,8 @@
|
|||||||
"redbean-node": "~0.3.0",
|
"redbean-node": "~0.3.0",
|
||||||
"redis": "~4.5.1",
|
"redis": "~4.5.1",
|
||||||
"semver": "~7.5.4",
|
"semver": "~7.5.4",
|
||||||
"socket.io": "~4.6.1",
|
"socket.io": "~4.8.0",
|
||||||
"socket.io-client": "~4.6.1",
|
"socket.io-client": "~4.8.0",
|
||||||
"socks-proxy-agent": "6.1.1",
|
"socks-proxy-agent": "6.1.1",
|
||||||
"tar": "~6.2.1",
|
"tar": "~6.2.1",
|
||||||
"tcp-ping": "~0.1.1",
|
"tcp-ping": "~0.1.1",
|
||||||
@@ -171,7 +171,7 @@
|
|||||||
"cypress": "^13.2.0",
|
"cypress": "^13.2.0",
|
||||||
"delay": "^5.0.0",
|
"delay": "^5.0.0",
|
||||||
"dns2": "~2.0.1",
|
"dns2": "~2.0.1",
|
||||||
"dompurify": "~3.0.11",
|
"dompurify": "~3.1.7",
|
||||||
"eslint": "~8.14.0",
|
"eslint": "~8.14.0",
|
||||||
"eslint-plugin-vue": "~8.7.1",
|
"eslint-plugin-vue": "~8.7.1",
|
||||||
"favico.js": "~0.3.10",
|
"favico.js": "~0.3.10",
|
||||||
|
@@ -512,10 +512,16 @@ class Monitor extends BeanModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let tlsInfo;
|
let tlsInfo = {};
|
||||||
// Store tlsInfo when key material is received
|
// Store tlsInfo when secureConnect event is emitted
|
||||||
options.httpsAgent.on("keylog", (line, tlsSocket) => {
|
// The keylog event listener is a workaround to access the tlsSocket
|
||||||
tlsInfo = checkCertificate(tlsSocket);
|
options.httpsAgent.once("keylog", async (line, tlsSocket) => {
|
||||||
|
tlsSocket.once("secureConnect", async () => {
|
||||||
|
tlsInfo = checkCertificate(tlsSocket);
|
||||||
|
tlsInfo.valid = tlsSocket.authorized || false;
|
||||||
|
|
||||||
|
await this.handleTlsInfo(tlsInfo);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
log.debug("monitor", `[${this.name}] Axios Options: ${JSON.stringify(options)}`);
|
log.debug("monitor", `[${this.name}] Axios Options: ${JSON.stringify(options)}`);
|
||||||
@@ -527,19 +533,16 @@ class Monitor extends BeanModel {
|
|||||||
bean.msg = `${res.status} - ${res.statusText}`;
|
bean.msg = `${res.status} - ${res.statusText}`;
|
||||||
bean.ping = dayjs().valueOf() - startTime;
|
bean.ping = dayjs().valueOf() - startTime;
|
||||||
|
|
||||||
// Store certificate and check for expiry if https is used
|
// fallback for if kelog event is not emitted, but we may still have tlsInfo,
|
||||||
if (this.getUrl()?.protocol === "https:") {
|
// e.g. if the connection is made through a proxy
|
||||||
// No way to listen for the `secureConnection` event, so we do it here
|
if (this.getUrl()?.protocol === "https:" && tlsInfo.valid === undefined) {
|
||||||
const tlssocket = res.request.res.socket;
|
const tlsSocket = res.request.res.socket;
|
||||||
|
|
||||||
if (tlssocket) {
|
if (tlsSocket) {
|
||||||
tlsInfo.valid = tlssocket.authorized || false;
|
tlsInfo = checkCertificate(tlsSocket);
|
||||||
}
|
tlsInfo.valid = tlsSocket.authorized || false;
|
||||||
|
|
||||||
await this.updateTlsInfo(tlsInfo);
|
await this.handleTlsInfo(tlsInfo);
|
||||||
if (!this.getIgnoreTls() && this.isEnabledExpiryNotification()) {
|
|
||||||
log.debug("monitor", `[${this.name}] call checkCertExpiryNotifications`);
|
|
||||||
await this.checkCertExpiryNotifications(tlsInfo);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1679,6 +1682,21 @@ class Monitor extends BeanModel {
|
|||||||
const parentActive = await Monitor.isParentActive(parent.id);
|
const parentActive = await Monitor.isParentActive(parent.id);
|
||||||
return parent.active && parentActive;
|
return parent.active && parentActive;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store TLS certificate information and check for expiry
|
||||||
|
* @param {Object} tlsInfo Information about the TLS connection
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
async handleTlsInfo(tlsInfo) {
|
||||||
|
await this.updateTlsInfo(tlsInfo);
|
||||||
|
this.prometheus?.update(null, tlsInfo);
|
||||||
|
|
||||||
|
if (!this.getIgnoreTls() && this.isEnabledExpiryNotification()) {
|
||||||
|
log.debug("monitor", `[${this.name}] call checkCertExpiryNotifications`);
|
||||||
|
await this.checkCertExpiryNotifications(tlsInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Monitor;
|
module.exports = Monitor;
|
||||||
|
@@ -79,23 +79,25 @@ class Prometheus {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
if (heartbeat) {
|
||||||
monitorStatus.set(this.monitorLabelValues, heartbeat.status);
|
try {
|
||||||
} catch (e) {
|
monitorStatus.set(this.monitorLabelValues, heartbeat.status);
|
||||||
log.error("prometheus", "Caught error");
|
} catch (e) {
|
||||||
log.error("prometheus", e);
|
log.error("prometheus", "Caught error");
|
||||||
}
|
log.error("prometheus", e);
|
||||||
|
}
|
||||||
try {
|
|
||||||
if (typeof heartbeat.ping === "number") {
|
try {
|
||||||
monitorResponseTime.set(this.monitorLabelValues, heartbeat.ping);
|
if (typeof heartbeat.ping === "number") {
|
||||||
} else {
|
monitorResponseTime.set(this.monitorLabelValues, heartbeat.ping);
|
||||||
// Is it good?
|
} else {
|
||||||
monitorResponseTime.set(this.monitorLabelValues, -1);
|
// Is it good?
|
||||||
|
monitorResponseTime.set(this.monitorLabelValues, -1);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
log.error("prometheus", "Caught error");
|
||||||
|
log.error("prometheus", e);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
|
||||||
log.error("prometheus", "Caught error");
|
|
||||||
log.error("prometheus", e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -147,7 +147,7 @@ module.exports.statusPageSocketHandler = (socket) => {
|
|||||||
config.logo = `/upload/${filename}?t=` + Date.now();
|
config.logo = `/upload/${filename}?t=` + Date.now();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
config.icon = imgDataUrl;
|
config.logo = imgDataUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
statusPage.slug = config.slug;
|
statusPage.slug = config.slug;
|
||||||
|
@@ -1,53 +1,63 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<div class="add-btn">
|
<div
|
||||||
<button class="btn btn-primary me-2" type="button" @click="$refs.apiKeyDialog.show()">
|
v-if="settings.disableAuth"
|
||||||
<font-awesome-icon icon="plus" /> {{ $t("Add API Key") }}
|
class="mt-5 d-flex align-items-center justify-content-center my-3"
|
||||||
</button>
|
>
|
||||||
|
{{ $t("apiKeysDisabledMsg") }}
|
||||||
</div>
|
</div>
|
||||||
|
<div v-else>
|
||||||
|
<div class="add-btn">
|
||||||
|
<button class="btn btn-primary me-2" type="button" @click="$refs.apiKeyDialog.show()">
|
||||||
|
<font-awesome-icon icon="plus" /> {{ $t("Add API Key") }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<span v-if="Object.keys(keyList).length === 0" class="d-flex align-items-center justify-content-center my-3">
|
<span
|
||||||
{{ $t("No API Keys") }}
|
v-if="Object.keys(keyList).length === 0"
|
||||||
</span>
|
class="d-flex align-items-center justify-content-center my-3"
|
||||||
|
>
|
||||||
|
{{ $t("No API Keys") }}
|
||||||
|
</span>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
v-for="(item, index) in keyList"
|
v-for="(item, index) in keyList"
|
||||||
:key="index"
|
:key="index"
|
||||||
class="item"
|
class="item"
|
||||||
:class="item.status"
|
:class="item.status"
|
||||||
>
|
>
|
||||||
<div class="left-part">
|
<div class="left-part">
|
||||||
<div
|
<div class="circle"></div>
|
||||||
class="circle"
|
<div class="info">
|
||||||
></div>
|
<div class="title">{{ item.name }}</div>
|
||||||
<div class="info">
|
<div class="status">
|
||||||
<div class="title">{{ item.name }}</div>
|
{{ $t("apiKey-" + item.status) }}
|
||||||
<div class="status">
|
</div>
|
||||||
{{ $t("apiKey-" + item.status) }}
|
<div class="date">
|
||||||
</div>
|
{{ $t("Created") }}: {{ item.createdDate }}
|
||||||
<div class="date">
|
</div>
|
||||||
{{ $t("Created") }}: {{ item.createdDate }}
|
<div class="date">
|
||||||
</div>
|
{{ $t("Expires") }}:
|
||||||
<div class="date">
|
{{ item.expires || $t("Never") }}
|
||||||
{{ $t("Expires") }}: {{ item.expires || $t("Never") }}
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="buttons">
|
<div class="buttons">
|
||||||
<div class="btn-group" role="group">
|
<div class="btn-group" role="group">
|
||||||
<button v-if="item.active" class="btn btn-normal" @click="disableDialog(item.id)">
|
<button v-if="item.active" class="btn btn-normal" @click="disableDialog(item.id)">
|
||||||
<font-awesome-icon icon="pause" /> {{ $t("Disable") }}
|
<font-awesome-icon icon="pause" /> {{ $t("Disable") }}
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<button v-if="!item.active" class="btn btn-primary" @click="enableKey(item.id)">
|
<button v-if="!item.active" class="btn btn-primary" @click="enableKey(item.id)">
|
||||||
<font-awesome-icon icon="play" /> {{ $t("Enable") }}
|
<font-awesome-icon icon="play" /> {{ $t("Enable") }}
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<button class="btn btn-danger" @click="deleteDialog(item.id)">
|
<button class="btn btn-danger" @click="deleteDialog(item.id)">
|
||||||
<font-awesome-icon icon="trash" /> {{ $t("Delete") }}
|
<font-awesome-icon icon="trash" /> {{ $t("Delete") }}
|
||||||
</button>
|
</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -90,6 +100,9 @@ export default {
|
|||||||
let result = Object.values(this.$root.apiKeyList);
|
let result = Object.values(this.$root.apiKeyList);
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
|
settings() {
|
||||||
|
return this.$parent.$parent.$parent.settings;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
@@ -127,9 +140,11 @@ export default {
|
|||||||
* Pause maintenance
|
* Pause maintenance
|
||||||
*/
|
*/
|
||||||
disableKey() {
|
disableKey() {
|
||||||
this.$root.getSocket().emit("disableAPIKey", this.selectedKeyID, (res) => {
|
this.$root
|
||||||
this.$root.toastRes(res);
|
.getSocket()
|
||||||
});
|
.emit("disableAPIKey", this.selectedKeyID, (res) => {
|
||||||
|
this.$root.toastRes(res);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -145,113 +160,113 @@ export default {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
@import "../../assets/vars.scss";
|
@import "../../assets/vars.scss";
|
||||||
|
|
||||||
.mobile {
|
|
||||||
.item {
|
|
||||||
flex-direction: column;
|
|
||||||
align-items: flex-start;
|
|
||||||
margin-bottom: 20px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.add-btn {
|
|
||||||
padding-top: 20px;
|
|
||||||
padding-bottom: 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
.mobile {
|
||||||
.item {
|
.item {
|
||||||
display: flex;
|
flex-direction: column;
|
||||||
align-items: center;
|
align-items: flex-start;
|
||||||
gap: 10px;
|
margin-bottom: 20px;
|
||||||
text-decoration: none;
|
}
|
||||||
border-radius: 10px;
|
}
|
||||||
transition: all ease-in-out 0.15s;
|
|
||||||
justify-content: space-between;
|
|
||||||
padding: 10px;
|
|
||||||
min-height: 90px;
|
|
||||||
margin-bottom: 5px;
|
|
||||||
|
|
||||||
&:hover {
|
.add-btn {
|
||||||
background-color: $highlight-white;
|
padding-top: 20px;
|
||||||
|
padding-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.item {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
text-decoration: none;
|
||||||
|
border-radius: 10px;
|
||||||
|
transition: all ease-in-out 0.15s;
|
||||||
|
justify-content: space-between;
|
||||||
|
padding: 10px;
|
||||||
|
min-height: 90px;
|
||||||
|
margin-bottom: 5px;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background-color: $highlight-white;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.active {
|
||||||
|
.circle {
|
||||||
|
background-color: $primary;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
&.active {
|
&.inactive {
|
||||||
.circle {
|
.circle {
|
||||||
background-color: $primary;
|
background-color: $danger;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&.inactive {
|
|
||||||
.circle {
|
|
||||||
background-color: $danger;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&.expired {
|
|
||||||
.left-part {
|
|
||||||
opacity: 0.3;
|
|
||||||
}
|
|
||||||
|
|
||||||
.circle {
|
|
||||||
background-color: $dark-font-color;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&.expired {
|
||||||
.left-part {
|
.left-part {
|
||||||
display: flex;
|
opacity: 0.3;
|
||||||
gap: 12px;
|
|
||||||
align-items: center;
|
|
||||||
|
|
||||||
.circle {
|
|
||||||
width: 25px;
|
|
||||||
height: 25px;
|
|
||||||
border-radius: 50rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.info {
|
|
||||||
.title {
|
|
||||||
font-weight: bold;
|
|
||||||
font-size: 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.status {
|
|
||||||
font-size: 14px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.buttons {
|
.circle {
|
||||||
display: flex;
|
background-color: $dark-font-color;
|
||||||
gap: 8px;
|
}
|
||||||
flex-direction: row-reverse;
|
}
|
||||||
|
|
||||||
.btn-group {
|
.left-part {
|
||||||
width: 310px;
|
display: flex;
|
||||||
|
gap: 12px;
|
||||||
|
align-items: center;
|
||||||
|
|
||||||
|
.circle {
|
||||||
|
width: 25px;
|
||||||
|
height: 25px;
|
||||||
|
border-radius: 50rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.info {
|
||||||
|
.title {
|
||||||
|
font-weight: bold;
|
||||||
|
font-size: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status {
|
||||||
|
font-size: 14px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.date {
|
.buttons {
|
||||||
margin-top: 5px;
|
display: flex;
|
||||||
display: block;
|
gap: 8px;
|
||||||
font-size: 14px;
|
flex-direction: row-reverse;
|
||||||
background-color: rgba(255, 255, 255, 0.5);
|
|
||||||
border-radius: 20px;
|
|
||||||
padding: 0 10px;
|
|
||||||
width: fit-content;
|
|
||||||
|
|
||||||
.dark & {
|
.btn-group {
|
||||||
color: white;
|
width: 310px;
|
||||||
background-color: rgba(255, 255, 255, 0.1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.dark {
|
.date {
|
||||||
.item {
|
margin-top: 5px;
|
||||||
&:hover {
|
display: block;
|
||||||
background-color: $dark-bg2;
|
font-size: 14px;
|
||||||
}
|
background-color: rgba(255, 255, 255, 0.5);
|
||||||
|
border-radius: 20px;
|
||||||
|
padding: 0 10px;
|
||||||
|
width: fit-content;
|
||||||
|
|
||||||
|
.dark & {
|
||||||
|
color: white;
|
||||||
|
background-color: rgba(255, 255, 255, 0.1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.dark {
|
||||||
|
.item {
|
||||||
|
&:hover {
|
||||||
|
background-color: $dark-bg2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
19
src/i18n.js
19
src/i18n.js
@@ -63,9 +63,22 @@ const rtlLangs = [ "fa", "ar-SY", "ur" ];
|
|||||||
* @returns {string} the locale that should be displayed
|
* @returns {string} the locale that should be displayed
|
||||||
*/
|
*/
|
||||||
export function currentLocale() {
|
export function currentLocale() {
|
||||||
const potentialLocales = [ localStorage.locale, navigator.language, navigator.language.substring(0, 2), ...navigator.languages ];
|
for (const locale of [ localStorage.locale, navigator.language, ...navigator.languages ]) {
|
||||||
const availableLocales = potentialLocales.filter(l => languageList[l]);
|
// localstorage might not have a value or there might not be a language in `navigator.language`
|
||||||
return availableLocales[0] || "en";
|
if (!locale) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (locale in messages) {
|
||||||
|
return locale;
|
||||||
|
}
|
||||||
|
// some locales are further specified such as "en-US".
|
||||||
|
// If we only have a generic locale for this, we can use it too
|
||||||
|
const genericLocale = locale.split("-")[0];
|
||||||
|
if (genericLocale in messages) {
|
||||||
|
return genericLocale;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "en";
|
||||||
}
|
}
|
||||||
|
|
||||||
export const localeDirection = () => {
|
export const localeDirection = () => {
|
||||||
|
@@ -820,5 +820,6 @@
|
|||||||
"showCertificateExpiry": "Show Certificate Expiry",
|
"showCertificateExpiry": "Show Certificate Expiry",
|
||||||
"noOrBadCertificate": "No/Bad Certificate",
|
"noOrBadCertificate": "No/Bad Certificate",
|
||||||
"gamedigGuessPort": "Gamedig: Guess Port",
|
"gamedigGuessPort": "Gamedig: Guess Port",
|
||||||
"gamedigGuessPortDescription": "The port used by Valve Server Query Protocol may be different from the client port. Try this if the monitor cannot connect to your server."
|
"gamedigGuessPortDescription": "The port used by Valve Server Query Protocol may be different from the client port. Try this if the monitor cannot connect to your server.",
|
||||||
|
"apiKeysDisabledMsg": "API keys are disabled because authentication is disabled."
|
||||||
}
|
}
|
||||||
|
23
src/util.js
23
src/util.js
@@ -6,9 +6,12 @@
|
|||||||
//
|
//
|
||||||
// Backend uses the compiled file util.js
|
// Backend uses the compiled file util.js
|
||||||
// Frontend uses util.ts
|
// Frontend uses util.ts
|
||||||
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.localToUTC = exports.utcToLocal = exports.utcToISODateTime = exports.isoToUTCDateTime = exports.parseTimeFromTimeObject = exports.parseTimeObject = exports.getMaintenanceRelativeURL = exports.getMonitorRelativeURL = exports.genSecret = exports.getCryptoRandomInt = exports.getRandomInt = exports.getRandomArbitrary = exports.TimeLogger = exports.polyfill = exports.log = exports.debug = exports.ucfirst = exports.sleep = exports.flipStatus = exports.badgeConstants = exports.MIN_INTERVAL_SECOND = exports.MAX_INTERVAL_SECOND = exports.SQL_DATETIME_FORMAT_WITHOUT_SECOND = exports.SQL_DATETIME_FORMAT = exports.SQL_DATE_FORMAT = exports.STATUS_PAGE_MAINTENANCE = exports.STATUS_PAGE_PARTIAL_DOWN = exports.STATUS_PAGE_ALL_UP = exports.STATUS_PAGE_ALL_DOWN = exports.MAINTENANCE = exports.PENDING = exports.UP = exports.DOWN = exports.appName = exports.isDev = void 0;
|
exports.localToUTC = exports.utcToLocal = exports.utcToISODateTime = exports.isoToUTCDateTime = exports.parseTimeFromTimeObject = exports.parseTimeObject = exports.getMaintenanceRelativeURL = exports.getMonitorRelativeURL = exports.genSecret = exports.getCryptoRandomInt = exports.getRandomInt = exports.getRandomArbitrary = exports.TimeLogger = exports.polyfill = exports.log = exports.debug = exports.ucfirst = exports.sleep = exports.flipStatus = exports.badgeConstants = exports.MIN_INTERVAL_SECOND = exports.MAX_INTERVAL_SECOND = exports.SQL_DATETIME_FORMAT_WITHOUT_SECOND = exports.SQL_DATETIME_FORMAT = exports.SQL_DATE_FORMAT = exports.STATUS_PAGE_MAINTENANCE = exports.STATUS_PAGE_PARTIAL_DOWN = exports.STATUS_PAGE_ALL_UP = exports.STATUS_PAGE_ALL_DOWN = exports.MAINTENANCE = exports.PENDING = exports.UP = exports.DOWN = exports.appName = exports.isDev = void 0;
|
||||||
const dayjs = require("dayjs");
|
const dayjs_1 = __importDefault(require("dayjs"));
|
||||||
exports.isDev = process.env.NODE_ENV === "development";
|
exports.isDev = process.env.NODE_ENV === "development";
|
||||||
exports.appName = "Uptime Kuma";
|
exports.appName = "Uptime Kuma";
|
||||||
exports.DOWN = 0;
|
exports.DOWN = 0;
|
||||||
@@ -129,11 +132,11 @@ class Logger {
|
|||||||
module = module.toUpperCase();
|
module = module.toUpperCase();
|
||||||
level = level.toUpperCase();
|
level = level.toUpperCase();
|
||||||
let now;
|
let now;
|
||||||
if (dayjs.tz) {
|
if (dayjs_1.default.tz) {
|
||||||
now = dayjs.tz(new Date()).format();
|
now = dayjs_1.default.tz(new Date()).format();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
now = dayjs().format();
|
now = (0, dayjs_1.default)().format();
|
||||||
}
|
}
|
||||||
const formattedMessage = (typeof msg === "string") ? `${now} [${module}] ${level}: ${msg}` : msg;
|
const formattedMessage = (typeof msg === "string") ? `${now} [${module}] ${level}: ${msg}` : msg;
|
||||||
if (level === "INFO") {
|
if (level === "INFO") {
|
||||||
@@ -222,7 +225,7 @@ function polyfill() {
|
|||||||
exports.polyfill = polyfill;
|
exports.polyfill = polyfill;
|
||||||
class TimeLogger {
|
class TimeLogger {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.startTime = dayjs().valueOf();
|
this.startTime = (0, dayjs_1.default)().valueOf();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Output time since start of monitor
|
* Output time since start of monitor
|
||||||
@@ -230,7 +233,7 @@ class TimeLogger {
|
|||||||
*/
|
*/
|
||||||
print(name) {
|
print(name) {
|
||||||
if (exports.isDev && process.env.TIMELOGGER === "1") {
|
if (exports.isDev && process.env.TIMELOGGER === "1") {
|
||||||
console.log(name + ": " + (dayjs().valueOf() - this.startTime) + "ms");
|
console.log(name + ": " + ((0, dayjs_1.default)().valueOf() - this.startTime) + "ms");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -394,21 +397,21 @@ exports.parseTimeFromTimeObject = parseTimeFromTimeObject;
|
|||||||
* @returns ISO Date time
|
* @returns ISO Date time
|
||||||
*/
|
*/
|
||||||
function isoToUTCDateTime(input) {
|
function isoToUTCDateTime(input) {
|
||||||
return dayjs(input).utc().format(exports.SQL_DATETIME_FORMAT);
|
return (0, dayjs_1.default)(input).utc().format(exports.SQL_DATETIME_FORMAT);
|
||||||
}
|
}
|
||||||
exports.isoToUTCDateTime = isoToUTCDateTime;
|
exports.isoToUTCDateTime = isoToUTCDateTime;
|
||||||
/**
|
/**
|
||||||
* @param input
|
* @param input
|
||||||
*/
|
*/
|
||||||
function utcToISODateTime(input) {
|
function utcToISODateTime(input) {
|
||||||
return dayjs.utc(input).toISOString();
|
return dayjs_1.default.utc(input).toISOString();
|
||||||
}
|
}
|
||||||
exports.utcToISODateTime = utcToISODateTime;
|
exports.utcToISODateTime = utcToISODateTime;
|
||||||
/**
|
/**
|
||||||
* For SQL_DATETIME_FORMAT
|
* For SQL_DATETIME_FORMAT
|
||||||
*/
|
*/
|
||||||
function utcToLocal(input, format = exports.SQL_DATETIME_FORMAT) {
|
function utcToLocal(input, format = exports.SQL_DATETIME_FORMAT) {
|
||||||
return dayjs.utc(input).local().format(format);
|
return dayjs_1.default.utc(input).local().format(format);
|
||||||
}
|
}
|
||||||
exports.utcToLocal = utcToLocal;
|
exports.utcToLocal = utcToLocal;
|
||||||
/**
|
/**
|
||||||
@@ -418,6 +421,6 @@ exports.utcToLocal = utcToLocal;
|
|||||||
* @returns Date in requested format
|
* @returns Date in requested format
|
||||||
*/
|
*/
|
||||||
function localToUTC(input, format = exports.SQL_DATETIME_FORMAT) {
|
function localToUTC(input, format = exports.SQL_DATETIME_FORMAT) {
|
||||||
return dayjs(input).utc().format(format);
|
return (0, dayjs_1.default)(input).utc().format(format);
|
||||||
}
|
}
|
||||||
exports.localToUTC = localToUTC;
|
exports.localToUTC = localToUTC;
|
||||||
|
@@ -6,7 +6,7 @@
|
|||||||
// Backend uses the compiled file util.js
|
// Backend uses the compiled file util.js
|
||||||
// Frontend uses util.ts
|
// Frontend uses util.ts
|
||||||
|
|
||||||
import * as dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import * as timezone from "dayjs/plugin/timezone";
|
import * as timezone from "dayjs/plugin/timezone";
|
||||||
import * as utc from "dayjs/plugin/utc";
|
import * as utc from "dayjs/plugin/utc";
|
||||||
|
|
||||||
|
@@ -3,46 +3,62 @@ import { currentLocale } from "../../../src/i18n";
|
|||||||
describe("Test i18n.js", () => {
|
describe("Test i18n.js", () => {
|
||||||
|
|
||||||
it("currentLocale()", () => {
|
it("currentLocale()", () => {
|
||||||
const setLanguage = (language) => {
|
const setLanguages = (languages) => {
|
||||||
Object.defineProperty(window.navigator, 'language', {
|
Object.defineProperty(navigator, 'language', {
|
||||||
value: language,
|
value: languages[0],
|
||||||
writable: true
|
writable: true
|
||||||
});
|
});
|
||||||
Object.defineProperty(window.navigator, 'languages', {
|
Object.defineProperty(navigator, 'languages', {
|
||||||
value: [language],
|
value: languages,
|
||||||
writable: true
|
writable: true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
setLanguage('en-EN');
|
|
||||||
|
|
||||||
|
setLanguages(['en-EN']);
|
||||||
expect(currentLocale()).equal("en");
|
expect(currentLocale()).equal("en");
|
||||||
|
|
||||||
setLanguage('zh-HK');
|
setLanguages(['zh-HK']);
|
||||||
expect(currentLocale()).equal("zh-HK");
|
expect(currentLocale()).equal("zh-HK");
|
||||||
|
|
||||||
// Note that in Safari on iOS prior to 10.2, the country code returned is lowercase: "en-us", "fr-fr" etc.
|
// Note that in Safari on iOS prior to 10.2, the country code returned is lowercase: "en-us", "fr-fr" etc.
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/API/Navigator/language
|
// https://developer.mozilla.org/en-US/docs/Web/API/Navigator/language
|
||||||
setLanguage('zh-hk');
|
setLanguages(['zh-hk']);
|
||||||
expect(currentLocale()).equal("en");
|
expect(currentLocale()).equal("en");
|
||||||
|
|
||||||
setLanguage('en-US');
|
setLanguages(['en-US']);
|
||||||
expect(currentLocale()).equal("en");
|
expect(currentLocale()).equal("en");
|
||||||
|
|
||||||
setLanguage('ja-ZZ');
|
setLanguages(['ja-ZZ']);
|
||||||
expect(currentLocale()).equal("ja");
|
expect(currentLocale()).equal("ja");
|
||||||
|
|
||||||
setLanguage('zz-ZZ');
|
setLanguages(['zz-ZZ']);
|
||||||
expect(currentLocale()).equal("en");
|
expect(currentLocale()).equal("en");
|
||||||
|
|
||||||
setLanguage('zz-ZZ');
|
setLanguages(['zz-ZZ']);
|
||||||
expect(currentLocale()).equal("en");
|
expect(currentLocale()).equal("en");
|
||||||
|
|
||||||
setLanguage('en');
|
setLanguages(['en-US', 'en', 'pl', 'ja']);
|
||||||
localStorage.locale = "en";
|
|
||||||
expect(currentLocale()).equal("en");
|
expect(currentLocale()).equal("en");
|
||||||
|
|
||||||
localStorage.locale = "zh-HK";
|
setLanguages(['en-US', 'pl', 'ja']);
|
||||||
expect(currentLocale()).equal("zh-HK");
|
expect(currentLocale()).equal("en");
|
||||||
|
|
||||||
|
setLanguages(['abc', 'en-US', 'pl', 'ja']);
|
||||||
|
expect(currentLocale()).equal("en");
|
||||||
|
|
||||||
|
setLanguages(['fil-PH', 'pl']);
|
||||||
|
expect(currentLocale()).equal("pl");
|
||||||
|
|
||||||
|
setLanguages(['shi-Latn-MA', 'pl']);
|
||||||
|
expect(currentLocale()).equal("pl");
|
||||||
|
|
||||||
|
setLanguages(['pl']);
|
||||||
|
localStorage.locale = "ja-ZZ";
|
||||||
|
expect(currentLocale()).equal("ja");
|
||||||
|
|
||||||
|
setLanguages(['pl']);
|
||||||
|
localStorage.locale = "invalid-lang";
|
||||||
|
expect(currentLocale()).equal("pl");
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@@ -11,7 +11,8 @@
|
|||||||
"removeComments": false,
|
"removeComments": false,
|
||||||
"preserveConstEnums": true,
|
"preserveConstEnums": true,
|
||||||
"sourceMap": false,
|
"sourceMap": false,
|
||||||
"strict": true
|
"strict": true,
|
||||||
|
"esModuleInterop": true
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"./src/util.ts"
|
"./src/util.ts"
|
||||||
|
Reference in New Issue
Block a user