Compare commits

...

16 commits

Author SHA1 Message Date
Mohammad Jibin
c084d52dfc
Merge be83595a19 into 46d8744fa4 2024-10-27 05:22:34 +00:00
Louis Lam
46d8744fa4
Fix: Docker Healthcheck is not happy during migration (#5258)
Some checks are pending
Auto Test / auto-test (18, ARM64) (push) Blocked by required conditions
Auto Test / auto-test (18, macos-latest) (push) Blocked by required conditions
Auto Test / auto-test (18, ubuntu-latest) (push) Blocked by required conditions
Auto Test / auto-test (18, windows-latest) (push) Blocked by required conditions
Auto Test / auto-test (20, ARM64) (push) Blocked by required conditions
Auto Test / auto-test (20, macos-latest) (push) Blocked by required conditions
Auto Test / auto-test (20, ubuntu-latest) (push) Blocked by required conditions
Auto Test / auto-test (20, windows-latest) (push) Blocked by required conditions
Auto Test / armv7-simple-test (18, ARMv7) (push) Waiting to run
Auto Test / armv7-simple-test (20, ARMv7) (push) Waiting to run
Auto Test / check-linters (push) Waiting to run
Auto Test / e2e-test (push) Waiting to run
CodeQL / Analyze (push) Waiting to run
Merge Conflict Labeler / Labeling (push) Waiting to run
json-yaml-validate / json-yaml-validate (push) Waiting to run
json-yaml-validate / check-lang-json (push) Waiting to run
2024-10-27 13:22:23 +08:00
Louis Lam
7d8dc55dbe
Fix: the rootless user put in the wrong place (#5257) 2024-10-27 11:47:30 +08:00
Frank Elsinga
be83595a19
Merge branch 'master' into feature/time-format 2024-05-20 00:18:21 +02:00
Substancia
15d7f5d348 load once and cache 2023-10-09 15:01:00 +05:30
Substancia
1db6722670 Merge branch 'feature/time-format' of github.com-substancia:Substancia/uptime-kuma into feature/time-format 2023-10-08 13:37:02 +05:30
Mohammad Jibin
556d98754d
Merge branch 'louislam:master' into feature/time-format 2023-10-08 13:36:16 +05:30
Substancia
449f68e20b fix PR tasks 2023-10-08 13:35:32 +05:30
Mohammad Jibin
be31cbe842
Merge branch 'master' into feature/time-format 2023-10-04 01:22:24 +05:30
Substancia
0fbf2f375f fix PR comments 2023-10-03 03:50:04 +05:30
Substancia
5e9d562712 cleanup 2023-10-03 02:40:22 +05:30
Substancia
7a4918d493 move time format change to settings 2023-10-03 02:22:16 +05:30
Mohammad Jibin
06a9e47f62
Merge branch 'louislam:master' into feature/time-format 2023-10-02 23:31:14 +05:30
Substancia
e1d47c56a5 fix lint 2023-10-02 19:34:58 +05:30
Substancia
dbaf84fe39 feat: add support for 12-hour time format 2023-10-02 19:27:49 +05:30
Substancia
e897a96c17 [empty commit] pull request for Substancia 2023-10-02 19:26:47 +05:30
12 changed files with 216 additions and 16 deletions

View file

@ -27,7 +27,6 @@ RUN mkdir ./data
# ⭐ Main Image
############################################
FROM $BASE_IMAGE AS release
USER node
WORKDIR /app
LABEL org.opencontainers.image.source="https://github.com/louislam/uptime-kuma"
@ -46,6 +45,7 @@ CMD ["node", "server/server.js"]
# Rootless Image
############################################
FROM release AS rootless
USER node
############################################
# Mark as Nightly

View file

@ -9,6 +9,7 @@ const mysql = require("mysql2/promise");
const { Settings } = require("./settings");
const { UptimeCalculator } = require("./uptime-calculator");
const dayjs = require("dayjs");
const { SimpleMigrationServer } = require("./utils/simple-migration-server");
/**
* Database & App Data Folder
@ -382,9 +383,11 @@ class Database {
/**
* Patch the database
* @param {number} port Start the migration server for aggregate tables on this port if provided
* @param {string} hostname Start the migration server for aggregate tables on this hostname if provided
* @returns {Promise<void>}
*/
static async patch() {
static async patch(port = undefined, hostname = undefined) {
// Still need to keep this for old versions of Uptime Kuma
if (Database.dbConfig.type === "sqlite") {
await this.patchSqlite();
@ -409,7 +412,7 @@ class Database {
await R.exec("PRAGMA foreign_keys = ON");
}
await this.migrateAggregateTable();
await this.migrateAggregateTable(port, hostname);
} catch (e) {
// Allow missing patch files for downgrade or testing pr.
@ -735,9 +738,11 @@ class Database {
* Normally, it should be in transaction, but UptimeCalculator wasn't designed to be in transaction before that.
* I don't want to heavily modify the UptimeCalculator, so it is not in transaction.
* Run `npm run reset-migrate-aggregate-table-state` to reset, in case the migration is interrupted.
* @param {number} port Start the migration server on this port if provided
* @param {string} hostname Start the migration server on this hostname if provided
* @returns {Promise<void>}
*/
static async migrateAggregateTable() {
static async migrateAggregateTable(port, hostname = undefined) {
log.debug("db", "Enter Migrate Aggregate Table function");
// Add a setting for 2.0.0-dev users to skip this migration
@ -758,6 +763,18 @@ class Database {
throw new Error("Aggregate table migration is already in progress");
}
/**
* Start migration server for displaying the migration status
* @type {SimpleMigrationServer}
*/
let migrationServer;
let msg;
if (port) {
migrationServer = new SimpleMigrationServer();
await migrationServer.start(port, hostname);
}
await Settings.set("migrateAggregateTableState", "migrating");
log.info("db", "Migrating Aggregate Table");
@ -777,6 +794,7 @@ class Database {
let count = countResult.count;
if (count > 0) {
log.warn("db", `Aggregate table ${table} is not empty, migration will not be started (Maybe you were using 2.0.0-dev?)`);
await migrationServer?.stop();
return;
}
}
@ -811,7 +829,9 @@ class Database {
`, [ monitor.monitor_id, date.date ]);
if (heartbeats.length > 0) {
log.info("db", `[DON'T STOP] Migrating monitor data ${monitor.monitor_id} - ${date.date} [${progressPercent.toFixed(2)}%][${i}/${monitors.length}]`);
msg = `[DON'T STOP] Migrating monitor data ${monitor.monitor_id} - ${date.date} [${progressPercent.toFixed(2)}%][${i}/${monitors.length}]`;
log.info("db", msg);
migrationServer?.update(msg);
}
for (let heartbeat of heartbeats) {
@ -829,9 +849,13 @@ class Database {
i++;
}
await Database.clearHeartbeatData(true);
msg = "Clearing non-important heartbeats";
log.info("db", msg);
migrationServer?.update(msg);
await Database.clearHeartbeatData(true);
await Settings.set("migrateAggregateTableState", "migrated");
await migrationServer?.stop();
if (monitors.length > 0) {
log.info("db", "Aggregate Table Migration Completed");

View file

@ -1716,7 +1716,7 @@ async function initDatabase(testMode = false) {
log.info("server", "Connected to the database");
// Patch the database
await Database.patch();
await Database.patch(port, hostname);
let jwtSecretBean = await R.findOne("setting", " `key` = ? ", [
"jwtSecret",

View file

@ -0,0 +1,84 @@
const express = require("express");
const http = require("node:http");
const { log } = require("../../src/util");
/**
* SimpleMigrationServer
* For displaying the migration status of the server
* Also, it is used to let Docker healthcheck know the status of the server, as the main server is not started yet, healthcheck will think the server is down incorrectly.
*/
class SimpleMigrationServer {
/**
* Express app instance
* @type {?Express}
*/
app;
/**
* Server instance
* @type {?Server}
*/
server;
/**
* Response object
* @type {?Response}
*/
response;
/**
* Start the server
* @param {number} port Port
* @param {string} hostname Hostname
* @returns {Promise<void>}
*/
start(port, hostname) {
this.app = express();
this.server = http.createServer(this.app);
this.app.get("/", (req, res) => {
res.set("Content-Type", "text/plain");
res.write("Migration is in progress, listening message...\n");
if (this.response) {
this.response.write("Disconnected\n");
this.response.end();
}
this.response = res;
// never ending response
});
return new Promise((resolve) => {
this.server.listen(port, hostname, () => {
if (hostname) {
log.info("migration", `Migration server is running on http://${hostname}:${port}`);
} else {
log.info("migration", `Migration server is running on http://localhost:${port}`);
}
resolve();
});
});
}
/**
* Update the message
* @param {string} msg Message to update
* @returns {void}
*/
update(msg) {
this.response?.write(msg + "\n");
}
/**
* Stop the server
* @returns {Promise<void>}
*/
async stop() {
this.response?.write("Finished, please refresh this page.\n");
this.response?.end();
await this.server?.close();
}
}
module.exports = {
SimpleMigrationServer,
};

View file

@ -15,6 +15,10 @@ export default {
type: Boolean,
default: false,
},
use12HourTimeFormat: {
type: Boolean,
default: false
},
},
computed: {
@ -22,7 +26,7 @@ export default {
if (this.dateOnly) {
return this.$root.date(this.value);
} else {
return this.$root.datetime(this.value);
return this.$root.datetime(this.value, this.use12HourTimeFormat);
}
},
},

View file

@ -40,6 +40,10 @@ export default {
type: Number,
required: true,
},
use12HourTimeFormat: {
type: Boolean,
default: false
}
},
data() {
return {
@ -64,6 +68,13 @@ export default {
},
computed: {
chartOptions() {
const hourTimeFormat = this.use12HourTimeFormat ? "hh" : "HH";
const minuteTimeFormat = `${hourTimeFormat}:mm${
this.use12HourTimeFormat ? " A" : ""
}`;
const tooltipFormat = `YYYY-MM-DD ${hourTimeFormat}:mm:ss${
this.use12HourTimeFormat ? " A" : ""
}`;
return {
responsive: true,
maintainAspectRatio: false,
@ -101,10 +112,10 @@ export default {
time: {
minUnit: "minute",
round: "second",
tooltipFormat: "YYYY-MM-DD HH:mm:ss",
tooltipFormat,
displayFormats: {
minute: "HH:mm",
hour: "MM-DD HH:mm",
minute: minuteTimeFormat,
hour: `MM-DD ${minuteTimeFormat}`,
}
},
ticks: {

View file

@ -37,6 +37,42 @@
</select>
</div>
<!-- Time Format -->
<div class="mb-4">
<label class="form-label">
{{ $t("Time Format") }}
</label>
<div class="form-check">
<input
id="timeFormatIndex12Hour"
v-model="settings.use12HourTimeFormat"
class="form-check-input"
type="radio"
name="timeFormatIndex"
:value="true"
required
/>
<label class="form-check-label" for="timeFormatIndex12Hour">
{{ $t("12-hour") }}
</label>
</div>
<div class="form-check">
<input
id="timeFormatIndex24Hour"
v-model="settings.use12HourTimeFormat"
class="form-check-input"
type="radio"
name="timeFormatIndex"
:value="false"
required
/>
<label class="form-check-label" for="timeFormatIndex24Hour">
{{ $t("24-hour") }}
</label>
</div>
</div>
<!-- Search Engine -->
<div class="mb-4">
<label class="form-label">
@ -259,6 +295,7 @@ export default {
*/
saveGeneral() {
localStorage.timezone = this.$root.userTimezone;
this.$root.use12HourTimeFormat = this.settings.use12HourTimeFormat;
this.saveSettings();
},
/**

View file

@ -918,6 +918,9 @@
"successEnabled": "Enabled Successfully.",
"tagNotFound": "Tag not found.",
"foundChromiumVersion": "Found Chromium/Chrome. Version: {0}",
"Time Format": "Time Format",
"12-hour": "12 Hour",
"24-hour": "24 Hour",
"Remote Browsers": "Remote Browsers",
"Remote Browser": "Remote Browser",
"Add a Remote Browser": "Add a Remote Browser",

View file

@ -35,10 +35,16 @@ export default {
/**
* Return a given value in the format YYYY-MM-DD HH:mm:ss
* @param {any} value Value to format as date time
* @param {boolean} use12HourTimeFormat Whether to use 12-hour format
* @returns {string} Formatted string
*/
datetime(value) {
return this.datetimeFormat(value, "YYYY-MM-DD HH:mm:ss");
datetime(value, use12HourTimeFormat = false) {
const hourTimeFormat = use12HourTimeFormat ? "hh" : "HH";
const timeFormat =
`YYYY-MM-DD ${hourTimeFormat}:mm:ss${
use12HourTimeFormat ? " A" : ""
}`;
return this.datetimeFormat(value, timeFormat);
},
/**

View file

@ -59,7 +59,7 @@
<tr v-for="(beat, index) in displayedRecords" :key="index" :class="{ 'shadow-box': $root.windowWidth <= 550}">
<td class="name-column"><router-link :to="`/dashboard/${beat.monitorID}`">{{ $root.monitorList[beat.monitorID]?.name }}</router-link></td>
<td><Status :status="beat.status" /></td>
<td :class="{ 'border-0':! beat.msg}"><Datetime :value="beat.time" /></td>
<td :class="{ 'border-0':! beat.msg}"><Datetime :value="beat.time" :use12HourTimeFormat="use12HourTimeFormat" /></td>
<td class="border-0">{{ beat.msg }}</td>
</tr>
@ -113,6 +113,7 @@ export default {
},
importantHeartBeatListLength: 0,
displayedRecords: [],
use12HourTimeFormat: false
};
},
watch: {
@ -127,6 +128,10 @@ export default {
},
},
created() {
this.loadSettings();
},
mounted() {
this.getImportantHeartbeatListLength();
@ -203,6 +208,16 @@ export default {
}
},
/**
* Retrieves important settings values.
* @returns {void}
*/
loadSettings() {
this.$root.getSocket().emit("getSettings", res => {
this.use12HourTimeFormat = res.data.use12HourTimeFormat;
});
}
},
};
</script>

View file

@ -184,7 +184,7 @@
<div v-if="showPingChartBox" class="shadow-box big-padding text-center ping-chart-wrapper">
<div class="row">
<div class="col">
<PingChart :monitor-id="monitor.id" />
<PingChart :monitor-id="monitor.id" :use12HourTimeFormat="use12HourTimeFormat" />
</div>
</div>
</div>
@ -228,7 +228,7 @@
<tbody>
<tr v-for="(beat, index) in displayedRecords" :key="index" style="padding: 10px;">
<td><Status :status="beat.status" /></td>
<td :class="{ 'border-0':! beat.msg}"><Datetime :value="beat.time" /></td>
<td :class="{ 'border-0':! beat.msg}"><Datetime :value="beat.time" :use12HourTimeFormat="use12HourTimeFormat" /></td>
<td class="border-0">{{ beat.msg }}</td>
</tr>
@ -328,6 +328,7 @@ export default {
currentExample: "javascript-fetch",
code: "",
},
use12HourTimeFormat: false,
};
},
computed: {
@ -420,6 +421,10 @@ export default {
},
},
created() {
this.loadSettings();
},
mounted() {
this.getImportantHeartbeatListLength();
@ -656,7 +661,14 @@ export default {
.replace("https://example.com/api/push/key?status=up&msg=OK&ping=", this.pushURL);
this.pushMonitor.code = code;
});
},
loadSettings() {
this.$root.getSocket().emit("getSettings", res => {
this.use12HourTimeFormat = res.data.use12HourTimeFormat || false;
});
}
},
};
</script>

View file

@ -163,6 +163,10 @@ export default {
this.settings.searchEngineIndex = false;
}
if (this.settings.use12HourTimeFormat === undefined) {
this.settings.use12HourTimeFormat = false;
}
if (this.settings.entryPage === undefined) {
this.settings.entryPage = "dashboard";
}