diff options
-rw-r--r-- | server/controllers/lazy-static.ts | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/server/controllers/lazy-static.ts b/server/controllers/lazy-static.ts index 55bf02660..8a180b5bc 100644 --- a/server/controllers/lazy-static.ts +++ b/server/controllers/lazy-static.ts | |||
@@ -1,9 +1,10 @@ | |||
1 | import cors from 'cors' | 1 | import cors from 'cors' |
2 | import express from 'express' | 2 | import express from 'express' |
3 | import { VideosTorrentCache } from '@server/lib/files-cache/videos-torrent-cache' | 3 | import { VideosTorrentCache } from '@server/lib/files-cache/videos-torrent-cache' |
4 | import { MActorImage } from '@server/types/models' | ||
4 | import { HttpStatusCode } from '../../shared/models/http/http-error-codes' | 5 | import { HttpStatusCode } from '../../shared/models/http/http-error-codes' |
5 | import { logger } from '../helpers/logger' | 6 | import { logger } from '../helpers/logger' |
6 | import { LAZY_STATIC_PATHS, STATIC_MAX_AGE } from '../initializers/constants' | 7 | import { ACTOR_IMAGES_SIZE, LAZY_STATIC_PATHS, STATIC_MAX_AGE } from '../initializers/constants' |
7 | import { VideosCaptionCache, VideosPreviewCache } from '../lib/files-cache' | 8 | import { VideosCaptionCache, VideosPreviewCache } from '../lib/files-cache' |
8 | import { actorImagePathUnsafeCache, pushActorImageProcessInQueue } from '../lib/local-actor' | 9 | import { actorImagePathUnsafeCache, pushActorImageProcessInQueue } from '../lib/local-actor' |
9 | import { asyncMiddleware } from '../middlewares' | 10 | import { asyncMiddleware } from '../middlewares' |
@@ -67,10 +68,7 @@ async function getActorImage (req: express.Request, res: express.Response, next: | |||
67 | await pushActorImageProcessInQueue({ | 68 | await pushActorImageProcessInQueue({ |
68 | filename: image.filename, | 69 | filename: image.filename, |
69 | fileUrl: image.fileUrl, | 70 | fileUrl: image.fileUrl, |
70 | size: { | 71 | size: getActorImageSize(image), |
71 | height: image.height, | ||
72 | width: image.width | ||
73 | }, | ||
74 | type: image.type | 72 | type: image.type |
75 | }) | 73 | }) |
76 | } catch (err) { | 74 | } catch (err) { |
@@ -94,7 +92,7 @@ async function getActorImage (req: express.Request, res: express.Response, next: | |||
94 | if (err.status === HttpStatusCode.NOT_FOUND_404 && !image.isOwned()) { | 92 | if (err.status === HttpStatusCode.NOT_FOUND_404 && !image.isOwned()) { |
95 | logger.error('Cannot lazy serve actor image %s.', filename, { err }) | 93 | logger.error('Cannot lazy serve actor image %s.', filename, { err }) |
96 | 94 | ||
97 | actorImagePathUnsafeCache.del(filename) | 95 | actorImagePathUnsafeCache.delete(filename) |
98 | 96 | ||
99 | image.onDisk = false | 97 | image.onDisk = false |
100 | image.save() | 98 | image.save() |
@@ -105,6 +103,17 @@ async function getActorImage (req: express.Request, res: express.Response, next: | |||
105 | }) | 103 | }) |
106 | } | 104 | } |
107 | 105 | ||
106 | function getActorImageSize (image: MActorImage): { width: number, height: number } { | ||
107 | if (image.width && image.height) { | ||
108 | return { | ||
109 | height: image.height, | ||
110 | width: image.width | ||
111 | } | ||
112 | } | ||
113 | |||
114 | return ACTOR_IMAGES_SIZE[image.type][0] | ||
115 | } | ||
116 | |||
108 | async function getPreview (req: express.Request, res: express.Response) { | 117 | async function getPreview (req: express.Request, res: express.Response) { |
109 | const result = await VideosPreviewCache.Instance.getFilePath(req.params.filename) | 118 | const result = await VideosPreviewCache.Instance.getFilePath(req.params.filename) |
110 | if (!result) return res.status(HttpStatusCode.NOT_FOUND_404).end() | 119 | if (!result) return res.status(HttpStatusCode.NOT_FOUND_404).end() |