mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-06-19 02:36:47 +02:00
update uptime component with dynamic range
This commit is contained in:
parent
24b6209651
commit
6c26d32a8e
3 changed files with 41 additions and 8 deletions
|
@ -126,7 +126,11 @@ router.get("/api/status-page/heartbeat/:slug", cache("1 minutes"), async (reques
|
|||
ping: null
|
||||
}));
|
||||
|
||||
// Calculate uptime for the configured range
|
||||
// Calculate uptime for the exact configured range
|
||||
try {
|
||||
uptime = uptimeCalculator.getDataByDuration(`${heartbeatBarDays}d`).uptime;
|
||||
} catch (e) {
|
||||
// Fall back to available ranges if duration exceeds limits
|
||||
if (heartbeatBarDays <= 1) {
|
||||
uptime = uptimeCalculator.get24Hour().uptime;
|
||||
} else if (heartbeatBarDays <= 30) {
|
||||
|
@ -135,6 +139,7 @@ router.get("/api/status-page/heartbeat/:slug", cache("1 minutes"), async (reques
|
|||
uptime = uptimeCalculator.get1Year().uptime;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
monitorID,
|
||||
|
@ -149,7 +154,14 @@ router.get("/api/status-page/heartbeat/:slug", cache("1 minutes"), async (reques
|
|||
// Populate the response objects
|
||||
for (const result of monitorResults) {
|
||||
heartbeatList[result.monitorID] = result.heartbeats;
|
||||
|
||||
// Always populate 24h uptime for compatibility
|
||||
uptimeList[`${result.monitorID}_24`] = result.uptime;
|
||||
|
||||
// Add dynamic uptime key for the exact range
|
||||
if (heartbeatBarDays > 0) {
|
||||
uptimeList[`${result.monitorID}_${heartbeatBarDays}d`] = result.uptime;
|
||||
}
|
||||
}
|
||||
|
||||
response.json({
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
<font-awesome-icon v-if="editMode" icon="arrows-alt-v" class="action drag me-3" />
|
||||
<font-awesome-icon v-if="editMode" icon="times" class="action remove me-3" @click="removeMonitor(group.index, monitor.index)" />
|
||||
|
||||
<Uptime :monitor="monitor.element" type="24" :pill="true" />
|
||||
<Uptime :monitor="monitor.element" :type="uptimeType" :pill="true" />
|
||||
<a
|
||||
v-if="showLink(monitor)"
|
||||
:href="monitor.element.url"
|
||||
|
@ -129,6 +129,19 @@ export default {
|
|||
computed: {
|
||||
showGroupDrag() {
|
||||
return (this.$root.publicGroupList.length >= 2);
|
||||
},
|
||||
/**
|
||||
* Get the uptime type based on heartbeatBarDays
|
||||
* Returns the exact type for dynamic uptime calculation
|
||||
* @returns {string} The uptime type
|
||||
*/
|
||||
uptimeType() {
|
||||
const days = Number(this.heartbeatBarDays);
|
||||
if (days === 0 || days === 1) {
|
||||
return "24"; // 24 hours (for compatibility)
|
||||
} else {
|
||||
return `${days}d`; // Dynamic days format (e.g., "7d", "14d", "30d")
|
||||
}
|
||||
}
|
||||
},
|
||||
created() {
|
||||
|
|
|
@ -90,6 +90,14 @@ export default {
|
|||
if (this.type === "720") {
|
||||
return `30${this.$t("-day")}`;
|
||||
}
|
||||
if (this.type === "24") {
|
||||
return `24${this.$t("-hour")}`;
|
||||
}
|
||||
// Handle dynamic day formats (e.g., "7d", "14d", "30d")
|
||||
const dayMatch = this.type.match(/^(\d+)d$/);
|
||||
if (dayMatch) {
|
||||
return `${dayMatch[1]}${this.$t("-day")}`;
|
||||
}
|
||||
return `24${this.$t("-hour")}`;
|
||||
}
|
||||
},
|
||||
|
|
Loading…
Add table
Reference in a new issue