diff options
author | Chocobozzz <me@florianbigard.com> | 2021-06-02 15:47:05 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-06-02 16:57:53 +0200 |
commit | 304a84d59c3a800b7f7aef48cf55f307534c0926 (patch) | |
tree | e099aefd76aa8ee5aacef7ddfc59d79111fe474b /server/controllers | |
parent | c56faf0d9453490737f283b29a203bb1ca632b95 (diff) | |
download | PeerTube-304a84d59c3a800b7f7aef48cf55f307534c0926.tar.gz PeerTube-304a84d59c3a800b7f7aef48cf55f307534c0926.tar.zst PeerTube-304a84d59c3a800b7f7aef48cf55f307534c0926.zip |
Refactor getOrCreateAPVideo
Diffstat (limited to 'server/controllers')
-rw-r--r-- | server/controllers/api/search.ts | 4 | ||||
-rw-r--r-- | server/controllers/api/videos/index.ts | 17 |
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' | |||
2 | import { sanitizeUrl } from '@server/helpers/core-utils' | 2 | import { sanitizeUrl } from '@server/helpers/core-utils' |
3 | import { doJSONRequest } from '@server/helpers/requests' | 3 | import { doJSONRequest } from '@server/helpers/requests' |
4 | import { CONFIG } from '@server/initializers/config' | 4 | import { CONFIG } from '@server/initializers/config' |
5 | import { getOrCreateVideoAndAccountAndChannel } from '@server/lib/activitypub/videos' | 5 | import { getOrCreateAPVideo } from '@server/lib/activitypub/videos' |
6 | import { Hooks } from '@server/lib/plugins/hooks' | 6 | import { Hooks } from '@server/lib/plugins/hooks' |
7 | import { AccountBlocklistModel } from '@server/models/account/account-blocklist' | 7 | import { AccountBlocklistModel } from '@server/models/account/account-blocklist' |
8 | import { getServerActor } from '@server/models/application/application' | 8 | import { 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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import toInt from 'validator/lib/toInt' | 2 | import toInt from 'validator/lib/toInt' |
3 | import { doJSONRequest } from '@server/helpers/requests' | ||
3 | import { LiveManager } from '@server/lib/live-manager' | 4 | import { LiveManager } from '@server/lib/live-manager' |
4 | import { getServerActor } from '@server/models/application/application' | 5 | import { getServerActor } from '@server/models/application/application' |
6 | import { MVideoAccountLight } from '@server/types/models' | ||
5 | import { VideosCommonQuery } from '../../../../shared' | 7 | import { VideosCommonQuery } from '../../../../shared' |
6 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs' | 8 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs' |
7 | import { auditLoggerFactory, getAuditIdFromRes, VideoAuditView } from '../../../helpers/audit-logger' | 9 | import { auditLoggerFactory, getAuditIdFromRes, VideoAuditView } from '../../../helpers/audit-logger' |
8 | import { buildNSFWFilter, getCountVideos } from '../../../helpers/express-utils' | 10 | import { buildNSFWFilter, getCountVideos } from '../../../helpers/express-utils' |
9 | import { logger } from '../../../helpers/logger' | 11 | import { logger } from '../../../helpers/logger' |
10 | import { getFormattedObjects } from '../../../helpers/utils' | 12 | import { getFormattedObjects } from '../../../helpers/utils' |
11 | import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../initializers/constants' | 13 | import { REMOTE_SCHEME, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../initializers/constants' |
12 | import { sequelizeTypescript } from '../../../initializers/database' | 14 | import { sequelizeTypescript } from '../../../initializers/database' |
13 | import { sendView } from '../../../lib/activitypub/send/send-view' | 15 | import { sendView } from '../../../lib/activitypub/send/send-view' |
14 | import { fetchRemoteVideoDescription } from '../../../lib/activitypub/videos' | ||
15 | import { JobQueue } from '../../../lib/job-queue' | 16 | import { JobQueue } from '../../../lib/job-queue' |
16 | import { Hooks } from '../../../lib/plugins/hooks' | 17 | import { Hooks } from '../../../lib/plugins/hooks' |
17 | import { Redis } from '../../../lib/redis' | 18 | import { 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 | ||
253 | async 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 | } | ||