Fix error logging, dont use simple-array

This commit is contained in:
Rory&
2026-04-18 00:23:14 +02:00
parent 16dcd33289
commit e2a5e2d50c
13 changed files with 76 additions and 20 deletions
+1 -1
View File
@@ -50,7 +50,7 @@ export function ErrorHandler(error: Error & { type?: string }, req: Request, res
code = 50109;
message = "The request body contains invalid JSON.";
} else {
console.error(`[Error] ${code} ${req.url}\n`, errors, "\nbody:", req.body);
console.error(`[Error] ${code} ${req.url}\n`, errors ?? error, "\nbody:", req.body);
if (req.server?.options?.production) {
// don't expose internal errors to the user, instead human errors should be thrown as HTTPError
+3 -3
View File
@@ -61,7 +61,7 @@ export class Application extends BaseClass {
@Column()
flags: number = 0;
@Column({ type: "simple-array", nullable: true })
@Column({ type: "varchar", nullable: true })
redirect_uris: string[] = [];
@Column({ nullable: true })
@@ -92,7 +92,7 @@ export class Application extends BaseClass {
@OneToOne(() => User, { onDelete: "CASCADE" })
bot?: User;
@Column({ type: "simple-array", nullable: true })
@Column({ type: "varchar", array: true, nullable: true })
tags?: string[];
@Column({ nullable: true })
@@ -120,7 +120,7 @@ export class Application extends BaseClass {
//just for us
//@Column({ type: "simple-array", nullable: true })
//@Column({ type: "varchar", array: true, nullable: true })
//rpc_origins?: string[];
//@Column({ nullable: true })
+2 -2
View File
@@ -35,10 +35,10 @@ export class AutomodRule extends BaseClass {
@Column()
event_type: AutomodRuleEventType;
@Column({ type: "simple-array" })
@Column({ type: "int8", array: true })
exempt_channels: string[];
@Column({ type: "simple-array" })
@Column({ type: "int8", array: true })
exempt_roles: string[];
@Column()
-2
View File
@@ -122,5 +122,3 @@ export class BaseClass extends BaseClassWithoutId {
if (!this.id) this.id = Snowflake.generate();
}
}
export const ArrayColumn = (opts: ColumnOptions) => (process.env.DATABASE?.startsWith("postgres") ? Column({ ...opts, array: true }) : Column({ ...opts, type: "simple-array" }));
+1 -1
View File
@@ -59,7 +59,7 @@ export class ConnectedAccount extends BaseClass {
@Column({ select: false })
visibility?: number = 0;
@Column({ type: "simple-array" })
@Column({ type: "varchar", array: true })
integrations?: string[] = [];
@Column({ type: "jsonb", name: "metadata", nullable: true })
+2 -2
View File
@@ -57,9 +57,9 @@ export class Emoji extends BaseClass {
@Column()
require_colons: boolean;
@Column({ type: "simple-array" })
@Column({ type: "int8", array: true })
roles: string[]; // roles this emoji is whitelisted to (new discord feature?)
@Column({ type: "simple-array", nullable: true })
@Column({ type: "int8", array: true, nullable: true })
groups: string[]; // user groups this emoji is whitelisted to (Spacebar extension)
}
+1 -1
View File
@@ -32,7 +32,7 @@ export class SecuritySettings extends BaseClass {
@Column()
encryption_permission_mask: number;
@Column({ type: "simple-array" })
@Column({ type: "varchar", array: true })
allowed_algorithms: string[];
@Column()
+3 -3
View File
@@ -101,7 +101,7 @@ export class Guild extends BaseClass {
@Column({ nullable: true })
explicit_content_filter?: number;
@Column({ type: "simple-array" })
@Column({ type: "varchar", array: true })
features: string[] = []; //TODO use enum
//TODO: https://discord.com/developers/docs/resources/guild#guild-object-guild-features
@@ -267,7 +267,7 @@ export class Guild extends BaseClass {
@Column({ type: "jsonb" })
welcome_screen: GuildWelcomeScreen;
@Column({ nullable: true })
@Column({ nullable: true, type: "int8" })
@RelationId((guild: Guild) => guild.widget_channel)
widget_channel_id?: string;
@@ -295,7 +295,7 @@ export class Guild extends BaseClass {
@Column({ nullable: true })
premium_progress_bar_enabled: boolean = false;
@Column({ select: false, type: "simple-array" })
@Column({ select: false, type: "int8", array: true })
channel_ordering: string[];
@Column()
+1 -1
View File
@@ -133,7 +133,7 @@ export class Member extends BaseClassWithoutId {
@Column()
bio: string;
@Column({ nullable: true, type: "simple-array" })
@Column({ nullable: true, type: "int4", array: true })
theme_colors?: number[]; // TODO: Separate `User` and `UserProfile` models
@Column({ nullable: true })
+1 -1
View File
@@ -28,7 +28,7 @@ export class TeamMember extends BaseClass {
@Column({ type: "int" })
membership_state: TeamMemberState;
@Column({ type: "simple-array" })
@Column({ type: "varchar", array: true })
permissions: string[];
@Column()
+3 -3
View File
@@ -61,7 +61,7 @@ export class User extends BaseClass {
// TODO: Separate `User` and `UserProfile` models
// puyo: changed from [number, number] because it breaks openapi
@Column({ nullable: true, type: "simple-array" })
@Column({ nullable: true, type: "int4", array: true })
theme_colors?: number[];
@Column({ nullable: true })
@@ -166,7 +166,7 @@ export class User extends BaseClass {
hash?: string; // hash of the password, salt is saved in password (bcrypt)
};
@Column({ type: "simple-array", select: false })
@Column({ type: "varchar", array: true, select: false })
fingerprints: string[] = []; // array of fingerprints -> used to prevent multiple accounts
@OneToOne(() => UserSettings, {
@@ -180,7 +180,7 @@ export class User extends BaseClass {
@OneToMany(() => SecurityKey, (key: SecurityKey) => key.user)
security_keys: SecurityKey[];
@Column({ type: "simple-array", nullable: true })
@Column({ type: "int8", array: true, nullable: true })
badge_ids?: string[];
@Column({ type: "jsonb", nullable: true })
@@ -0,0 +1,17 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class GuildChannelOrderingAsArray1776450647000 implements MigrationInterface {
name = "GuildChannelOrderingAsArray1776450647000";
public async up(queryRunner: QueryRunner): Promise<void> {
// spacebar was randomly adding json data into CSV values, unwrap them
await queryRunner.query(`UPDATE guilds SET channel_ordering = REPLACE(channel_ordering, '"', '') WHERE channel_ordering ~ '"';`);
await queryRunner.query(`UPDATE guilds SET channel_ordering = REPLACE(channel_ordering, '[', '') WHERE channel_ordering ~ '\\[';`);
await queryRunner.query(`UPDATE guilds SET channel_ordering = REPLACE(channel_ordering, ']', '') WHERE channel_ordering ~ '\\]';`);
await queryRunner.query(`ALTER TABLE guilds ALTER COLUMN channel_ordering TYPE int8[] USING string_to_array(channel_ordering, ',')::int8[];`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
console.log(`Migration ${this.name}.down() not implemented`);
}
}
@@ -0,0 +1,41 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class AllSimpleArraysToPgArrays1776450647001 implements MigrationInterface {
name = "AllSimpleArraysToPgArrays1776450647001";
public async up(queryRunner: QueryRunner): Promise<void> {
await this.cleanAndConvertToArray(queryRunner, "applications", "redirect_uris", "varchar");
await this.cleanAndConvertToArray(queryRunner, "applications", "tags", "varchar");
// await this.cleanAndConvertToArray(queryRunner, "applications", "rpc_origins", "varchar");
await this.cleanAndConvertToArray(queryRunner, "automod_rules", "exempt_channels", "int8");
await this.cleanAndConvertToArray(queryRunner, "automod_rules", "exempt_roles", "int8");
await this.cleanAndConvertToArray(queryRunner, "connected_accounts", "integrations", "varchar");
await this.cleanAndConvertToArray(queryRunner, "emojis", "roles", "int8");
await this.cleanAndConvertToArray(queryRunner, "emojis", "groups", "int8");
await this.cleanAndConvertToArray(queryRunner, "guilds", "features", "varchar");
await this.cleanAndConvertToArray(queryRunner, "members", "theme_colors", "int4");
await this.cleanAndConvertToArray(queryRunner, "team_members", "permissions", "varchar");
await this.cleanAndConvertToArray(queryRunner, "users", "theme_colors", "int4");
await this.cleanAndConvertToArray(queryRunner, "users", "fingerprints", "varchar");
await this.cleanAndConvertToArray(queryRunner, "users", "badge_ids", "int8");
}
public async down(queryRunner: QueryRunner): Promise<void> {
console.log(`Migration ${this.name}.down() not implemented`);
}
private async cleanAndConvertToArray(queryRunner: QueryRunner, table: string, column: string, type: string) {
// spacebar was randomly adding json data into CSV values, unwrap them
await queryRunner.query(`UPDATE ${table} SET ${column} = REPLACE(${column}, '"', '') WHERE ${column} ~ '"';`);
await queryRunner.query(`UPDATE ${table} SET ${column} = REPLACE(${column}, '[', '') WHERE ${column} ~ '\\[';`);
await queryRunner.query(`UPDATE ${table} SET ${column} = REPLACE(${column}, ']', '') WHERE ${column} ~ '\\]';`);
await queryRunner.query(`ALTER TABLE ${table} ALTER COLUMN ${column} TYPE ${type}[] USING string_to_array(${column}, ',')::${type}[];`);
}
}