mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-11-27 16:54:04 +00:00
[matrix] use encodeURIComponent to handle the url encode
This commit is contained in:
parent
2ce5c28ed4
commit
3a0143ac46
1 changed files with 15 additions and 10 deletions
|
@ -1,6 +1,7 @@
|
||||||
const NotificationProvider = require("./notification-provider");
|
const NotificationProvider = require("./notification-provider");
|
||||||
const axios = require("axios");
|
const axios = require("axios");
|
||||||
const Crypto = require('crypto')
|
const Crypto = require("crypto");
|
||||||
|
const { debug } = require("../../src/util");
|
||||||
|
|
||||||
class Matrix extends NotificationProvider {
|
class Matrix extends NotificationProvider {
|
||||||
name = "matrix";
|
name = "matrix";
|
||||||
|
@ -9,14 +10,18 @@ class Matrix extends NotificationProvider {
|
||||||
let okMsg = "Sent Successfully.";
|
let okMsg = "Sent Successfully.";
|
||||||
|
|
||||||
const size = 20;
|
const size = 20;
|
||||||
const randomString = Crypto
|
const randomString = encodeURIComponent(
|
||||||
.randomBytes(size)
|
Crypto
|
||||||
.toString('base64')
|
.randomBytes(size)
|
||||||
.slice(0, size);
|
.toString("base64")
|
||||||
const roomId = notification
|
.slice(0, size)
|
||||||
.internalRoomId
|
);
|
||||||
.replaceAll(":", "%3A")
|
|
||||||
.replaceAll("!", "%21");
|
debug("Random String: " + randomString);
|
||||||
|
|
||||||
|
const roomId = encodeURIComponent(notification.internalRoomId);
|
||||||
|
|
||||||
|
debug("Matrix Room ID: " + roomId);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let config = {
|
let config = {
|
||||||
|
@ -29,7 +34,7 @@ class Matrix extends NotificationProvider {
|
||||||
"body": msg
|
"body": msg
|
||||||
};
|
};
|
||||||
|
|
||||||
await axios.put(`${notification.homeserverUrl}/_matrix/client/r0/rooms/${roomId}/send/m.room.message/${randomString}`, data, config)
|
await axios.put(`${notification.homeserverUrl}/_matrix/client/r0/rooms/${roomId}/send/m.room.message/${randomString}`, data, config);
|
||||||
return okMsg;
|
return okMsg;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.throwGeneralAxiosError(error);
|
this.throwGeneralAxiosError(error);
|
||||||
|
|
Loading…
Reference in a new issue