X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fcontrollers%2Fapi%2Fvideos%2Findex.ts;h=7671f099ebaf1a99a1dc026dea80d0fee13be8b0;hb=b96d21b744f3b0714636bd43e7f39fb33c3adb73;hp=6483d2e8a1bd94a2f94b37e3ee20317735bd94d4;hpb=1c5e49e75284100b7b1fc8b4e73c8ba53fe22e89;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index 6483d2e8a..7671f099e 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts @@ -1,17 +1,19 @@ import * as express from 'express' import toInt from 'validator/lib/toInt' +import { doJSONRequest } from '@server/helpers/requests' import { LiveManager } from '@server/lib/live-manager' +import { docMiddleware } from '@server/middlewares/doc' import { getServerActor } from '@server/models/application/application' +import { MVideoAccountLight } from '@server/types/models' import { VideosCommonQuery } from '../../../../shared' import { HttpStatusCode } from '../../../../shared/core-utils/miscs' import { auditLoggerFactory, getAuditIdFromRes, VideoAuditView } from '../../../helpers/audit-logger' import { buildNSFWFilter, getCountVideos } from '../../../helpers/express-utils' import { logger } from '../../../helpers/logger' import { getFormattedObjects } from '../../../helpers/utils' -import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../initializers/constants' +import { REMOTE_SCHEME, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../initializers/constants' import { sequelizeTypescript } from '../../../initializers/database' import { sendView } from '../../../lib/activitypub/send/send-view' -import { fetchRemoteVideoDescription } from '../../../lib/activitypub/videos' import { JobQueue } from '../../../lib/job-queue' import { Hooks } from '../../../lib/plugins/hooks' import { Redis } from '../../../lib/redis' @@ -82,6 +84,7 @@ videosRouter.get('/:id/metadata/:videoFileId', asyncMiddleware(getVideoFileMetadata) ) videosRouter.get('/:id', + docMiddleware('https://docs.joinpeertube.org/api-rest-reference.html#operation/getVideo'), optionalAuthenticate, asyncMiddleware(videosCustomGetValidator('only-video-with-rights')), asyncMiddleware(checkVideoFollowConstraints), @@ -93,6 +96,7 @@ videosRouter.post('/:id/views', ) videosRouter.delete('/:id', + docMiddleware('https://docs.joinpeertube.org/api-rest-reference.html#operation/delVideo'), authenticate, asyncMiddleware(videosRemoveValidator), asyncRetryTransactionMiddleware(removeVideo) @@ -146,7 +150,7 @@ async function viewVideo (req: express.Request, res: express.Response) { const exists = await Redis.Instance.doesVideoIPViewExist(ip, immutableVideoAttrs.uuid) if (exists) { logger.debug('View for ip %s and video %s already exists.', ip, immutableVideoAttrs.uuid) - return res.sendStatus(HttpStatusCode.NO_CONTENT_204) + return res.status(HttpStatusCode.NO_CONTENT_204).end() } const video = await VideoModel.load(immutableVideoAttrs.id) @@ -179,7 +183,7 @@ async function viewVideo (req: express.Request, res: express.Response) { Hooks.runAction('action:api.video.viewed', { video, ip }) - return res.sendStatus(HttpStatusCode.NO_CONTENT_204) + return res.status(HttpStatusCode.NO_CONTENT_204).end() } async function getVideoDescription (req: express.Request, res: express.Response) { @@ -245,3 +249,15 @@ async function removeVideo (_req: express.Request, res: express.Response) { .status(HttpStatusCode.NO_CONTENT_204) .end() } + +// --------------------------------------------------------------------------- + +// FIXME: Should not exist, we rely on specific API +async function fetchRemoteVideoDescription (video: MVideoAccountLight) { + const host = video.VideoChannel.Account.Actor.Server.host + const path = video.getDescriptionAPIPath() + const url = REMOTE_SCHEME.HTTP + '://' + host + path + + const { body } = await doJSONRequest(url) + return body.description || '' +}