From c9ff1774b435b5af72faa97386890b3cb659744c Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Sun, 29 Aug 2021 00:03:40 +0200 Subject: :sparkles: typeorm api rewrite done --- api/src/schema/Guild.ts | 80 +++++++++++++------------------------------------ 1 file changed, 21 insertions(+), 59 deletions(-) (limited to 'api/src/schema/Guild.ts') diff --git a/api/src/schema/Guild.ts b/api/src/schema/Guild.ts index e5971baf..01690ae9 100644 --- a/api/src/schema/Guild.ts +++ b/api/src/schema/Guild.ts @@ -1,4 +1,4 @@ -import { ChannelSchema, GuildChannel } from "@fosscord/util"; +import { Channel } from "@fosscord/util"; import { Length } from "../util/instanceOf"; import { ChannelModifySchema } from "./Channel"; @@ -59,54 +59,6 @@ export interface GuildUpdateSchema extends Omit { preferred_locale?: string; } -export const GuildGetSchema = { - id: true, - name: true, - icon: true, - splash: true, - discovery_splash: true, - owner: true, - owner_id: true, - permissions: true, - region: true, - afk_channel_id: true, - afk_timeout: true, - widget_enabled: true, - widget_channel_id: true, - verification_level: true, - default_message_notifications: true, - explicit_content_filter: true, - roles: true, - emojis: true, - features: true, - mfa_level: true, - application_id: true, - system_channel_id: true, - system_channel_flags: true, - rules_channel_id: true, - joined_at: true, - // large: true, - // unavailable: true, - member_count: true, - // voice_states: true, - // members: true, - // channels: true, - // presences: true, - max_presences: true, - max_members: true, - vanity_url_code: true, - description: true, - banner: true, - premium_tier: true, - premium_subscription_count: true, - preferred_locale: true, - public_updates_channel_id: true, - max_video_channel_users: true, - approximate_member_count: true, - approximate_presence_count: true - // welcome_screen: true, -}; - export const GuildTemplateCreateSchema = { name: String, $avatar: String @@ -117,16 +69,26 @@ export interface GuildTemplateCreateSchema { avatar?: string; } -export const GuildAddChannelToWelcomeScreenSchema = { - channel_id: String, - description: String, - $emoji_id: String, - emoji_name: String +export const GuildUpdateWelcomeScreenSchema = { + $welcome_channels: [ + { + channel_id: String, + description: String, + $emoji_id: String, + emoji_name: String + } + ], + $enabled: Boolean, + $description: new Length(String, 0, 140) }; -export interface GuildAddChannelToWelcomeScreenSchema { - channel_id: string; - description: string; - emoji_id?: string; - emoji_name: string; +export interface GuildUpdateWelcomeScreenSchema { + welcome_channels?: { + channel_id: string; + description: string; + emoji_id?: string; + emoji_name: string; + }[]; + enabled?: boolean; + description?: string; } -- cgit 1.5.1 From d0292ef96bedde2dd23962c15b2a0446b8492fb0 Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Sun, 29 Aug 2021 17:12:46 +0200 Subject: :bug: convert bigint -> string --- api/src/middlewares/RateLimit.ts | 4 ++-- .../routes/channels/#channel_id/messages/index.ts | 2 +- api/src/routes/guilds/index.ts | 2 +- api/src/schema/Guild.ts | 2 +- bundle/database.db | Bin 225280 -> 225280 bytes gateway/src/opcodes/Identify.ts | 2 +- gateway/src/schema/Activity.ts | 4 ++-- util/src/entities/Application.ts | 2 +- util/src/interfaces/Event.ts | 6 +++--- 9 files changed, 12 insertions(+), 12 deletions(-) (limited to 'api/src/schema/Guild.ts') diff --git a/api/src/middlewares/RateLimit.ts b/api/src/middlewares/RateLimit.ts index e0cf103a..ed6b951a 100644 --- a/api/src/middlewares/RateLimit.ts +++ b/api/src/middlewares/RateLimit.ts @@ -1,6 +1,6 @@ import { Config, listenEvent, emitEvent, RateLimit } from "@fosscord/util"; import { NextFunction, Request, Response, Router } from "express"; -import { LessThan } from "typeorm"; +import { LessThan, MoreThan } from "typeorm"; import { getIpAdress } from "../util/ipAddress"; import { API_PREFIX_TRAILING_SLASH } from "./Authentication"; @@ -100,7 +100,7 @@ export async function initRateLimits(app: Router) { Cache.set(event.channel_id as string, event.data); event.acknowledge?.(); }); - await RateLimit.delete({ expires_at: LessThan(new Date()) }); // clean up if not already deleted + await RateLimit.delete({ expires_at: MoreThan(new Date()) }); // cleans up if not already deleted, morethan -> older date const limits = await RateLimit.find({ blocked: true }); limits.forEach((limit) => { Cache.set(limit.executor_id, limit); diff --git a/api/src/routes/channels/#channel_id/messages/index.ts b/api/src/routes/channels/#channel_id/messages/index.ts index 6307c022..17944548 100644 --- a/api/src/routes/channels/#channel_id/messages/index.ts +++ b/api/src/routes/channels/#channel_id/messages/index.ts @@ -77,7 +77,7 @@ router.get("/", async (req: Request, res: Response) => { delete x.user_ids; }); // @ts-ignore - if (!x.author) x.author = { discriminator: "0000", username: "Deleted User", public_flags: 0n, avatar: null }; + if (!x.author) x.author = { discriminator: "0000", username: "Deleted User", public_flags: "0", avatar: null }; return x; }); diff --git a/api/src/routes/guilds/index.ts b/api/src/routes/guilds/index.ts index c158c7d4..1e83cf13 100644 --- a/api/src/routes/guilds/index.ts +++ b/api/src/routes/guilds/index.ts @@ -47,7 +47,7 @@ router.post("/", check(GuildCreateSchema), async (req: Request, res: Response) = premium_tier: 0, public_updates_channel_id: undefined, rules_channel_id: undefined, - system_channel_flags: 0, + system_channel_flags: "0", system_channel_id: undefined, unavailable: false, vanity_url_code: undefined, diff --git a/api/src/schema/Guild.ts b/api/src/schema/Guild.ts index 01690ae9..3e98fe76 100644 --- a/api/src/schema/Guild.ts +++ b/api/src/schema/Guild.ts @@ -33,7 +33,7 @@ export const GuildUpdateSchema = { $icon: String, $verification_level: Number, $default_message_notifications: Number, - $system_channel_flags: Number, + $system_channel_flags: String, $system_channel_id: String, $explicit_content_filter: Number, $public_updates_channel_id: String, diff --git a/bundle/database.db b/bundle/database.db index 9572c45e..2d4abd49 100644 Binary files a/bundle/database.db and b/bundle/database.db differ diff --git a/gateway/src/opcodes/Identify.ts b/gateway/src/opcodes/Identify.ts index 5be2acce..87008998 100644 --- a/gateway/src/opcodes/Identify.ts +++ b/gateway/src/opcodes/Identify.ts @@ -42,7 +42,7 @@ export async function onIdentify(this: WebSocket, data: Payload) { } } - const members = await Member.find({ where: { id: this.user_id }, relations: ["guilds"] }); + const members = await Member.find({ where: { id: this.user_id }, relations: ["guild"] }); const merged_members = members.map((x: any) => { const y = { ...x, user_id: x.id }; delete y.settings; diff --git a/gateway/src/schema/Activity.ts b/gateway/src/schema/Activity.ts index 0fd0592f..f1665efd 100644 --- a/gateway/src/schema/Activity.ts +++ b/gateway/src/schema/Activity.ts @@ -39,7 +39,7 @@ export const ActivitySchema = { $match: String, }, $instance: Boolean, - $flags: BigInt, + $flags: String, }, ], $since: Number, // unix time (in milliseconds) of when the client went idle, or null if the client is not idle @@ -79,7 +79,7 @@ export interface ActivitySchema { match?: string; // the secret for a specific instanced match }; instance?: boolean; - flags: bigint; // activity flags OR d together, describes what the payload includes + flags: string; // activity flags OR d together, describes what the payload includes } ]; since?: number; // unix time (in milliseconds) of when the client went idle, or null if the client is not idle diff --git a/util/src/entities/Application.ts b/util/src/entities/Application.ts index a87b5cea..b179d171 100644 --- a/util/src/entities/Application.ts +++ b/util/src/entities/Application.ts @@ -62,7 +62,7 @@ export class Application extends BaseClass { cover_image?: string; // the application's default rich presence invite cover image hash @Column() - flags: number; // the application's public flags + flags: string; // the application's public flags } export interface ApplicationCommand { diff --git a/util/src/interfaces/Event.ts b/util/src/interfaces/Event.ts index 0de55f71..814a8beb 100644 --- a/util/src/interfaces/Event.ts +++ b/util/src/interfaces/Event.ts @@ -36,7 +36,7 @@ export interface ReadyEventData { mobile: boolean; desktop: boolean; email: string | undefined; - flags: bigint; + flags: string; mfa_enabled: boolean; nsfw_allowed: boolean; phone: string | undefined; @@ -85,7 +85,7 @@ export interface ReadyEventData { }; application?: { id: string; - flags: bigint; + flags: string; }; merged_members?: Omit[][]; // probably all users who the user is in contact with @@ -95,7 +95,7 @@ export interface ReadyEventData { id: string; username: string; bot: boolean; - public_flags: bigint; + public_flags: string; }[]; } -- cgit 1.5.1