app
components
data
functions
api
admin-apps
appeals
auth
data-transfers
events-team
game-appeals
game-bans
gme
inactivity
infractions
me
mod-queue
notifications
send.ts
reports
uploads
webview-captcha.ts
_middleware.ts
common.ts
email.ts
gcloud.ts
permissions.ts
roblox-open-cloud.ts
public
.gitignore
.node-version
.prettierignore
OFL.txt
emotion-server.js
index.css
index.d.ts
package-lock.json
package.json
remix.config.js
server.ts
theme.ts
tsconfig.json
36 lines
876 B
TypeScript
36 lines
876 B
TypeScript
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,
|
|
});
|
|
}
|