Merge pull request #1108 from trogper/push-status-param

Add status parameter to push monitor
This commit is contained in:
Louis Lam 2022-04-29 00:12:44 +08:00 committed by GitHub
commit 6333231f1b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 4 deletions

View file

@ -4,7 +4,7 @@ const { R } = require("redbean-node");
const apicache = require("../modules/apicache"); const apicache = require("../modules/apicache");
const Monitor = require("../model/monitor"); const Monitor = require("../model/monitor");
const dayjs = require("dayjs"); const dayjs = require("dayjs");
const { UP, flipStatus, log } = require("../../src/util"); const { UP, DOWN, flipStatus, log } = require("../../src/util");
const StatusPage = require("../model/status_page"); const StatusPage = require("../model/status_page");
const { UptimeKumaServer } = require("../uptime-kuma-server"); const { UptimeKumaServer } = require("../uptime-kuma-server");
let router = express.Router(); let router = express.Router();
@ -34,6 +34,8 @@ router.get("/api/push/:pushToken", async (request, response) => {
let pushToken = request.params.pushToken; let pushToken = request.params.pushToken;
let msg = request.query.msg || "OK"; let msg = request.query.msg || "OK";
let ping = request.query.ping || null; let ping = request.query.ping || null;
let statusString = request.query.status || "up";
let status = (statusString === "up") ? UP : DOWN;
let monitor = await R.findOne("monitor", " push_token = ? AND active = 1 ", [ let monitor = await R.findOne("monitor", " push_token = ? AND active = 1 ", [
pushToken pushToken
@ -45,7 +47,6 @@ router.get("/api/push/:pushToken", async (request, response) => {
const previousHeartbeat = await Monitor.getPreviousHeartbeat(monitor.id); const previousHeartbeat = await Monitor.getPreviousHeartbeat(monitor.id);
let status = UP;
if (monitor.isUpsideDown()) { if (monitor.isUpsideDown()) {
status = flipStatus(status); status = flipStatus(status);
} }

View file

@ -56,7 +56,7 @@
<CopyableInput id="push-url" v-model="pushURL" type="url" disabled="disabled" /> <CopyableInput id="push-url" v-model="pushURL" type="url" disabled="disabled" />
<div class="form-text"> <div class="form-text">
{{ $t("needPushEvery", [monitor.interval]) }}<br /> {{ $t("needPushEvery", [monitor.interval]) }}<br />
{{ $t("pushOptionalParams", ["msg, ping"]) }} {{ $t("pushOptionalParams", ["status, msg, ping"]) }}
</div> </div>
</div> </div>
@ -421,7 +421,7 @@ export default {
}, },
pushURL() { pushURL() {
return this.$root.baseURL + "/api/push/" + this.monitor.pushToken + "?msg=OK&ping="; return this.$root.baseURL + "/api/push/" + this.monitor.pushToken + "?status=true&msg=OK&ping=";
}, },
bodyPlaceholder() { bodyPlaceholder() {