diff options
Diffstat (limited to 'server/lib')
-rw-r--r-- | server/lib/activitypub/actor.ts | 14 | ||||
-rw-r--r-- | server/lib/avatar.ts | 22 |
2 files changed, 33 insertions, 3 deletions
diff --git a/server/lib/activitypub/actor.ts b/server/lib/activitypub/actor.ts index 52547536c..086d656f9 100644 --- a/server/lib/activitypub/actor.ts +++ b/server/lib/activitypub/actor.ts | |||
@@ -199,6 +199,19 @@ async function updateActorAvatarInstance (actor: MActorDefault, info: AvatarInfo | |||
199 | return actor | 199 | return actor |
200 | } | 200 | } |
201 | 201 | ||
202 | async function deleteActorAvatarInstance (actor: MActorDefault, t: Transaction) { | ||
203 | try { | ||
204 | await actor.Avatar.destroy({ transaction: t }) | ||
205 | } catch (err) { | ||
206 | logger.error('Cannot remove old avatar of actor %s.', actor.url, { err }) | ||
207 | } | ||
208 | |||
209 | actor.avatarId = null | ||
210 | actor.Avatar = null | ||
211 | |||
212 | return actor | ||
213 | } | ||
214 | |||
202 | async function fetchActorTotalItems (url: string) { | 215 | async function fetchActorTotalItems (url: string) { |
203 | const options = { | 216 | const options = { |
204 | uri: url, | 217 | uri: url, |
@@ -337,6 +350,7 @@ export { | |||
337 | fetchActorTotalItems, | 350 | fetchActorTotalItems, |
338 | getAvatarInfoIfExists, | 351 | getAvatarInfoIfExists, |
339 | updateActorInstance, | 352 | updateActorInstance, |
353 | deleteActorAvatarInstance, | ||
340 | refreshActorIfNeeded, | 354 | refreshActorIfNeeded, |
341 | updateActorAvatarInstance, | 355 | updateActorAvatarInstance, |
342 | addFetchOutboxJob | 356 | addFetchOutboxJob |
diff --git a/server/lib/avatar.ts b/server/lib/avatar.ts index be6657b6f..9d59a4966 100644 --- a/server/lib/avatar.ts +++ b/server/lib/avatar.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import 'multer' | 1 | import 'multer' |
2 | import { sendUpdateActor } from './activitypub/send' | 2 | import { sendUpdateActor } from './activitypub/send' |
3 | import { AVATARS_SIZE, LRU_CACHE, QUEUE_CONCURRENCY } from '../initializers/constants' | 3 | import { AVATARS_SIZE, LRU_CACHE, QUEUE_CONCURRENCY } from '../initializers/constants' |
4 | import { updateActorAvatarInstance } from './activitypub/actor' | 4 | import { updateActorAvatarInstance, deleteActorAvatarInstance } from './activitypub/actor' |
5 | import { processImage } from '../helpers/image-utils' | 5 | import { processImage } from '../helpers/image-utils' |
6 | import { extname, join } from 'path' | 6 | import { extname, join } from 'path' |
7 | import { retryTransactionWrapper } from '../helpers/database-utils' | 7 | import { retryTransactionWrapper } from '../helpers/database-utils' |
@@ -14,8 +14,8 @@ import { downloadImage } from '../helpers/requests' | |||
14 | import { MAccountDefault, MChannelDefault } from '../types/models' | 14 | import { MAccountDefault, MChannelDefault } from '../types/models' |
15 | 15 | ||
16 | async function updateActorAvatarFile ( | 16 | async function updateActorAvatarFile ( |
17 | avatarPhysicalFile: Express.Multer.File, | 17 | accountOrChannel: MAccountDefault | MChannelDefault, |
18 | accountOrChannel: MAccountDefault | MChannelDefault | 18 | avatarPhysicalFile: Express.Multer.File |
19 | ) { | 19 | ) { |
20 | const extension = extname(avatarPhysicalFile.filename) | 20 | const extension = extname(avatarPhysicalFile.filename) |
21 | const avatarName = uuidv4() + extension | 21 | const avatarName = uuidv4() + extension |
@@ -40,6 +40,21 @@ async function updateActorAvatarFile ( | |||
40 | }) | 40 | }) |
41 | } | 41 | } |
42 | 42 | ||
43 | async function deleteActorAvatarFile ( | ||
44 | accountOrChannel: MAccountDefault | MChannelDefault | ||
45 | ) { | ||
46 | return retryTransactionWrapper(() => { | ||
47 | return sequelizeTypescript.transaction(async t => { | ||
48 | const updatedActor = await deleteActorAvatarInstance(accountOrChannel.Actor, t) | ||
49 | await updatedActor.save({ transaction: t }) | ||
50 | |||
51 | await sendUpdateActor(accountOrChannel, t) | ||
52 | |||
53 | return updatedActor.Avatar | ||
54 | }) | ||
55 | }) | ||
56 | } | ||
57 | |||
43 | type DownloadImageQueueTask = { fileUrl: string, filename: string } | 58 | type DownloadImageQueueTask = { fileUrl: string, filename: string } |
44 | 59 | ||
45 | const downloadImageQueue = queue<DownloadImageQueueTask, Error>((task, cb) => { | 60 | const downloadImageQueue = queue<DownloadImageQueueTask, Error>((task, cb) => { |
@@ -64,5 +79,6 @@ const avatarPathUnsafeCache = new LRUCache<string, string>({ max: LRU_CACHE.AVAT | |||
64 | export { | 79 | export { |
65 | avatarPathUnsafeCache, | 80 | avatarPathUnsafeCache, |
66 | updateActorAvatarFile, | 81 | updateActorAvatarFile, |
82 | deleteActorAvatarFile, | ||
67 | pushAvatarProcessInQueue | 83 | pushAvatarProcessInQueue |
68 | } | 84 | } |