Better test messages
This commit is contained in:
parent
488aeb119b
commit
3f978bc45f
7 changed files with 60 additions and 12 deletions
|
@ -26,14 +26,24 @@ class Api {
|
|||
return messages;
|
||||
}
|
||||
|
||||
async publish(baseUrl, topic, message) {
|
||||
async publish(baseUrl, topic, message, title, priority, tags) {
|
||||
const user = await userManager.get(baseUrl);
|
||||
const url = topicUrl(baseUrl, topic);
|
||||
console.log(`[Api] Publishing message to ${url}`);
|
||||
const headers = {};
|
||||
if (title) {
|
||||
headers["X-Title"] = title;
|
||||
}
|
||||
if (priority !== 3) {
|
||||
headers["X-Priority"] = `${priority}`;
|
||||
}
|
||||
if (tags.length > 0) {
|
||||
headers["X-Tags"] = tags.join(",");
|
||||
}
|
||||
await fetch(url, {
|
||||
method: 'PUT',
|
||||
body: message,
|
||||
headers: maybeWithBasicAuth({}, user)
|
||||
headers: maybeWithBasicAuth(headers, user)
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -104,6 +104,17 @@ export const encodeBase64Url = (s) => {
|
|||
return Base64.encodeURI(s);
|
||||
}
|
||||
|
||||
export const shuffle = (arr) => {
|
||||
let j, x;
|
||||
for (let index = arr.length - 1; index > 0; index--) {
|
||||
j = Math.floor(Math.random() * (index + 1));
|
||||
x = arr[index];
|
||||
arr[index] = arr[j];
|
||||
arr[j] = x;
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
// https://jameshfisher.com/2017/10/30/web-cryptography-api-hello-world/
|
||||
export const sha256 = async (s) => {
|
||||
const buf = await crypto.subtle.digest("SHA-256", new TextEncoder("utf-8").encode(s));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue