diff --git a/packages/backend/src/migration/1713451569342-AddDriveFileUsage.ts b/packages/backend/src/migration/1713451569342-AddDriveFileUsage.ts index 57c6a73890..3bdb1aafc8 100644 --- a/packages/backend/src/migration/1713451569342-AddDriveFileUsage.ts +++ b/packages/backend/src/migration/1713451569342-AddDriveFileUsage.ts @@ -3,11 +3,15 @@ import type { MigrationInterface, QueryRunner } from "typeorm"; export class AddDriveFileUsage1713451569342 implements MigrationInterface { public async up(queryRunner: QueryRunner): Promise { await queryRunner.query( - `ALTER TABLE "drive_file" ADD "usageHint" character varying(16) DEFAULT NULL`, + `CREATE TYPE drive_file_usage_hint_enum AS ENUM ('userAvatar', 'userBanner')`, + ); + await queryRunner.query( + `ALTER TABLE "drive_file" ADD "usageHint" drive_file_usage_hint_enum DEFAULT NULL`, ); } public async down(queryRunner: QueryRunner): Promise { await queryRunner.query(`ALTER TABLE "drive_file" DROP COLUMN "usageHint"`); + await queryRunner.query(`DROP TYPE drive_file_usage_hint_enum`); } } diff --git a/packages/backend/src/models/entities/drive-file.ts b/packages/backend/src/models/entities/drive-file.ts index f257280d60..2c6c1bf598 100644 --- a/packages/backend/src/models/entities/drive-file.ts +++ b/packages/backend/src/models/entities/drive-file.ts @@ -16,7 +16,7 @@ import { DriveFolder } from "./drive-folder.js"; import { DB_MAX_IMAGE_COMMENT_LENGTH } from "@/misc/hard-limits.js"; import { NoteFile } from "./note-file.js"; -export type DriveFileUsageHint = "user_avatar" | "user_banner" | null; +export type DriveFileUsageHint = "userAvatar" | "userBanner" | null; @Entity() @Index(["userId", "folderId", "id"]) @@ -179,8 +179,9 @@ export class DriveFile { }) public isSensitive: boolean; - @Column("varchar", { - length: 16, + @Column({ + type: "enum", + enum: ["userAvatar", "userBanner"], nullable: true, comment: "Hint for what the file is used for.", }) diff --git a/packages/backend/src/remote/activitypub/models/person.ts b/packages/backend/src/remote/activitypub/models/person.ts index 657ac7d553..4baa2c021b 100644 --- a/packages/backend/src/remote/activitypub/models/person.ts +++ b/packages/backend/src/remote/activitypub/models/person.ts @@ -369,7 +369,7 @@ export async function createPerson( : resolveImage( user, img, - index === 0 ? "user_avatar" : index === 1 ? "user_banner" : null, + index === 0 ? "userAvatar" : index === 1 ? "userBanner" : null, ).catch(() => null), ), ); @@ -449,7 +449,7 @@ export async function updatePerson( : resolveImage( user, img, - index === 0 ? "user_avatar" : index === 1 ? "user_banner" : null, + index === 0 ? "userAvatar" : index === 1 ? "userBanner" : null, ).catch(() => null), ), ); diff --git a/packages/backend/src/server/api/endpoints/i/update.ts b/packages/backend/src/server/api/endpoints/i/update.ts index 29d03cc465..4f65c59a9e 100644 --- a/packages/backend/src/server/api/endpoints/i/update.ts +++ b/packages/backend/src/server/api/endpoints/i/update.ts @@ -335,14 +335,14 @@ export default define(meta, paramDef, async (ps, _user, token) => { if (avatar) { if (user.avatarId) await DriveFiles.update(user.avatarId, { usageHint: null }); - await DriveFiles.update(avatar.id, { usageHint: "user_avatar" }); + await DriveFiles.update(avatar.id, { usageHint: "userAvatar" }); } // Update old/new banner usage hints if (banner) { if (user.bannerId) await DriveFiles.update(user.bannerId, { usageHint: null }); - await DriveFiles.update(banner.id, { usageHint: "user_banner" }); + await DriveFiles.update(banner.id, { usageHint: "userBanner" }); } if (Object.keys(updates).length > 0) await Users.update(user.id, updates); diff --git a/packages/backend/src/services/drive/add-file.ts b/packages/backend/src/services/drive/add-file.ts index 2f975e1984..d180bbabf3 100644 --- a/packages/backend/src/services/drive/add-file.ts +++ b/packages/backend/src/services/drive/add-file.ts @@ -66,7 +66,7 @@ function urlPathJoin( * @param type Content-Type for original * @param hash Hash for original * @param size Size for original - * @param usage Optional usage hint for file (f.e. "user_avatar") + * @param usage Optional usage hint for file (f.e. "userAvatar") */ async function save( file: DriveFile,