fix webhook only working when reported user is changed
All checks were successful
delpoy / build-and-deploy (push) Successful in 51s
All checks were successful
delpoy / build-and-deploy (push) Successful in 51s
This commit is contained in:
parent
8910a98489
commit
29d9765a81
@ -1,4 +1,4 @@
|
||||
async function webhookUserReported(endpoint: string, uuid: string) {
|
||||
export async function webhookUserReported(endpoint: string, uuid: string) {
|
||||
await fetch(endpoint, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
|
@ -6,6 +6,7 @@ import type { Attributes } from 'sequelize';
|
||||
import { Op } from 'sequelize';
|
||||
import { env } from '$env/dynamic/private';
|
||||
import crypto from 'crypto';
|
||||
import { webhookUserReported } from '$lib/server/webhook';
|
||||
|
||||
export const POST = (async ({ request, cookies }) => {
|
||||
if (getSession(cookies, { permissions: [Permissions.ReportRead] }) == null) {
|
||||
@ -114,9 +115,17 @@ export const PATCH = (async ({ request, cookies }) => {
|
||||
if (report === null || (admin === null && data.auditor != -1) || reported === null)
|
||||
return new Response(null, { status: 400 });
|
||||
|
||||
let reportedChanged: string | undefined;
|
||||
const webhookTriggerUsers: string[] = [];
|
||||
if (report.reported_id != reported?.id) {
|
||||
reportedChanged = reported ? reported.uuid : (await User.findByPk(report.reported_id))?.uuid;
|
||||
const oldReportUser = await User.findByPk(report.reported_id);
|
||||
if (oldReportUser) webhookTriggerUsers.push(oldReportUser.uuid);
|
||||
if (reported) webhookTriggerUsers.push(reported.uuid);
|
||||
} else if (
|
||||
reported &&
|
||||
report.reported_id != null &&
|
||||
report.strike_reason_id != data.strike_reason
|
||||
) {
|
||||
webhookTriggerUsers.push(reported.uuid);
|
||||
}
|
||||
|
||||
report.reported_id = reported?.id ?? null;
|
||||
@ -147,9 +156,11 @@ export const PATCH = (async ({ request, cookies }) => {
|
||||
|
||||
await report.save();
|
||||
|
||||
if (reportedChanged != null && data.status == 'reviewed' && env.REPORTED_WEBHOOK) {
|
||||
// no `await` to avoid blocking
|
||||
webhookUserReported(env.REPORTED_WEBHOOK, reportedChanged);
|
||||
if (webhookTriggerUsers.length > 0 && data.status == 'reviewed' && env.REPORTED_WEBHOOK) {
|
||||
for (const webhookTriggerUser in webhookTriggerUsers) {
|
||||
// no `await` to avoid blocking
|
||||
webhookUserReported(env.REPORTED_WEBHOOK, webhookTriggerUser);
|
||||
}
|
||||
}
|
||||
|
||||
return new Response();
|
||||
|
Loading…
x
Reference in New Issue
Block a user