use return codes to allow for automation
This commit is contained in:
parent
ddf0626a9a
commit
6a1e2edd8d
@ -2,13 +2,16 @@ import {
|
|||||||
Attachment,
|
Attachment,
|
||||||
Channel,
|
Channel,
|
||||||
Embed,
|
Embed,
|
||||||
|
DiscordApiErrors,
|
||||||
emitEvent,
|
emitEvent,
|
||||||
|
FosscordApiErrors,
|
||||||
getPermission,
|
getPermission,
|
||||||
getRights,
|
getRights,
|
||||||
Message,
|
Message,
|
||||||
MessageCreateEvent,
|
MessageCreateEvent,
|
||||||
MessageDeleteEvent,
|
MessageDeleteEvent,
|
||||||
MessageUpdateEvent,
|
MessageUpdateEvent,
|
||||||
|
Snowflake,
|
||||||
uploadFile
|
uploadFile
|
||||||
} from "@fosscord/util";
|
} from "@fosscord/util";
|
||||||
import { Router, Response, Request } from "express";
|
import { Router, Response, Request } from "express";
|
||||||
@ -16,7 +19,6 @@ import multer from "multer";
|
|||||||
import { route } from "@fosscord/api";
|
import { route } from "@fosscord/api";
|
||||||
import { handleMessage, postHandleMessage } from "@fosscord/api";
|
import { handleMessage, postHandleMessage } from "@fosscord/api";
|
||||||
import { MessageCreateSchema } from "../index";
|
import { MessageCreateSchema } from "../index";
|
||||||
import { Snowflake } from "@fosscord/util";
|
|
||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
@ -104,12 +106,12 @@ router.put(
|
|||||||
const snowflake = Snowflake.deconstruct(message_id)
|
const snowflake = Snowflake.deconstruct(message_id)
|
||||||
if (Date.now() < snowflake.timestamp) {
|
if (Date.now() < snowflake.timestamp) {
|
||||||
// message is in the future
|
// message is in the future
|
||||||
throw new HTTPError("You cannot backfill messages in the future", 400);
|
throw FosscordApiErrors.CANNOT_BACKFILL_TO_THE_FUTURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
const exists = await Message.findOne({ where: { id: message_id, channel_id: channel_id }});
|
const exists = await Message.findOne({ where: { id: message_id, channel_id: channel_id }});
|
||||||
if (exists) {
|
if (exists) {
|
||||||
throw new HTTPError("Cannot backfill to message ID that already exists", 409);
|
throw FosscordApiErrors.CANNOT_REPLACE_BY_BACKFILL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req.file) {
|
if (req.file) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user