mirror of
https://github.com/spacebarchat/server.git
synced 2026-10-22 17:32:30 +00:00
Embeds: factor out from postMessage
This commit is contained in:
1 parent
47e782ad62
commit
daaf6eae28
6 files changed
+202
-134
No files matched your search
@@ -24,4 +24,5 @@ export class MessageLimits {
|
||||
maxBulkDelete: number = 1000;
|
||||
maxEmbedDownloadSize: number = 1024 * 1024 * 5;
|
||||
maxPreloadCount: number = 100;
|
||||
maxEmbeds: number = 20;
|
||||
}
|
||||
@@ -29,4 +29,11 @@ export class EmbedCache extends BaseClass {
|
||||
|
||||
@Column({ type: "simple-json" })
|
||||
embed: Embed;
|
||||
|
||||
// TODO: store all returned embed objects from a handler
|
||||
// @Column({ type: "simple-json" })
|
||||
// embeds: Embed[];
|
||||
|
||||
@Column({ name: "created_at", type: "timestamp with time zone" })
|
||||
createdAt: Date;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class EmbedCacheCreatedAt1772404321402 implements MigrationInterface {
|
||||
name = "EmbedCacheCreatedAt1772404321402";
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE "embed_cache" ADD "created_at" timestamp with time zone DEFAULT now();`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE "embed_cache" DROP COLUMN "created_at"`);
|
||||
}
|
||||
}
|
||||
@@ -42,3 +42,16 @@ export function arrayDistinctBy<T, M>(array: T[], selector: (elem: T) => M): T[]
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
export function arrayGroupBy<T, M>(array: T[], selector: (elem: T) => M): Map<M, T[]> {
|
||||
const map = new Map<M, T[]>();
|
||||
|
||||
array.forEach((item) => {
|
||||
const mappedValue = selector(item);
|
||||
const existing = map.get(mappedValue);
|
||||
if (existing) existing.push(item);
|
||||
else map.set(mappedValue, [item]);
|
||||
});
|
||||
|
||||
return map;
|
||||
}
|
||||
Reference in new issue
Block a user