aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-06-02 15:47:05 +0200
committerChocobozzz <me@florianbigard.com>2021-06-02 16:57:53 +0200
commit304a84d59c3a800b7f7aef48cf55f307534c0926 (patch)
treee099aefd76aa8ee5aacef7ddfc59d79111fe474b /server/controllers/api
parentc56faf0d9453490737f283b29a203bb1ca632b95 (diff)
downloadPeerTube-304a84d59c3a800b7f7aef48cf55f307534c0926.tar.gz
PeerTube-304a84d59c3a800b7f7aef48cf55f307534c0926.tar.zst
PeerTube-304a84d59c3a800b7f7aef48cf55f307534c0926.zip
Refactor getOrCreateAPVideo
Diffstat (limited to 'server/controllers/api')
-rw-r--r--server/controllers/api/search.ts4
-rw-r--r--server/controllers/api/videos/index.ts17
2 files changed, 17 insertions, 4 deletions
diff --git a/server/controllers/api/search.ts b/server/controllers/api/search.ts
index 77e3a024d..0cb5674c2 100644
--- a/server/controllers/api/search.ts
+++ b/server/controllers/api/search.ts
@@ -2,7 +2,7 @@ import * as express from 'express'
2import { sanitizeUrl } from '@server/helpers/core-utils' 2import { sanitizeUrl } from '@server/helpers/core-utils'
3import { doJSONRequest } from '@server/helpers/requests' 3import { doJSONRequest } from '@server/helpers/requests'
4import { CONFIG } from '@server/initializers/config' 4import { CONFIG } from '@server/initializers/config'
5import { getOrCreateVideoAndAccountAndChannel } from '@server/lib/activitypub/videos' 5import { getOrCreateAPVideo } from '@server/lib/activitypub/videos'
6import { Hooks } from '@server/lib/plugins/hooks' 6import { Hooks } from '@server/lib/plugins/hooks'
7import { AccountBlocklistModel } from '@server/models/account/account-blocklist' 7import { AccountBlocklistModel } from '@server/models/account/account-blocklist'
8import { getServerActor } from '@server/models/application/application' 8import { getServerActor } from '@server/models/application/application'
@@ -244,7 +244,7 @@ async function searchVideoURI (url: string, res: express.Response) {
244 refreshVideo: false 244 refreshVideo: false
245 } 245 }
246 246
247 const result = await getOrCreateVideoAndAccountAndChannel({ videoObject: url, syncParam }) 247 const result = await getOrCreateAPVideo({ videoObject: url, syncParam })
248 video = result ? result.video : undefined 248 video = result ? result.video : undefined
249 } catch (err) { 249 } catch (err) {
250 logger.info('Cannot search remote video %s.', url, { err }) 250 logger.info('Cannot search remote video %s.', url, { err })
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts
index 47ab098ef..db23e5630 100644
--- a/server/controllers/api/videos/index.ts
+++ b/server/controllers/api/videos/index.ts
@@ -1,17 +1,18 @@
1import * as express from 'express' 1import * as express from 'express'
2import toInt from 'validator/lib/toInt' 2import toInt from 'validator/lib/toInt'
3import { doJSONRequest } from '@server/helpers/requests'
3import { LiveManager } from '@server/lib/live-manager' 4import { LiveManager } from '@server/lib/live-manager'
4import { getServerActor } from '@server/models/application/application' 5import { getServerActor } from '@server/models/application/application'
6import { MVideoAccountLight } from '@server/types/models'
5import { VideosCommonQuery } from '../../../../shared' 7import { VideosCommonQuery } from '../../../../shared'
6import { HttpStatusCode } from '../../../../shared/core-utils/miscs' 8import { HttpStatusCode } from '../../../../shared/core-utils/miscs'
7import { auditLoggerFactory, getAuditIdFromRes, VideoAuditView } from '../../../helpers/audit-logger' 9import { auditLoggerFactory, getAuditIdFromRes, VideoAuditView } from '../../../helpers/audit-logger'
8import { buildNSFWFilter, getCountVideos } from '../../../helpers/express-utils' 10import { buildNSFWFilter, getCountVideos } from '../../../helpers/express-utils'
9import { logger } from '../../../helpers/logger' 11import { logger } from '../../../helpers/logger'
10import { getFormattedObjects } from '../../../helpers/utils' 12import { getFormattedObjects } from '../../../helpers/utils'
11import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../initializers/constants' 13import { REMOTE_SCHEME, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../initializers/constants'
12import { sequelizeTypescript } from '../../../initializers/database' 14import { sequelizeTypescript } from '../../../initializers/database'
13import { sendView } from '../../../lib/activitypub/send/send-view' 15import { sendView } from '../../../lib/activitypub/send/send-view'
14import { fetchRemoteVideoDescription } from '../../../lib/activitypub/videos'
15import { JobQueue } from '../../../lib/job-queue' 16import { JobQueue } from '../../../lib/job-queue'
16import { Hooks } from '../../../lib/plugins/hooks' 17import { Hooks } from '../../../lib/plugins/hooks'
17import { Redis } from '../../../lib/redis' 18import { Redis } from '../../../lib/redis'
@@ -245,3 +246,15 @@ async function removeVideo (_req: express.Request, res: express.Response) {
245 .status(HttpStatusCode.NO_CONTENT_204) 246 .status(HttpStatusCode.NO_CONTENT_204)
246 .end() 247 .end()
247} 248}
249
250// ---------------------------------------------------------------------------
251
252// FIXME: Should not exist, we rely on specific API
253async function fetchRemoteVideoDescription (video: MVideoAccountLight) {
254 const host = video.VideoChannel.Account.Actor.Server.host
255 const path = video.getDescriptionAPIPath()
256 const url = REMOTE_SCHEME.HTTP + '://' + host + path
257
258 const { body } = await doJSONRequest<any>(url)
259 return body.description || ''
260}