upd: port Listenbrainz

upd: port Listenbrainz
This commit is contained in:
Amelia Yukii 2023-09-22 03:34:39 +02:00 committed by GitHub
commit 313cbb19db
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 210 additions and 3 deletions

View file

@ -0,0 +1,20 @@
export class AddLbToUser1691264431000 {
name = "AddLbToUser1691264431000";
async up(queryRunner) {
await queryRunner.query(`
ALTER TABLE "user_profile"
ADD "listenbrainz" character varying(128) NULL
`);
await queryRunner.query(`
COMMENT ON COLUMN "user_profile"."listenbrainz"
IS 'listenbrainz username to fetch currently playing.'
`);
}
async down(queryRunner) {
await queryRunner.query(`
ALTER TABLE "user_profile" DROP COLUMN "listenbrainz"
`);
}
}

View file

@ -14,7 +14,7 @@ import type { Promiseable } from '@/misc/prelude/await-all.js';
import { awaitAll } from '@/misc/prelude/await-all.js';
import { USER_ACTIVE_THRESHOLD, USER_ONLINE_THRESHOLD } from '@/const.js';
import type { MiLocalUser, MiPartialLocalUser, MiPartialRemoteUser, MiRemoteUser, MiUser } from '@/models/User.js';
import { birthdaySchema, descriptionSchema, localUsernameSchema, locationSchema, nameSchema, passwordSchema } from '@/models/User.js';
import { birthdaySchema, listenbrainzSchema, descriptionSchema, localUsernameSchema, locationSchema, nameSchema, passwordSchema } from '@/models/User.js';
import type { UsersRepository, UserSecurityKeysRepository, FollowingsRepository, FollowRequestsRepository, BlockingsRepository, MutingsRepository, DriveFilesRepository, NoteUnreadsRepository, UserNotePiningsRepository, UserProfilesRepository, AnnouncementReadsRepository, AnnouncementsRepository, MiUserProfile, RenoteMutingsRepository, UserMemoRepository } from '@/models/_.js';
import { bindThis } from '@/decorators.js';
import { RoleService } from '@/core/RoleService.js';
@ -139,6 +139,7 @@ export class UserEntityService implements OnModuleInit {
public validateDescription = ajv.compile(descriptionSchema);
public validateLocation = ajv.compile(locationSchema);
public validateBirthday = ajv.compile(birthdaySchema);
public validateListenBrainz = ajv.compile(listenbrainzSchema);
//#endregion
public isLocalUser = isLocalUser;
@ -381,6 +382,7 @@ export class UserEntityService implements OnModuleInit {
description: profile!.description,
location: profile!.location,
birthday: profile!.birthday,
listenbrainz: profile!.listenbrainz,
lang: profile!.lang,
fields: profile!.fields,
verifiedLinks: profile!.verifiedLinks,

View file

@ -280,4 +280,5 @@ export const passwordSchema = { type: 'string', minLength: 1 } as const;
export const nameSchema = { type: 'string', minLength: 1, maxLength: 50 } as const;
export const descriptionSchema = { type: 'string', minLength: 1, maxLength: 1500 } as const;
export const locationSchema = { type: 'string', minLength: 1, maxLength: 50 } as const;
export const listenbrainzSchema = { type: "string", minLength: 1, maxLength: 128 } as const;
export const birthdaySchema = { type: 'string', pattern: /^([0-9]{4})-([0-9]{2})-([0-9]{2})$/.toString().slice(1, -1) } as const;

View file

@ -34,6 +34,13 @@ export class MiUserProfile {
})
public birthday: string | null;
@Column("varchar", {
length: 128,
nullable: true,
comment: "The ListenBrainz username of the User.",
})
public listenbrainz: string | null;
@Column('varchar', {
length: 2048, nullable: true,
comment: 'The description (bio) of the User.',

View file

@ -145,6 +145,12 @@ export const packedUserDetailedNotMeOnlySchema = {
nullable: true, optional: false,
example: '2018-03-12',
},
ListenBrainz: {
type: "string",
nullable: true,
optional: false,
example: "Steve",
},
lang: {
type: 'string',
nullable: true, optional: false,

View file

@ -13,7 +13,7 @@ import { extractHashtags } from '@/misc/extract-hashtags.js';
import * as Acct from '@/misc/acct.js';
import type { UsersRepository, DriveFilesRepository, UserProfilesRepository, PagesRepository } from '@/models/_.js';
import type { MiLocalUser, MiUser } from '@/models/User.js';
import { birthdaySchema, descriptionSchema, locationSchema, nameSchema } from '@/models/User.js';
import { birthdaySchema, listenbrainzSchema, descriptionSchema, locationSchema, nameSchema } from '@/models/User.js';
import type { MiUserProfile } from '@/models/UserProfile.js';
import { notificationTypes } from '@/types.js';
import { normalizeForSearch } from '@/misc/normalize-for-search.js';
@ -129,6 +129,7 @@ export const paramDef = {
description: { ...descriptionSchema, nullable: true },
location: { ...locationSchema, nullable: true },
birthday: { ...birthdaySchema, nullable: true },
listenbrainz: { ...listenbrainzSchema, nullable: true },
lang: { type: 'string', enum: [null, ...Object.keys(langmap)] as string[], nullable: true },
avatarId: { type: 'string', format: 'misskey:id', nullable: true },
bannerId: { type: 'string', format: 'misskey:id', nullable: true },
@ -224,6 +225,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
if (ps.lang !== undefined) profileUpdates.lang = ps.lang;
if (ps.location !== undefined) profileUpdates.location = ps.location;
if (ps.birthday !== undefined) profileUpdates.birthday = ps.birthday;
if (ps.listenbrainz !== undefined) profileUpdates.listenbrainz = ps.listenbrainz;
if (ps.ffVisibility !== undefined) profileUpdates.ffVisibility = ps.ffVisibility;
if (ps.mutedWords !== undefined) {
// TODO: ちゃんと数える