diff options
author | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-08-13 12:59:59 +0200 |
---|---|---|
committer | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-08-13 12:59:59 +0200 |
commit | 90d5307a5668030b414d35deeb2bb9b6845b76e0 (patch) | |
tree | 6dcb69012336c1222ac75ad539e0a576ada05a7c /api/src/util | |
parent | :sparkles: server bundle (diff) | |
download | server-90d5307a5668030b414d35deeb2bb9b6845b76e0.tar.xz |
rename @fosscord/server-util to -> @fosscord/util
Diffstat (limited to 'api/src/util')
-rw-r--r-- | api/src/util/Channel.ts | 8 | ||||
-rw-r--r-- | api/src/util/Config.ts | 4 | ||||
-rw-r--r-- | api/src/util/Event.ts | 26 | ||||
-rw-r--r-- | api/src/util/Member.ts | 7 | ||||
-rw-r--r-- | api/src/util/Message.ts | 16 | ||||
-rw-r--r-- | api/src/util/User.ts | 2 | ||||
-rw-r--r-- | api/src/util/cdn.ts | 2 | ||||
-rw-r--r-- | api/src/util/ipAddress.ts | 2 | ||||
-rw-r--r-- | api/src/util/passwordStrength.ts | 2 |
9 files changed, 22 insertions, 47 deletions
diff --git a/api/src/util/Channel.ts b/api/src/util/Channel.ts index 4d322812..ef04d521 100644 --- a/api/src/util/Channel.ts +++ b/api/src/util/Channel.ts @@ -2,18 +2,18 @@ import { ChannelCreateEvent, ChannelModel, ChannelType, + emitEvent, getPermission, GuildModel, Snowflake, TextChannel, + toObject, VoiceChannel -} from "@fosscord/server-util"; +} from "@fosscord/util"; import { HTTPError } from "lambert-server"; -import { emitEvent } from "./Event"; // TODO: DM channel export async function createChannel(channel: Partial<TextChannel | VoiceChannel>, user_id: string = "0") { - // Always check if user has permission first const permissions = await getPermission(user_id, channel.guild_id); permissions.hasThrow("MANAGE_CHANNELS"); @@ -50,7 +50,7 @@ export async function createChannel(channel: Partial<TextChannel | VoiceChannel> recipient_ids: null }).save(); - await emitEvent({ event: "CHANNEL_CREATE", data: channel, guild_id: channel.guild_id } as ChannelCreateEvent); + await emitEvent({ event: "CHANNEL_CREATE", data: toObject(channel), guild_id: channel.guild_id } as ChannelCreateEvent); return channel; } diff --git a/api/src/util/Config.ts b/api/src/util/Config.ts index e2e0d312..c86afbe7 100644 --- a/api/src/util/Config.ts +++ b/api/src/util/Config.ts @@ -1,7 +1,7 @@ // @ts-nocheck import Ajv, { JSONSchemaType } from "ajv"; -import { getConfigPathForFile } from "@fosscord/server-util/dist/util/Config"; -import { Config } from "@fosscord/server-util"; +import { getConfigPathForFile } from "@fosscord/util/dist/util/Config"; +import { Config } from "@fosscord/util"; export interface RateLimitOptions { count: number; diff --git a/api/src/util/Event.ts b/api/src/util/Event.ts deleted file mode 100644 index 4dd56417..00000000 --- a/api/src/util/Event.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { Config, Event, EventModel, RabbitMQ } from "@fosscord/server-util"; - -export async function emitEvent(payload: Omit<Event, "created_at">) { - if (RabbitMQ.connection) { - const id = (payload.channel_id || payload.user_id || payload.guild_id) as string; - if (!id) console.error("event doesn't contain any id", payload); - const data = typeof payload.data === "object" ? JSON.stringify(payload.data) : payload.data; // use rabbitmq for event transmission - await RabbitMQ.channel?.assertExchange(id, "fanout", { durable: false }); - - // assertQueue isn't needed, because a queue will automatically created if it doesn't exist - const successful = RabbitMQ.channel?.publish(id, "", Buffer.from(`${data}`), { type: payload.event }); - if (!successful) throw new Error("failed to send event"); - } else { - // use mongodb for event transmission - // TODO: use event emitter for local server bundle - const obj = { - created_at: new Date(), // in seconds - ...payload - }; - // TODO: bigint isn't working - - return await new EventModel(obj).save(); - } -} - -export async function emitAuditLog(payload: any) {} diff --git a/api/src/util/Member.ts b/api/src/util/Member.ts index 7b06720b..ee3f64ad 100644 --- a/api/src/util/Member.ts +++ b/api/src/util/Member.ts @@ -11,11 +11,12 @@ import { toObject, UserModel, GuildDocument, - Config -} from "@fosscord/server-util"; + Config, + emitEvent +} from "@fosscord/util"; import { HTTPError } from "lambert-server"; -import { emitEvent } from "./Event"; + import { getPublicUser } from "./User"; export const PublicMemberProjection = { diff --git a/api/src/util/Message.ts b/api/src/util/Message.ts index e811f522..a55c3365 100644 --- a/api/src/util/Message.ts +++ b/api/src/util/Message.ts @@ -1,14 +1,14 @@ -import { ChannelModel, Embed, Message, MessageCreateEvent, MessageUpdateEvent } from "@fosscord/server-util"; -import { Snowflake } from "@fosscord/server-util"; -import { MessageModel } from "@fosscord/server-util"; -import { PublicMemberProjection } from "@fosscord/server-util"; -import { toObject } from "@fosscord/server-util"; -import { getPermission } from "@fosscord/server-util"; +import { ChannelModel, Embed, emitEvent, Message, MessageCreateEvent, MessageUpdateEvent } from "@fosscord/util"; +import { Snowflake } from "@fosscord/util"; +import { MessageModel } from "@fosscord/util"; +import { PublicMemberProjection } from "@fosscord/util"; +import { toObject } from "@fosscord/util"; +import { getPermission } from "@fosscord/util"; import { HTTPError } from "lambert-server"; import fetch from "node-fetch"; import cheerio from "cheerio"; -import { emitEvent } from "./Event"; -import { MessageType } from "@fosscord/server-util/dist/util/Constants"; + +import { MessageType } from "@fosscord/util/dist/util/Constants"; // TODO: check webhook, application, system author const LINK_REGEX = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/g; diff --git a/api/src/util/User.ts b/api/src/util/User.ts index 107fc759..392c7101 100644 --- a/api/src/util/User.ts +++ b/api/src/util/User.ts @@ -1,4 +1,4 @@ -import { toObject, UserModel, PublicUserProjection } from "@fosscord/server-util"; +import { toObject, UserModel, PublicUserProjection } from "@fosscord/util"; import { HTTPError } from "lambert-server"; export { PublicUserProjection }; diff --git a/api/src/util/cdn.ts b/api/src/util/cdn.ts index aed8ca0a..3c71d980 100644 --- a/api/src/util/cdn.ts +++ b/api/src/util/cdn.ts @@ -1,4 +1,4 @@ -import { Config } from "@fosscord/server-util"; +import { Config } from "@fosscord/util"; import FormData from "form-data"; import { HTTPError } from "lambert-server"; import fetch from "node-fetch"; diff --git a/api/src/util/ipAddress.ts b/api/src/util/ipAddress.ts index f2c8fd4d..0a724daa 100644 --- a/api/src/util/ipAddress.ts +++ b/api/src/util/ipAddress.ts @@ -1,4 +1,4 @@ -import { Config } from "@fosscord/server-util"; +import { Config } from "@fosscord/util"; import { Request } from "express"; // use ipdata package instead of simple fetch because of integrated caching import fetch from "node-fetch"; diff --git a/api/src/util/passwordStrength.ts b/api/src/util/passwordStrength.ts index cc503843..dfffa2c0 100644 --- a/api/src/util/passwordStrength.ts +++ b/api/src/util/passwordStrength.ts @@ -1,4 +1,4 @@ -import { Config } from "@fosscord/server-util"; +import { Config } from "@fosscord/util"; import "missing-native-js-functions"; const reNUMBER = /[0-9]/g; |