ニジカ投稿局 https://tv.nizika.tv
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

35 lines
1.1 KiB

  1. import express from 'express'
  2. import { CONFIG } from '@server/initializers/config.js'
  3. import { OpenTelemetryMetrics } from '@server/lib/opentelemetry/metrics.js'
  4. import { HttpStatusCode, PlaybackMetricCreate } from '@peertube/peertube-models'
  5. import { addPlaybackMetricValidator, apiRateLimiter, asyncMiddleware } from '../../middlewares/index.js'
  6. const metricsRouter = express.Router()
  7. metricsRouter.use(apiRateLimiter)
  8. metricsRouter.post('/playback',
  9. asyncMiddleware(addPlaybackMetricValidator),
  10. addPlaybackMetric
  11. )
  12. // ---------------------------------------------------------------------------
  13. export {
  14. metricsRouter
  15. }
  16. // ---------------------------------------------------------------------------
  17. function addPlaybackMetric (req: express.Request, res: express.Response) {
  18. if (!CONFIG.OPEN_TELEMETRY.METRICS.ENABLED) {
  19. return res.sendStatus(HttpStatusCode.FORBIDDEN_403)
  20. }
  21. const body: PlaybackMetricCreate = req.body
  22. OpenTelemetryMetrics.Instance.observePlaybackMetric(res.locals.onlyImmutableVideo, body)
  23. return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
  24. }