EmbedHandlers: more configuration for embeds, switch to storing all returned embeds

This commit is contained in:
Rory& committed 2026-03-26 15:14:18 +01:00
1 parent 1ad351559f
commit 53ab01c4e2
7 files changed
+117 -40

No files matched your search

+2
View File
@@ -22,6 +22,7 @@ import {
ComponentConfiguration,
DefaultsConfiguration,
EmailConfiguration,
EmbedConfiguration,
EndpointConfiguration,
ExternalTokensConfiguration,
GeneralConfiguration,
@@ -61,4 +62,5 @@ export class ConfigValue {
user: UserConfiguration = new UserConfiguration();
offload: OffloadConfiguration = new OffloadConfiguration();
components = new ComponentConfiguration();
embeds = new EmbedConfiguration();
}
@@ -0,0 +1,29 @@
/*
Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
Copyright (C) 2025 Spacebar and Spacebar Contributors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
export class EmbedConfiguration {
defaultUserAgent: string | null = null;
youtube = new YoutubeEmbedConfiguration();
}
export class YoutubeEmbedConfiguration {
useCurlUserAgent: boolean = false;
userAgent: string | null = null;
cookie: string | null = null;
}
+1
View File
@@ -37,3 +37,4 @@ export * from "./subconfigurations";
export * from "./TemplateConfiguration";
export * from "./UsersConfiguration";
export * from "./ComponentConfiguration";
export * from "./EmbedConfiguration";
+4 -5
View File
@@ -27,12 +27,11 @@ export class EmbedCache extends BaseClass {
@Column()
url: string;
@Column({ type: "simple-json" })
embed: Embed;
@Column({ type: "simple-json", nullable: true })
embed?: Embed;
// TODO: store all returned embed objects from a handler
// @Column({ type: "simple-json" })
// embeds: Embed[];
@Column({ type: "simple-json", nullable: true })
embeds?: Embed[];
@Column({ name: "created_at", type: "timestamp with time zone" })
createdAt: Date;
@@ -0,0 +1,16 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class EmbedCacheCreatedAt1772404321403 implements MigrationInterface {
name = "EmbedCacheCreatedAt1772404321403";
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "embed_cache" ALTER COLUMN "embed" DROP NOT NULL;`);
await queryRunner.query(`ALTER TABLE "embed_cache" ADD "embeds" text NULL;`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "embed_cache" DROP COLUMN "embeds"`);
await queryRunner.query(`UPDATE "embed_cache" SET "embed" = '{}' WHERE "embed" IS NULL;`);
await queryRunner.query(`ALTER TABLE "embed_cache" ALTER COLUMN "embed" SET NOT NULL;`);
}
}