import { ACTOR_IMAGES_SIZE, LAZY_STATIC_PATHS, STATIC_MAX_AGE } from '../initializers/constants'
import { VideosCaptionCache, VideosPreviewCache } from '../lib/files-cache'
import { actorImagePathUnsafeCache, downloadActorImageFromWorker } from '../lib/local-actor'
-import { asyncMiddleware } from '../middlewares'
+import { asyncMiddleware, handleStaticError } from '../middlewares'
import { ActorImageModel } from '../models/actor/actor-image'
const lazyStaticRouter = express.Router()
lazyStaticRouter.use(
LAZY_STATIC_PATHS.AVATARS + ':filename',
- asyncMiddleware(getActorImage)
+ asyncMiddleware(getActorImage),
+ handleStaticError
)
lazyStaticRouter.use(
LAZY_STATIC_PATHS.BANNERS + ':filename',
- asyncMiddleware(getActorImage)
+ asyncMiddleware(getActorImage),
+ handleStaticError
)
lazyStaticRouter.use(
LAZY_STATIC_PATHS.PREVIEWS + ':filename',
- asyncMiddleware(getPreview)
+ asyncMiddleware(getPreview),
+ handleStaticError
)
lazyStaticRouter.use(
LAZY_STATIC_PATHS.VIDEO_CAPTIONS + ':filename',
- asyncMiddleware(getVideoCaption)
+ asyncMiddleware(getVideoCaption),
+ handleStaticError
)
lazyStaticRouter.use(
LAZY_STATIC_PATHS.TORRENTS + ':filename',
- asyncMiddleware(getTorrent)
+ asyncMiddleware(getTorrent),
+ handleStaticError
)
// ---------------------------------------------------------------------------
-import { HttpStatusCode } from '@shared/models'
import cors from 'cors'
import express from 'express'
+import { handleStaticError } from '@server/middlewares'
import { CONFIG } from '../initializers/config'
import { HLS_STREAMING_PLAYLIST_DIRECTORY, STATIC_MAX_AGE, STATIC_PATHS } from '../initializers/constants'
export {
staticRouter
}
-
-// ---------------------------------------------------------------------------
-
-function handleStaticError (err: any, req: express.Request, res: express.Response, next: express.NextFunction) {
- const message = err.message || ''
-
- if (message.includes('ENOENT')) {
- return res.fail({
- status: err.status || HttpStatusCode.INTERNAL_SERVER_ERROR_500,
- message: err.message,
- type: err.name
- })
- }
-
- return next(err)
-}
if (next) next()
}
+function handleStaticError (err: any, req: express.Request, res: express.Response, next: express.NextFunction) {
+ const message = err.message || ''
+
+ if (message.includes('ENOENT')) {
+ return res.fail({
+ status: err.status || HttpStatusCode.INTERNAL_SERVER_ERROR_500,
+ message: err.message,
+ type: err.name
+ })
+ }
+
+ return next(err)
+}
+
export {
- apiFailMiddleware
+ apiFailMiddleware,
+ handleStaticError
}