aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/local-actor.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/local-actor.ts')
-rw-r--r--server/lib/local-actor.ts35
1 files changed, 15 insertions, 20 deletions
diff --git a/server/lib/local-actor.ts b/server/lib/local-actor.ts
index 01046d017..e3b04c094 100644
--- a/server/lib/local-actor.ts
+++ b/server/lib/local-actor.ts
@@ -1,4 +1,3 @@
1import { queue } from 'async'
2import { remove } from 'fs-extra' 1import { remove } from 'fs-extra'
3import LRUCache from 'lru-cache' 2import LRUCache from 'lru-cache'
4import { join } from 'path' 3import { join } from 'path'
@@ -8,13 +7,13 @@ import { buildUUID } from '@shared/extra-utils'
8import { ActivityPubActorType, ActorImageType } from '@shared/models' 7import { ActivityPubActorType, ActorImageType } from '@shared/models'
9import { retryTransactionWrapper } from '../helpers/database-utils' 8import { retryTransactionWrapper } from '../helpers/database-utils'
10import { processImage } from '../helpers/image-utils' 9import { processImage } from '../helpers/image-utils'
11import { downloadImage } from '../helpers/requests'
12import { CONFIG } from '../initializers/config' 10import { CONFIG } from '../initializers/config'
13import { ACTOR_IMAGES_SIZE, LRU_CACHE, QUEUE_CONCURRENCY, WEBSERVER } from '../initializers/constants' 11import { ACTOR_IMAGES_SIZE, LRU_CACHE, WEBSERVER } from '../initializers/constants'
14import { sequelizeTypescript } from '../initializers/database' 12import { sequelizeTypescript } from '../initializers/database'
15import { MAccountDefault, MActor, MChannelDefault } from '../types/models' 13import { MAccountDefault, MActor, MChannelDefault } from '../types/models'
16import { deleteActorImages, updateActorImages } from './activitypub/actors' 14import { deleteActorImages, updateActorImages } from './activitypub/actors'
17import { sendUpdateActor } from './activitypub/send' 15import { sendUpdateActor } from './activitypub/send'
16import { downloadImageFromWorker } from './worker/parent-process'
18 17
19function buildActorInstance (type: ActivityPubActorType, url: string, preferredUsername: string) { 18function buildActorInstance (type: ActivityPubActorType, url: string, preferredUsername: string) {
20 return new ActorModel({ 19 return new ActorModel({
@@ -87,27 +86,22 @@ async function deleteLocalActorImageFile (accountOrChannel: MAccountDefault | MC
87 }) 86 })
88} 87}
89 88
90type DownloadImageQueueTask = { 89// ---------------------------------------------------------------------------
90
91function downloadActorImageFromWorker (options: {
91 fileUrl: string 92 fileUrl: string
92 filename: string 93 filename: string
93 type: ActorImageType 94 type: ActorImageType
94 size: typeof ACTOR_IMAGES_SIZE[ActorImageType][0] 95 size: typeof ACTOR_IMAGES_SIZE[ActorImageType][0]
95} 96}) {
96 97 const downloaderOptions = {
97const downloadImageQueue = queue<DownloadImageQueueTask, Error>((task, cb) => { 98 url: options.fileUrl,
98 downloadImage(task.fileUrl, CONFIG.STORAGE.ACTOR_IMAGES, task.filename, task.size) 99 destDir: CONFIG.STORAGE.ACTOR_IMAGES,
99 .then(() => cb()) 100 destName: options.filename,
100 .catch(err => cb(err)) 101 size: options.size
101}, QUEUE_CONCURRENCY.ACTOR_PROCESS_IMAGE) 102 }
102
103function pushActorImageProcessInQueue (task: DownloadImageQueueTask) {
104 return new Promise<void>((res, rej) => {
105 downloadImageQueue.push(task, err => {
106 if (err) return rej(err)
107 103
108 return res() 104 return downloadImageFromWorker(downloaderOptions)
109 })
110 })
111} 105}
112 106
113// Unsafe so could returns paths that does not exist anymore 107// Unsafe so could returns paths that does not exist anymore
@@ -116,7 +110,8 @@ const actorImagePathUnsafeCache = new LRUCache<string, string>({ max: LRU_CACHE.
116export { 110export {
117 actorImagePathUnsafeCache, 111 actorImagePathUnsafeCache,
118 updateLocalActorImageFiles, 112 updateLocalActorImageFiles,
113 downloadActorImageFromWorker,
119 deleteLocalActorImageFile, 114 deleteLocalActorImageFile,
120 pushActorImageProcessInQueue, 115 downloadImageFromWorker,
121 buildActorInstance 116 buildActorInstance
122} 117}