diff options
author | Chocobozzz <me@florianbigard.com> | 2021-04-06 11:35:56 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2021-04-08 10:07:53 +0200 |
commit | f479685678406a5df864d89615b33d29085ebfc6 (patch) | |
tree | 8de15e90cd8d97d8810715df8585c61f48d5282a /server/lib | |
parent | 968aaed2066873fc1c39f95168284122d9d15e21 (diff) | |
download | PeerTube-f479685678406a5df864d89615b33d29085ebfc6.tar.gz PeerTube-f479685678406a5df864d89615b33d29085ebfc6.tar.zst PeerTube-f479685678406a5df864d89615b33d29085ebfc6.zip |
Agnostic actor image storage
Diffstat (limited to 'server/lib')
-rw-r--r-- | server/lib/activitypub/actor.ts | 6 | ||||
-rw-r--r-- | server/lib/actor-image.ts (renamed from server/lib/avatar.ts) | 30 |
2 files changed, 18 insertions, 18 deletions
diff --git a/server/lib/activitypub/actor.ts b/server/lib/activitypub/actor.ts index 3c9a7ba02..da831dcfd 100644 --- a/server/lib/activitypub/actor.ts +++ b/server/lib/activitypub/actor.ts | |||
@@ -19,8 +19,8 @@ import { getUrlFromWebfinger } from '../../helpers/webfinger' | |||
19 | import { MIMETYPES, WEBSERVER } from '../../initializers/constants' | 19 | import { MIMETYPES, WEBSERVER } from '../../initializers/constants' |
20 | import { sequelizeTypescript } from '../../initializers/database' | 20 | import { sequelizeTypescript } from '../../initializers/database' |
21 | import { AccountModel } from '../../models/account/account' | 21 | import { AccountModel } from '../../models/account/account' |
22 | import { ActorImageModel } from '../../models/account/actor-image' | ||
22 | import { ActorModel } from '../../models/activitypub/actor' | 23 | import { ActorModel } from '../../models/activitypub/actor' |
23 | import { AvatarModel } from '../../models/avatar/avatar' | ||
24 | import { ServerModel } from '../../models/server/server' | 24 | import { ServerModel } from '../../models/server/server' |
25 | import { VideoChannelModel } from '../../models/video/video-channel' | 25 | import { VideoChannelModel } from '../../models/video/video-channel' |
26 | import { | 26 | import { |
@@ -183,7 +183,7 @@ async function updateActorAvatarInstance (actor: MActorDefault, info: AvatarInfo | |||
183 | } | 183 | } |
184 | } | 184 | } |
185 | 185 | ||
186 | const avatar = await AvatarModel.create({ | 186 | const avatar = await ActorImageModel.create({ |
187 | filename: info.name, | 187 | filename: info.name, |
188 | onDisk: info.onDisk, | 188 | onDisk: info.onDisk, |
189 | fileUrl: info.fileUrl | 189 | fileUrl: info.fileUrl |
@@ -378,7 +378,7 @@ function saveActorAndServerAndModelIfNotExist ( | |||
378 | 378 | ||
379 | // Avatar? | 379 | // Avatar? |
380 | if (result.avatar) { | 380 | if (result.avatar) { |
381 | const avatar = await AvatarModel.create({ | 381 | const avatar = await ActorImageModel.create({ |
382 | filename: result.avatar.name, | 382 | filename: result.avatar.name, |
383 | fileUrl: result.avatar.fileUrl, | 383 | fileUrl: result.avatar.fileUrl, |
384 | onDisk: false | 384 | onDisk: false |
diff --git a/server/lib/avatar.ts b/server/lib/actor-image.ts index 86f1e7bdb..ca7f9658d 100644 --- a/server/lib/avatar.ts +++ b/server/lib/actor-image.ts | |||
@@ -1,17 +1,17 @@ | |||
1 | import 'multer' | 1 | import 'multer' |
2 | import { sendUpdateActor } from './activitypub/send' | 2 | import { queue } from 'async' |
3 | import { AVATARS_SIZE, LRU_CACHE, QUEUE_CONCURRENCY } from '../initializers/constants' | 3 | import * as LRUCache from 'lru-cache' |
4 | import { updateActorAvatarInstance, deleteActorAvatarInstance } from './activitypub/actor' | ||
5 | import { processImage } from '../helpers/image-utils' | ||
6 | import { extname, join } from 'path' | 4 | import { extname, join } from 'path' |
7 | import { retryTransactionWrapper } from '../helpers/database-utils' | ||
8 | import { v4 as uuidv4 } from 'uuid' | 5 | import { v4 as uuidv4 } from 'uuid' |
6 | import { retryTransactionWrapper } from '../helpers/database-utils' | ||
7 | import { processImage } from '../helpers/image-utils' | ||
8 | import { downloadImage } from '../helpers/requests' | ||
9 | import { CONFIG } from '../initializers/config' | 9 | import { CONFIG } from '../initializers/config' |
10 | import { AVATARS_SIZE, LRU_CACHE, QUEUE_CONCURRENCY } from '../initializers/constants' | ||
10 | import { sequelizeTypescript } from '../initializers/database' | 11 | import { sequelizeTypescript } from '../initializers/database' |
11 | import * as LRUCache from 'lru-cache' | ||
12 | import { queue } from 'async' | ||
13 | import { downloadImage } from '../helpers/requests' | ||
14 | import { MAccountDefault, MChannelDefault } from '../types/models' | 12 | import { MAccountDefault, MChannelDefault } from '../types/models' |
13 | import { deleteActorAvatarInstance, updateActorAvatarInstance } from './activitypub/actor' | ||
14 | import { sendUpdateActor } from './activitypub/send' | ||
15 | 15 | ||
16 | async function updateLocalActorAvatarFile ( | 16 | async function updateLocalActorAvatarFile ( |
17 | accountOrChannel: MAccountDefault | MChannelDefault, | 17 | accountOrChannel: MAccountDefault | MChannelDefault, |
@@ -20,7 +20,7 @@ async function updateLocalActorAvatarFile ( | |||
20 | const extension = extname(avatarPhysicalFile.filename) | 20 | const extension = extname(avatarPhysicalFile.filename) |
21 | 21 | ||
22 | const avatarName = uuidv4() + extension | 22 | const avatarName = uuidv4() + extension |
23 | const destination = join(CONFIG.STORAGE.AVATARS_DIR, avatarName) | 23 | const destination = join(CONFIG.STORAGE.ACTOR_IMAGES, avatarName) |
24 | await processImage(avatarPhysicalFile.path, destination, AVATARS_SIZE) | 24 | await processImage(avatarPhysicalFile.path, destination, AVATARS_SIZE) |
25 | 25 | ||
26 | return retryTransactionWrapper(() => { | 26 | return retryTransactionWrapper(() => { |
@@ -59,12 +59,12 @@ async function deleteLocalActorAvatarFile ( | |||
59 | type DownloadImageQueueTask = { fileUrl: string, filename: string } | 59 | type DownloadImageQueueTask = { fileUrl: string, filename: string } |
60 | 60 | ||
61 | const downloadImageQueue = queue<DownloadImageQueueTask, Error>((task, cb) => { | 61 | const downloadImageQueue = queue<DownloadImageQueueTask, Error>((task, cb) => { |
62 | downloadImage(task.fileUrl, CONFIG.STORAGE.AVATARS_DIR, task.filename, AVATARS_SIZE) | 62 | downloadImage(task.fileUrl, CONFIG.STORAGE.ACTOR_IMAGES, task.filename, AVATARS_SIZE) |
63 | .then(() => cb()) | 63 | .then(() => cb()) |
64 | .catch(err => cb(err)) | 64 | .catch(err => cb(err)) |
65 | }, QUEUE_CONCURRENCY.AVATAR_PROCESS_IMAGE) | 65 | }, QUEUE_CONCURRENCY.ACTOR_PROCESS_IMAGE) |
66 | 66 | ||
67 | function pushAvatarProcessInQueue (task: DownloadImageQueueTask) { | 67 | function pushActorImageProcessInQueue (task: DownloadImageQueueTask) { |
68 | return new Promise<void>((res, rej) => { | 68 | return new Promise<void>((res, rej) => { |
69 | downloadImageQueue.push(task, err => { | 69 | downloadImageQueue.push(task, err => { |
70 | if (err) return rej(err) | 70 | if (err) return rej(err) |
@@ -75,11 +75,11 @@ function pushAvatarProcessInQueue (task: DownloadImageQueueTask) { | |||
75 | } | 75 | } |
76 | 76 | ||
77 | // Unsafe so could returns paths that does not exist anymore | 77 | // Unsafe so could returns paths that does not exist anymore |
78 | const avatarPathUnsafeCache = new LRUCache<string, string>({ max: LRU_CACHE.AVATAR_STATIC.MAX_SIZE }) | 78 | const actorImagePathUnsafeCache = new LRUCache<string, string>({ max: LRU_CACHE.ACTOR_IMAGE_STATIC.MAX_SIZE }) |
79 | 79 | ||
80 | export { | 80 | export { |
81 | avatarPathUnsafeCache, | 81 | actorImagePathUnsafeCache, |
82 | updateLocalActorAvatarFile, | 82 | updateLocalActorAvatarFile, |
83 | deleteLocalActorAvatarFile, | 83 | deleteLocalActorAvatarFile, |
84 | pushAvatarProcessInQueue | 84 | pushActorImageProcessInQueue |
85 | } | 85 | } |