diff options
author | Rigel Kent <sendmemail@rigelk.eu> | 2021-01-13 09:12:55 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-13 09:12:55 +0100 |
commit | 1ea7da819e5bfae7b443ed722c18c4165d101439 (patch) | |
tree | 17cea3786dfb3a59a2ad5559de9ebf106a0440a2 /server/controllers | |
parent | 75dd1b641f987e1e09dbaa3329e08c6e98a858f3 (diff) | |
download | PeerTube-1ea7da819e5bfae7b443ed722c18c4165d101439.tar.gz PeerTube-1ea7da819e5bfae7b443ed722c18c4165d101439.tar.zst PeerTube-1ea7da819e5bfae7b443ed722c18c4165d101439.zip |
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
Diffstat (limited to 'server/controllers')
-rw-r--r-- | server/controllers/api/users/me.ts | 18 | ||||
-rw-r--r-- | server/controllers/api/video-channel.ts | 19 |
2 files changed, 33 insertions, 4 deletions
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' | |||
10 | import { MIMETYPES } from '../../../initializers/constants' | 10 | import { MIMETYPES } from '../../../initializers/constants' |
11 | import { sequelizeTypescript } from '../../../initializers/database' | 11 | import { sequelizeTypescript } from '../../../initializers/database' |
12 | import { sendUpdateActor } from '../../../lib/activitypub/send' | 12 | import { sendUpdateActor } from '../../../lib/activitypub/send' |
13 | import { updateActorAvatarFile } from '../../../lib/avatar' | 13 | import { deleteActorAvatarFile, updateActorAvatarFile } from '../../../lib/avatar' |
14 | import { getOriginalVideoFileTotalDailyFromUser, getOriginalVideoFileTotalFromUser, sendVerifyUserEmail } from '../../../lib/user' | 14 | import { getOriginalVideoFileTotalDailyFromUser, getOriginalVideoFileTotalFromUser, sendVerifyUserEmail } from '../../../lib/user' |
15 | import { | 15 | import { |
16 | asyncMiddleware, | 16 | asyncMiddleware, |
@@ -89,6 +89,11 @@ meRouter.post('/me/avatar/pick', | |||
89 | asyncRetryTransactionMiddleware(updateMyAvatar) | 89 | asyncRetryTransactionMiddleware(updateMyAvatar) |
90 | ) | 90 | ) |
91 | 91 | ||
92 | meRouter.delete('/me/avatar', | ||
93 | authenticate, | ||
94 | asyncRetryTransactionMiddleware(deleteMyAvatar) | ||
95 | ) | ||
96 | |||
92 | // --------------------------------------------------------------------------- | 97 | // --------------------------------------------------------------------------- |
93 | 98 | ||
94 | export { | 99 | export { |
@@ -225,7 +230,16 @@ async function updateMyAvatar (req: express.Request, res: express.Response) { | |||
225 | 230 | ||
226 | const userAccount = await AccountModel.load(user.Account.id) | 231 | const userAccount = await AccountModel.load(user.Account.id) |
227 | 232 | ||
228 | const avatar = await updateActorAvatarFile(avatarPhysicalFile, userAccount) | 233 | const avatar = await updateActorAvatarFile(userAccount, avatarPhysicalFile) |
229 | 234 | ||
230 | return res.json({ avatar: avatar.toFormattedJSON() }) | 235 | return res.json({ avatar: avatar.toFormattedJSON() }) |
231 | } | 236 | } |
237 | |||
238 | async function deleteMyAvatar (req: express.Request, res: express.Response) { | ||
239 | const user = res.locals.oauth.token.user | ||
240 | |||
241 | const userAccount = await AccountModel.load(user.Account.id) | ||
242 | await deleteActorAvatarFile(userAccount) | ||
243 | |||
244 | return res.sendStatus(HttpStatusCode.NO_CONTENT_204) | ||
245 | } | ||
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' | |||
13 | import { sequelizeTypescript } from '../../initializers/database' | 13 | import { sequelizeTypescript } from '../../initializers/database' |
14 | import { setAsyncActorKeys } from '../../lib/activitypub/actor' | 14 | import { setAsyncActorKeys } from '../../lib/activitypub/actor' |
15 | import { sendUpdateActor } from '../../lib/activitypub/send' | 15 | import { sendUpdateActor } from '../../lib/activitypub/send' |
16 | import { updateActorAvatarFile } from '../../lib/avatar' | 16 | import { deleteActorAvatarFile, updateActorAvatarFile } from '../../lib/avatar' |
17 | import { JobQueue } from '../../lib/job-queue' | 17 | import { JobQueue } from '../../lib/job-queue' |
18 | import { createLocalVideoChannel, federateAllVideosOfChannel } from '../../lib/video-channel' | 18 | import { createLocalVideoChannel, federateAllVideosOfChannel } from '../../lib/video-channel' |
19 | import { | 19 | import { |
@@ -70,6 +70,13 @@ videoChannelRouter.post('/:nameWithHost/avatar/pick', | |||
70 | asyncMiddleware(updateVideoChannelAvatar) | 70 | asyncMiddleware(updateVideoChannelAvatar) |
71 | ) | 71 | ) |
72 | 72 | ||
73 | videoChannelRouter.delete('/:nameWithHost/avatar', | ||
74 | authenticate, | ||
75 | // Check the rights | ||
76 | asyncMiddleware(videoChannelsUpdateValidator), | ||
77 | asyncMiddleware(deleteVideoChannelAvatar) | ||
78 | ) | ||
79 | |||
73 | videoChannelRouter.put('/:nameWithHost', | 80 | videoChannelRouter.put('/:nameWithHost', |
74 | authenticate, | 81 | authenticate, |
75 | asyncMiddleware(videoChannelsUpdateValidator), | 82 | asyncMiddleware(videoChannelsUpdateValidator), |
@@ -133,7 +140,7 @@ async function updateVideoChannelAvatar (req: express.Request, res: express.Resp | |||
133 | const videoChannel = res.locals.videoChannel | 140 | const videoChannel = res.locals.videoChannel |
134 | const oldVideoChannelAuditKeys = new VideoChannelAuditView(videoChannel.toFormattedJSON()) | 141 | const oldVideoChannelAuditKeys = new VideoChannelAuditView(videoChannel.toFormattedJSON()) |
135 | 142 | ||
136 | const avatar = await updateActorAvatarFile(avatarPhysicalFile, videoChannel) | 143 | const avatar = await updateActorAvatarFile(videoChannel, avatarPhysicalFile) |
137 | 144 | ||
138 | auditLogger.update(getAuditIdFromRes(res), new VideoChannelAuditView(videoChannel.toFormattedJSON()), oldVideoChannelAuditKeys) | 145 | auditLogger.update(getAuditIdFromRes(res), new VideoChannelAuditView(videoChannel.toFormattedJSON()), oldVideoChannelAuditKeys) |
139 | 146 | ||
@@ -144,6 +151,14 @@ async function updateVideoChannelAvatar (req: express.Request, res: express.Resp | |||
144 | .end() | 151 | .end() |
145 | } | 152 | } |
146 | 153 | ||
154 | async function deleteVideoChannelAvatar (req: express.Request, res: express.Response) { | ||
155 | const videoChannel = res.locals.videoChannel | ||
156 | |||
157 | await deleteActorAvatarFile(videoChannel) | ||
158 | |||
159 | return res.sendStatus(HttpStatusCode.NO_CONTENT_204) | ||
160 | } | ||
161 | |||
147 | async function addVideoChannel (req: express.Request, res: express.Response) { | 162 | async function addVideoChannel (req: express.Request, res: express.Response) { |
148 | const videoChannelInfo: VideoChannelCreate = req.body | 163 | const videoChannelInfo: VideoChannelCreate = req.body |
149 | 164 | ||