From 1ea7da819e5bfae7b443ed722c18c4165d101439 Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Wed, 13 Jan 2021 09:12:55 +0100 Subject: add ability to remove one's avatar for account and channels (#3467) * add ability to remove one's avatar for account and channels * add ability to remove one's avatar for account and channels * only display avatar edition options after input change --- server/controllers/api/users/me.ts | 18 ++++++++++++++++-- server/controllers/api/video-channel.ts | 19 +++++++++++++++++-- 2 files changed, 33 insertions(+), 4 deletions(-) (limited to 'server/controllers') diff --git a/server/controllers/api/users/me.ts b/server/controllers/api/users/me.ts index 7ab089713..009cf42b7 100644 --- a/server/controllers/api/users/me.ts +++ b/server/controllers/api/users/me.ts @@ -10,7 +10,7 @@ import { CONFIG } from '../../../initializers/config' import { MIMETYPES } from '../../../initializers/constants' import { sequelizeTypescript } from '../../../initializers/database' import { sendUpdateActor } from '../../../lib/activitypub/send' -import { updateActorAvatarFile } from '../../../lib/avatar' +import { deleteActorAvatarFile, updateActorAvatarFile } from '../../../lib/avatar' import { getOriginalVideoFileTotalDailyFromUser, getOriginalVideoFileTotalFromUser, sendVerifyUserEmail } from '../../../lib/user' import { asyncMiddleware, @@ -89,6 +89,11 @@ meRouter.post('/me/avatar/pick', asyncRetryTransactionMiddleware(updateMyAvatar) ) +meRouter.delete('/me/avatar', + authenticate, + asyncRetryTransactionMiddleware(deleteMyAvatar) +) + // --------------------------------------------------------------------------- export { @@ -225,7 +230,16 @@ async function updateMyAvatar (req: express.Request, res: express.Response) { const userAccount = await AccountModel.load(user.Account.id) - const avatar = await updateActorAvatarFile(avatarPhysicalFile, userAccount) + const avatar = await updateActorAvatarFile(userAccount, avatarPhysicalFile) return res.json({ avatar: avatar.toFormattedJSON() }) } + +async function deleteMyAvatar (req: express.Request, res: express.Response) { + const user = res.locals.oauth.token.user + + const userAccount = await AccountModel.load(user.Account.id) + await deleteActorAvatarFile(userAccount) + + return res.sendStatus(HttpStatusCode.NO_CONTENT_204) +} diff --git a/server/controllers/api/video-channel.ts b/server/controllers/api/video-channel.ts index c48e00232..7ac01b0ef 100644 --- a/server/controllers/api/video-channel.ts +++ b/server/controllers/api/video-channel.ts @@ -13,7 +13,7 @@ import { MIMETYPES } from '../../initializers/constants' import { sequelizeTypescript } from '../../initializers/database' import { setAsyncActorKeys } from '../../lib/activitypub/actor' import { sendUpdateActor } from '../../lib/activitypub/send' -import { updateActorAvatarFile } from '../../lib/avatar' +import { deleteActorAvatarFile, updateActorAvatarFile } from '../../lib/avatar' import { JobQueue } from '../../lib/job-queue' import { createLocalVideoChannel, federateAllVideosOfChannel } from '../../lib/video-channel' import { @@ -70,6 +70,13 @@ videoChannelRouter.post('/:nameWithHost/avatar/pick', asyncMiddleware(updateVideoChannelAvatar) ) +videoChannelRouter.delete('/:nameWithHost/avatar', + authenticate, + // Check the rights + asyncMiddleware(videoChannelsUpdateValidator), + asyncMiddleware(deleteVideoChannelAvatar) +) + videoChannelRouter.put('/:nameWithHost', authenticate, asyncMiddleware(videoChannelsUpdateValidator), @@ -133,7 +140,7 @@ async function updateVideoChannelAvatar (req: express.Request, res: express.Resp const videoChannel = res.locals.videoChannel const oldVideoChannelAuditKeys = new VideoChannelAuditView(videoChannel.toFormattedJSON()) - const avatar = await updateActorAvatarFile(avatarPhysicalFile, videoChannel) + const avatar = await updateActorAvatarFile(videoChannel, avatarPhysicalFile) auditLogger.update(getAuditIdFromRes(res), new VideoChannelAuditView(videoChannel.toFormattedJSON()), oldVideoChannelAuditKeys) @@ -144,6 +151,14 @@ async function updateVideoChannelAvatar (req: express.Request, res: express.Resp .end() } +async function deleteVideoChannelAvatar (req: express.Request, res: express.Response) { + const videoChannel = res.locals.videoChannel + + await deleteActorAvatarFile(videoChannel) + + return res.sendStatus(HttpStatusCode.NO_CONTENT_204) +} + async function addVideoChannel (req: express.Request, res: express.Response) { const videoChannelInfo: VideoChannelCreate = req.body -- cgit v1.2.3