add MiUserProfile.defaultCW property and API

This commit is contained in:
Hazelnoot 2025-02-01 17:07:34 -05:00
parent 8a087e75a5
commit 74407bc8ee
7 changed files with 47 additions and 3 deletions

View file

@ -0,0 +1,11 @@
export class AddUserProfileDefaultCw1738446745738 {
name = 'AddUserProfileDefaultCw1738446745738'
async up(queryRunner) {
await queryRunner.query(`ALTER TABLE "user_profile" ADD "default_cw" text`);
}
async down(queryRunner) {
await queryRunner.query(`ALTER TABLE "user_profile" DROP COLUMN "default_cw"`);
}
}

View file

@ -669,6 +669,7 @@ export class UserEntityService implements OnModuleInit {
achievements: profile!.achievements,
loggedInDays: profile!.loggedInDates.length,
policies: this.roleService.getUserPolicies(user.id),
defaultCW: profile?.defaultCW ?? null,
} : {}),
...(opts.includeSecrets ? {

View file

@ -36,10 +36,10 @@ export class MiUserProfile {
})
public birthday: string | null;
@Column("varchar", {
@Column('varchar', {
length: 128,
nullable: true,
comment: "The ListenBrainz username of the User.",
comment: 'The ListenBrainz username of the User.',
})
public listenbrainz: string | null;
@ -290,6 +290,12 @@ export class MiUserProfile {
unlockedAt: number;
}[];
@Column('text', {
name: 'default_cw',
nullable: true,
})
public defaultCW: string | null;
//#region Denormalized fields
@Index()
@Column('varchar', {

View file

@ -752,6 +752,10 @@ export const packedMeDetailedOnlySchema = {
},
},
//#endregion
defaultCW: {
type: 'string',
nullable: true, optional: false,
},
},
} as const;

View file

@ -133,6 +133,12 @@ export const meta = {
id: '0b3f9f6a-2f4d-4b1f-9fb4-49d3a2fd7191',
httpStatusCode: 422,
},
maxCwLength: {
message: 'You tried setting a default content warning which is too long.',
code: 'MAX_CW_LENGTH',
id: '7004c478-bda3-4b4f-acb2-4316398c9d52',
},
},
res: {
@ -243,6 +249,7 @@ export const paramDef = {
uniqueItems: true,
items: { type: 'string' },
},
defaultCW: { type: 'string', nullable: true },
},
} as const;
@ -494,6 +501,16 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
updates.alsoKnownAs = newAlsoKnownAs.size > 0 ? Array.from(newAlsoKnownAs) : null;
}
let defaultCW = ps.defaultCW;
if (defaultCW !== undefined) {
if (defaultCW === '') defaultCW = null;
if (defaultCW && defaultCW.length > this.config.maxCwLength) {
throw new ApiError(meta.errors.maxCwLength);
}
profileUpdates.defaultCW = defaultCW;
}
//#region emojis/tags
let emojis = [] as string[];