diff options
Diffstat (limited to 'packages/backend/src/server/api/endpoints')
| -rw-r--r-- | packages/backend/src/server/api/endpoints/i/update.ts | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/packages/backend/src/server/api/endpoints/i/update.ts b/packages/backend/src/server/api/endpoints/i/update.ts index 93897b9c8f..1011a8d31a 100644 --- a/packages/backend/src/server/api/endpoints/i/update.ts +++ b/packages/backend/src/server/api/endpoints/i/update.ts @@ -60,6 +60,12 @@ export const meta = { id: '0d8f5629-f210-41c2-9433-735831a58595', }, + noSuchBackground: { + message: 'No such background file.', + code: 'NO_SUCH_BACKGROUND', + id: '0d8f5629-f210-41c2-9433-735831a58582', + }, + avatarNotAnImage: { message: 'The file specified as an avatar is not an image.', code: 'AVATAR_NOT_AN_IMAGE', @@ -72,6 +78,12 @@ export const meta = { id: '75aedb19-2afd-4e6d-87fc-67941256fa60', }, + backgroundNotAnImage: { + message: 'The file specified as a background is not an image.', + code: 'BACKGROUND_NOT_AN_IMAGE', + id: '75aedb19-2afd-4e6d-87fc-67941256fa40', + }, + noSuchPage: { message: 'No such page.', code: 'NO_SUCH_PAGE', @@ -133,6 +145,7 @@ export const paramDef = { 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 }, + backgroundId: { type: 'string', format: 'misskey:id', nullable: true }, fields: { type: 'array', minItems: 0, @@ -300,6 +313,21 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint- updates.bannerBlurhash = null; } + if (ps.backgroundId) { + const background = await this.driveFilesRepository.findOneBy({ id: ps.backgroundId }); + + if (background == null || background.userId !== user.id) throw new ApiError(meta.errors.noSuchBackground); + if (!background.type.startsWith('image/')) throw new ApiError(meta.errors.backgroundNotAnImage); + + updates.backgroundId = background.id; + updates.backgroundUrl = this.driveFileEntityService.getPublicUrl(background); + updates.backgroundBlurhash = background.blurhash; + } else if (ps.backgroundId === null) { + updates.backgroundId = null; + updates.backgroundUrl = null; + updates.backgroundBlurhash = null; + } + if (ps.pinnedPageId) { const page = await this.pagesRepository.findOneBy({ id: ps.pinnedPageId }); |