aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/avatar.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/avatar.ts')
-rw-r--r--server/lib/avatar.ts22
1 files changed, 19 insertions, 3 deletions
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 @@
1import 'multer' 1import 'multer'
2import { sendUpdateActor } from './activitypub/send' 2import { sendUpdateActor } from './activitypub/send'
3import { AVATARS_SIZE, LRU_CACHE, QUEUE_CONCURRENCY } from '../initializers/constants' 3import { AVATARS_SIZE, LRU_CACHE, QUEUE_CONCURRENCY } from '../initializers/constants'
4import { updateActorAvatarInstance } from './activitypub/actor' 4import { updateActorAvatarInstance, deleteActorAvatarInstance } from './activitypub/actor'
5import { processImage } from '../helpers/image-utils' 5import { processImage } from '../helpers/image-utils'
6import { extname, join } from 'path' 6import { extname, join } from 'path'
7import { retryTransactionWrapper } from '../helpers/database-utils' 7import { retryTransactionWrapper } from '../helpers/database-utils'
@@ -14,8 +14,8 @@ import { downloadImage } from '../helpers/requests'
14import { MAccountDefault, MChannelDefault } from '../types/models' 14import { MAccountDefault, MChannelDefault } from '../types/models'
15 15
16async function updateActorAvatarFile ( 16async 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
43async 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
43type DownloadImageQueueTask = { fileUrl: string, filename: string } 58type DownloadImageQueueTask = { fileUrl: string, filename: string }
44 59
45const downloadImageQueue = queue<DownloadImageQueueTask, Error>((task, cb) => { 60const downloadImageQueue = queue<DownloadImageQueueTask, Error>((task, cb) => {
@@ -64,5 +79,6 @@ const avatarPathUnsafeCache = new LRUCache<string, string>({ max: LRU_CACHE.AVAT
64export { 79export {
65 avatarPathUnsafeCache, 80 avatarPathUnsafeCache,
66 updateActorAvatarFile, 81 updateActorAvatarFile,
82 deleteActorAvatarFile,
67 pushAvatarProcessInQueue 83 pushAvatarProcessInQueue
68} 84}