From dedcd583b2461895f816c3dd67d56f05d3274f6b Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 5 Nov 2021 14:11:19 +0100 Subject: Fix remote interaction When we fetch a ressource that is a redirection of another ressource --- server/controllers/api/search/search-video-channels.ts | 6 ++++-- server/controllers/api/search/search-video-playlists.ts | 6 ++++-- server/controllers/api/search/search-videos.ts | 7 +++++-- 3 files changed, 13 insertions(+), 6 deletions(-) (limited to 'server/controllers/api') diff --git a/server/controllers/api/search/search-video-channels.ts b/server/controllers/api/search/search-video-channels.ts index c9e81bffa..aa5afb46e 100644 --- a/server/controllers/api/search/search-video-channels.ts +++ b/server/controllers/api/search/search-video-channels.ts @@ -1,7 +1,7 @@ import express from 'express' import { sanitizeUrl } from '@server/helpers/core-utils' import { pickSearchChannelQuery } from '@server/helpers/query' -import { doJSONRequest } from '@server/helpers/requests' +import { doJSONRequest, findLatestRedirection } from '@server/helpers/requests' import { CONFIG } from '@server/initializers/config' import { WEBSERVER } from '@server/initializers/constants' import { Hooks } from '@server/lib/plugins/hooks' @@ -126,7 +126,9 @@ async function searchVideoChannelURI (search: string, isWebfingerSearch: boolean if (isUserAbleToSearchRemoteURI(res)) { try { - const actor = await getOrCreateAPActor(uri, 'all', true, true) + const latestUri = await findLatestRedirection(uri, { activityPub: true }) + + const actor = await getOrCreateAPActor(latestUri, 'all', true, true) videoChannel = actor.VideoChannel } catch (err) { logger.info('Cannot search remote video channel %s.', uri, { err }) diff --git a/server/controllers/api/search/search-video-playlists.ts b/server/controllers/api/search/search-video-playlists.ts index 61a11c74a..e76d65fde 100644 --- a/server/controllers/api/search/search-video-playlists.ts +++ b/server/controllers/api/search/search-video-playlists.ts @@ -3,7 +3,7 @@ import { sanitizeUrl } from '@server/helpers/core-utils' import { isUserAbleToSearchRemoteURI } from '@server/helpers/express-utils' import { logger } from '@server/helpers/logger' import { pickSearchPlaylistQuery } from '@server/helpers/query' -import { doJSONRequest } from '@server/helpers/requests' +import { doJSONRequest, findLatestRedirection } from '@server/helpers/requests' import { getFormattedObjects } from '@server/helpers/utils' import { CONFIG } from '@server/initializers/config' import { WEBSERVER } from '@server/initializers/constants' @@ -105,7 +105,9 @@ async function searchVideoPlaylistsURI (search: string, res: express.Response) { if (isUserAbleToSearchRemoteURI(res)) { try { - videoPlaylist = await getOrCreateAPVideoPlaylist(search) + const url = await findLatestRedirection(search, { activityPub: true }) + + videoPlaylist = await getOrCreateAPVideoPlaylist(url) } catch (err) { logger.info('Cannot search remote video playlist %s.', search, { err }) } diff --git a/server/controllers/api/search/search-videos.ts b/server/controllers/api/search/search-videos.ts index 6db70acdf..68428d766 100644 --- a/server/controllers/api/search/search-videos.ts +++ b/server/controllers/api/search/search-videos.ts @@ -1,7 +1,7 @@ import express from 'express' import { sanitizeUrl } from '@server/helpers/core-utils' import { pickSearchVideoQuery } from '@server/helpers/query' -import { doJSONRequest } from '@server/helpers/requests' +import { doJSONRequest, findLatestRedirection } from '@server/helpers/requests' import { CONFIG } from '@server/initializers/config' import { WEBSERVER } from '@server/initializers/constants' import { getOrCreateAPVideo } from '@server/lib/activitypub/videos' @@ -142,7 +142,10 @@ async function searchVideoURI (url: string, res: express.Response) { refreshVideo: false } - const result = await getOrCreateAPVideo({ videoObject: url, syncParam }) + const result = await getOrCreateAPVideo({ + videoObject: await findLatestRedirection(url, { activityPub: true }), + syncParam + }) video = result ? result.video : undefined } catch (err) { logger.info('Cannot search remote video %s.', url, { err }) -- cgit v1.2.3