Fix auth base64, fix iPhone things

This commit is contained in:
Philipp Heckel 2022-03-10 18:11:12 -05:00
parent ccb9da9333
commit 160c72997f
7 changed files with 48 additions and 11 deletions

View file

@ -5,6 +5,9 @@ import logo from "../img/ntfy.png";
class Notifier {
async notify(subscriptionId, notification, onClickFallback) {
if (!this.supported()) {
return;
}
const subscription = await subscriptionManager.get(subscriptionId);
const shouldNotify = await this.shouldNotify(subscription, notification);
if (!shouldNotify) {
@ -38,10 +41,14 @@ class Notifier {
}
granted() {
return Notification.permission === 'granted';
return this.supported() && Notification.permission === 'granted';
}
maybeRequestPermission(cb) {
if (!this.supported()) {
cb(false);
return;
}
if (!this.granted()) {
Notification.requestPermission().then((permission) => {
const granted = permission === 'granted';
@ -61,6 +68,10 @@ class Notifier {
}
return true;
}
supported() {
return 'Notification' in window;
}
}
const notifier = new Notifier();

View file

@ -7,6 +7,7 @@ import dadum from "../sounds/dadum.mp3";
import pop from "../sounds/pop.mp3";
import popSwoosh from "../sounds/pop-swoosh.mp3";
import config from "./config";
import {Base64} from 'js-base64';
export const topicUrl = (baseUrl, topic) => `${baseUrl}/${topic}`;
export const topicUrlWs = (baseUrl, topic) => `${topicUrl(baseUrl, topic)}/ws`
@ -96,14 +97,11 @@ export const basicAuth = (username, password) => {
}
export const encodeBase64 = (s) => {
return new Buffer(s).toString('base64');
return Base64.encode(s);
}
export const encodeBase64Url = (s) => {
return encodeBase64(s)
.replaceAll('+', '-')
.replaceAll('/', '_')
.replaceAll('=', '');
return Base64.encodeURI(s);
}
// https://jameshfisher.com/2017/10/30/web-cryptography-api-hello-world/