pinafore/routes/_utils/base64.js
Sorin Davidoi e45af16bf9 Push notifications (#579)
* feat: Push notifications

* feat: Feature-detect push notifications support

* feat: Prompt user to reauthenticate when missing push scope

* fix(service-worker): Add tags to notifications

* feat: Push notification actions for mentions
2018-10-06 13:06:10 -07:00

21 lines
539 B
JavaScript

const decodeBase64 = base64 => {
const rawData = window.atob(base64)
const outputArray = new Uint8Array(rawData.length)
for (let i = 0; i < rawData.length; ++i) {
outputArray[i] = rawData.charCodeAt(i)
}
return outputArray
}
// Taken from https://www.npmjs.com/package/web-push
export const urlBase64ToUint8Array = (base64String) => {
const padding = '='.repeat((4 - base64String.length % 4) % 4)
const base64 = (base64String + padding)
.replace(/-/g, '+')
.replace(/_/g, '/')
return decodeBase64(base64)
}