mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-06 03:50:26 +02:00
Lazy load avatars
This commit is contained in:
parent
c5407d7046
commit
557b13ae24
18 changed files with 324 additions and 92 deletions
|
@ -9,7 +9,6 @@ import {
|
|||
STATIC_PATHS,
|
||||
WEBSERVER
|
||||
} from '../initializers/constants'
|
||||
import { VideosCaptionCache, VideosPreviewCache } from '../lib/files-cache'
|
||||
import { cacheRoute } from '../middlewares/cache'
|
||||
import { asyncMiddleware, videosGetValidator } from '../middlewares'
|
||||
import { VideoModel } from '../models/video/video'
|
||||
|
@ -19,6 +18,7 @@ import { HttpNodeinfoDiasporaSoftwareNsSchema20 } from '../../shared/models/node
|
|||
import { join } from 'path'
|
||||
import { root } from '../helpers/core-utils'
|
||||
import { CONFIG } from '../initializers/config'
|
||||
import { getPreview, getVideoCaption } from './lazy-static'
|
||||
|
||||
const staticRouter = express.Router()
|
||||
|
||||
|
@ -72,19 +72,20 @@ staticRouter.use(
|
|||
express.static(thumbnailsPhysicalPath, { maxAge: STATIC_MAX_AGE.SERVER, fallthrough: false }) // 404 if the file does not exist
|
||||
)
|
||||
|
||||
// DEPRECATED: use lazy-static route instead
|
||||
const avatarsPhysicalPath = CONFIG.STORAGE.AVATARS_DIR
|
||||
staticRouter.use(
|
||||
STATIC_PATHS.AVATARS,
|
||||
express.static(avatarsPhysicalPath, { maxAge: STATIC_MAX_AGE.SERVER, fallthrough: false }) // 404 if the file does not exist
|
||||
)
|
||||
|
||||
// We don't have video previews, fetch them from the origin instance
|
||||
// DEPRECATED: use lazy-static route instead
|
||||
staticRouter.use(
|
||||
STATIC_PATHS.PREVIEWS + ':uuid.jpg',
|
||||
asyncMiddleware(getPreview)
|
||||
)
|
||||
|
||||
// We don't have video captions, fetch them from the origin instance
|
||||
// DEPRECATED: use lazy-static route instead
|
||||
staticRouter.use(
|
||||
STATIC_PATHS.VIDEO_CAPTIONS + ':videoId-:captionLanguage([a-z]+).vtt',
|
||||
asyncMiddleware(getVideoCaption)
|
||||
|
@ -177,23 +178,6 @@ export {
|
|||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
async function getPreview (req: express.Request, res: express.Response) {
|
||||
const result = await VideosPreviewCache.Instance.getFilePath(req.params.uuid)
|
||||
if (!result) return res.sendStatus(404)
|
||||
|
||||
return res.sendFile(result.path, { maxAge: STATIC_MAX_AGE })
|
||||
}
|
||||
|
||||
async function getVideoCaption (req: express.Request, res: express.Response) {
|
||||
const result = await VideosCaptionCache.Instance.getFilePath({
|
||||
videoId: req.params.videoId,
|
||||
language: req.params.captionLanguage
|
||||
})
|
||||
if (!result) return res.sendStatus(404)
|
||||
|
||||
return res.sendFile(result.path, { maxAge: STATIC_MAX_AGE })
|
||||
}
|
||||
|
||||
async function generateNodeinfo (req: express.Request, res: express.Response) {
|
||||
const { totalVideos } = await VideoModel.getStats()
|
||||
const { totalLocalVideoComments } = await VideoCommentModel.getStats()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue