diff options
author | Lobo Metalúrgico <43734867+LoboMetalurgico@users.noreply.github.com> | 2021-10-09 23:44:59 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-09 23:44:59 -0300 |
commit | a801dfc47895ecd0c6e15e382a18c1d6cbe0b4e9 (patch) | |
tree | 50a0e87efa1bbc503c65677ab8dc514047eb1164 /util | |
parent | (api): fix some issues (diff) | |
parent | :sparkles: random guest username generation added (diff) | |
download | server-a801dfc47895ecd0c6e15e382a18c1d6cbe0b4e9.tar.xz |
Merge branch 'fosscord:master' into milestoneV1/routes/implement/emojis
Diffstat (limited to 'util')
-rw-r--r-- | util/src/entities/ReadState.ts | 13 | ||||
-rw-r--r-- | util/src/util/Config.ts | 1 | ||||
-rw-r--r-- | util/src/util/cdn.ts | 23 |
3 files changed, 26 insertions, 11 deletions
diff --git a/util/src/entities/ReadState.ts b/util/src/entities/ReadState.ts index 68e867a0..89480e83 100644 --- a/util/src/entities/ReadState.ts +++ b/util/src/entities/ReadState.ts @@ -1,4 +1,4 @@ -import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm"; +import { Column, Entity, Index, JoinColumn, ManyToOne, RelationId } from "typeorm"; import { BaseClass } from "./BaseClass"; import { Channel } from "./Channel"; import { Message } from "./Message"; @@ -9,8 +9,9 @@ import { User } from "./User"; // public read receipt ≥ notification cursor ≥ private fully read marker @Entity("read_states") +@Index(["channel_id", "user_id"], { unique: true }) export class ReadState extends BaseClass { - @Column({ nullable: true }) + @Column() @RelationId((read_state: ReadState) => read_state.channel) channel_id: string; @@ -20,7 +21,7 @@ export class ReadState extends BaseClass { }) channel: Channel; - @Column({ nullable: true }) + @Column() @RelationId((read_state: ReadState) => read_state.user) user_id: string; @@ -35,15 +36,15 @@ export class ReadState extends BaseClass { last_message_id: string; @JoinColumn({ name: "last_message_id" }) - @ManyToOne(() => Message) + @ManyToOne(() => Message, { nullable: true }) last_message?: Message; @Column({ nullable: true }) last_pin_timestamp?: Date; - @Column() + @Column({ nullable: true }) mention_count: number; - @Column() + @Column({ nullable: true }) manual: boolean; } diff --git a/util/src/util/Config.ts b/util/src/util/Config.ts index eeeaa2ce..704f3f2f 100644 --- a/util/src/util/Config.ts +++ b/util/src/util/Config.ts @@ -12,7 +12,6 @@ export const Config = { if (config) return config; pairs = await ConfigEntity.find(); config = pairsToConfig(pairs); - console.log(config.guild.autoJoin); return this.set((config || {}).merge(DefaultConfigOptions)); }, diff --git a/util/src/util/cdn.ts b/util/src/util/cdn.ts index 2de23f5d..8d45f85f 100644 --- a/util/src/util/cdn.ts +++ b/util/src/util/cdn.ts @@ -25,15 +25,30 @@ export async function uploadFile(path: string, file: Express.Multer.File) { return result; } -export async function handleFile(path: string, body?: string): Promise<string | undefined> { - if (!body || !body.startsWith("data:")) return body; +export async function handleFile( + path: string, + body?: string +): Promise< + | (string & { + id: string; + content_type: string; + size: number; + url: string; + }) + | undefined +> { + if (!body || !body.startsWith("data:")) return undefined; try { const mimetype = body.split(":")[1].split(";")[0]; const buffer = Buffer.from(body.split(",")[1], "base64"); // @ts-ignore - const { id } = await uploadFile(path, { buffer, mimetype, originalname: "banner" }); - return id; + const file = await uploadFile(path, { buffer, mimetype, originalname: "banner" }); + const obj = file.id; + for (const key in file) { + obj[key] = file[key]; + } + return obj; } catch (error) { console.error(error); throw new HTTPError("Invalid " + path); |