mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-06-17 09:59:10 +00:00
miniflare init
This commit is contained in:
parent
8c07ed3123
commit
688954a2e0
52 changed files with 898 additions and 25 deletions
51
packages/api/old-src/handlers/update-guild.ts
Normal file
51
packages/api/old-src/handlers/update-guild.ts
Normal file
|
@ -0,0 +1,51 @@
|
|||
import { sendAuditLog, validateAuditLogWebhook } from '@roleypoly/api/utils/audit-log';
|
||||
import { GuildDataUpdate, WebhookValidationStatus } from '@roleypoly/types';
|
||||
import { asEditor, getGuildData } from '../utils/guild';
|
||||
import { GuildData } from '../utils/kv';
|
||||
import { invalid, ok } from '../utils/responses';
|
||||
|
||||
export const UpdateGuild = asEditor(
|
||||
{},
|
||||
(session, { guildID, guild }) =>
|
||||
async (request: Request): Promise<Response> => {
|
||||
const guildUpdate = (await request.json()) as GuildDataUpdate;
|
||||
|
||||
const oldGuildData = await getGuildData(guildID);
|
||||
const newGuildData = {
|
||||
...oldGuildData,
|
||||
...guildUpdate,
|
||||
};
|
||||
|
||||
if (oldGuildData.auditLogWebhook !== newGuildData.auditLogWebhook) {
|
||||
try {
|
||||
const validationStatus = await validateAuditLogWebhook(
|
||||
guild,
|
||||
newGuildData.auditLogWebhook
|
||||
);
|
||||
|
||||
if (validationStatus !== WebhookValidationStatus.Ok) {
|
||||
if (validationStatus === WebhookValidationStatus.NoneSet) {
|
||||
newGuildData.auditLogWebhook = null;
|
||||
} else {
|
||||
return invalid({
|
||||
what: 'webhookValidationStatus',
|
||||
webhookValidationStatus: validationStatus,
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
invalid();
|
||||
}
|
||||
}
|
||||
|
||||
await GuildData.put(guildID, newGuildData);
|
||||
|
||||
try {
|
||||
await sendAuditLog(oldGuildData, guildUpdate, session.user);
|
||||
} catch (e) {
|
||||
// Catching errors here because this isn't a critical task, and could simply fail due to operator error.
|
||||
}
|
||||
|
||||
return ok();
|
||||
}
|
||||
);
|
Loading…
Add table
Add a link
Reference in a new issue