parent
8910a98489
commit
29d9765a81
src
@ -1,4 +1,4 @@
|
|||||||
async function webhookUserReported(endpoint: string, uuid: string) {
|
export async function webhookUserReported(endpoint: string, uuid: string) {
|
||||||
await fetch(endpoint, {
|
await fetch(endpoint, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -6,6 +6,7 @@ import type { Attributes } from 'sequelize';
|
|||||||
import { Op } from 'sequelize';
|
import { Op } from 'sequelize';
|
||||||
import { env } from '$env/dynamic/private';
|
import { env } from '$env/dynamic/private';
|
||||||
import crypto from 'crypto';
|
import crypto from 'crypto';
|
||||||
|
import { webhookUserReported } from '$lib/server/webhook';
|
||||||
|
|
||||||
export const POST = (async ({ request, cookies }) => {
|
export const POST = (async ({ request, cookies }) => {
|
||||||
if (getSession(cookies, { permissions: [Permissions.ReportRead] }) == null) {
|
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)
|
if (report === null || (admin === null && data.auditor != -1) || reported === null)
|
||||||
return new Response(null, { status: 400 });
|
return new Response(null, { status: 400 });
|
||||||
|
|
||||||
let reportedChanged: string | undefined;
|
const webhookTriggerUsers: string[] = [];
|
||||||
if (report.reported_id != reported?.id) {
|
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;
|
report.reported_id = reported?.id ?? null;
|
||||||
@ -147,9 +156,11 @@ export const PATCH = (async ({ request, cookies }) => {
|
|||||||
|
|
||||||
await report.save();
|
await report.save();
|
||||||
|
|
||||||
if (reportedChanged != null && data.status == 'reviewed' && env.REPORTED_WEBHOOK) {
|
if (webhookTriggerUsers.length > 0 && data.status == 'reviewed' && env.REPORTED_WEBHOOK) {
|
||||||
// no `await` to avoid blocking
|
for (const webhookTriggerUser in webhookTriggerUsers) {
|
||||||
webhookUserReported(env.REPORTED_WEBHOOK, reportedChanged);
|
// no `await` to avoid blocking
|
||||||
|
webhookUserReported(env.REPORTED_WEBHOOK, webhookTriggerUser);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Response();
|
return new Response();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user