Skip to content
Permalink
75402b3315
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
35 lines (27 sloc) 876 Bytes
import { jsonError } from "../../common.js";
import { sendPushNotification } from "../../gcloud.js";
export async function onRequestPost(context: RequestContext) {
const { current_user: currentUser } = context.data;
if (!currentUser) return jsonError("Unauthorized", 401);
if (!(currentUser.permissions & (1 << 0))) return jsonError("Forbidden", 403);
const { body, title } = context.data.body;
if (typeof body !== "string" || typeof title !== "string")
return jsonError("Body and title must be strings", 400);
if (
new Blob([
JSON.stringify({
message: {
notification: {
body,
title,
},
},
}),
]).size > 4000
)
return jsonError("Payload too large", 400);
await sendPushNotification(context.env, title, body);
return new Response(null, {
status: 204,
});
}