aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/lazy-static.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-06-20 11:48:40 +0200
committerChocobozzz <me@florianbigard.com>2022-06-20 11:48:40 +0200
commit0f07c28951cf893e6313009d9517c3a5c6c84abd (patch)
treedfb8224a76adf86d3164bb2e28a8894a83971d1c /server/controllers/lazy-static.ts
parent73114c103aedc9ace4057d91957ff9f3fc60f83b (diff)
downloadPeerTube-0f07c28951cf893e6313009d9517c3a5c6c84abd.tar.gz
PeerTube-0f07c28951cf893e6313009d9517c3a5c6c84abd.tar.zst
PeerTube-0f07c28951cf893e6313009d9517c3a5c6c84abd.zip
Correctly handle unknown remote actor image size
Diffstat (limited to 'server/controllers/lazy-static.ts')
-rw-r--r--server/controllers/lazy-static.ts21
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 @@
1import cors from 'cors' 1import cors from 'cors'
2import express from 'express' 2import express from 'express'
3import { VideosTorrentCache } from '@server/lib/files-cache/videos-torrent-cache' 3import { VideosTorrentCache } from '@server/lib/files-cache/videos-torrent-cache'
4import { MActorImage } from '@server/types/models'
4import { HttpStatusCode } from '../../shared/models/http/http-error-codes' 5import { HttpStatusCode } from '../../shared/models/http/http-error-codes'
5import { logger } from '../helpers/logger' 6import { logger } from '../helpers/logger'
6import { LAZY_STATIC_PATHS, STATIC_MAX_AGE } from '../initializers/constants' 7import { ACTOR_IMAGES_SIZE, LAZY_STATIC_PATHS, STATIC_MAX_AGE } from '../initializers/constants'
7import { VideosCaptionCache, VideosPreviewCache } from '../lib/files-cache' 8import { VideosCaptionCache, VideosPreviewCache } from '../lib/files-cache'
8import { actorImagePathUnsafeCache, pushActorImageProcessInQueue } from '../lib/local-actor' 9import { actorImagePathUnsafeCache, pushActorImageProcessInQueue } from '../lib/local-actor'
9import { asyncMiddleware } from '../middlewares' 10import { 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
106function 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
108async function getPreview (req: express.Request, res: express.Response) { 117async 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()