From 5ef0430dfb46d1657679a72d6a73989aadf68a96 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 27 Mar 2024 15:48:29 +0100 Subject: [PATCH] Display playlists if allowed to escape federation --- server/core/controllers/api/accounts.ts | 6 ++++- server/core/controllers/api/video-channel.ts | 6 ++++- server/core/controllers/api/video-playlist.ts | 6 ++--- server/core/models/video/video-playlist.ts | 23 ++++++++++--------- 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/server/core/controllers/api/accounts.ts b/server/core/controllers/api/accounts.ts index 7b4a11ddd..ae3274246 100644 --- a/server/core/controllers/api/accounts.ts +++ b/server/core/controllers/api/accounts.ts @@ -188,7 +188,11 @@ async function listAccountPlaylists (req: express.Request, res: express.Response const resultList = await VideoPlaylistModel.listForApi({ search: req.query.search, - followerActorId: serverActor.id, + + followerActorId: isUserAbleToSearchRemoteURI(res) + ? null + : serverActor.id, + start: req.query.start, count: req.query.count, sort: req.query.sort, diff --git a/server/core/controllers/api/video-channel.ts b/server/core/controllers/api/video-channel.ts index b9c9e5f60..86a5c6193 100644 --- a/server/core/controllers/api/video-channel.ts +++ b/server/core/controllers/api/video-channel.ts @@ -140,6 +140,7 @@ videoChannelRouter.get('/:nameWithHost', ) videoChannelRouter.get('/:nameWithHost/video-playlists', + optionalAuthenticate, asyncMiddleware(videoChannelsNameWithHostValidator), paginationValidator, videoPlaylistsSortValidator, @@ -372,7 +373,10 @@ async function listVideoChannelPlaylists (req: express.Request, res: express.Res const serverActor = await getServerActor() const resultList = await VideoPlaylistModel.listForApi({ - followerActorId: serverActor.id, + followerActorId: isUserAbleToSearchRemoteURI(res) + ? null + : serverActor.id, + start: req.query.start, count: req.query.count, sort: req.query.sort, diff --git a/server/core/controllers/api/video-playlist.ts b/server/core/controllers/api/video-playlist.ts index 9220e3e71..8283c59b2 100644 --- a/server/core/controllers/api/video-playlist.ts +++ b/server/core/controllers/api/video-playlist.ts @@ -1,4 +1,3 @@ -import express from 'express' import { forceNumber } from '@peertube/peertube-core-utils' import { HttpStatusCode, @@ -12,11 +11,13 @@ import { VideoPlaylistReorder, VideoPlaylistUpdate } from '@peertube/peertube-models' +import { uuidToShort } from '@peertube/peertube-node-utils' import { scheduleRefreshIfNeeded } from '@server/lib/activitypub/playlists/index.js' import { Hooks } from '@server/lib/plugins/hooks.js' +import { generateThumbnailForPlaylist } from '@server/lib/video-playlist.js' import { getServerActor } from '@server/models/application/application.js' import { MVideoPlaylistFull, MVideoPlaylistThumbnail } from '@server/types/models/index.js' -import { uuidToShort } from '@peertube/peertube-node-utils' +import express from 'express' import { resetSequelizeInstance } from '../../helpers/database-utils.js' import { createReqFiles } from '../../helpers/express-utils.js' import { logger } from '../../helpers/logger.js' @@ -50,7 +51,6 @@ import { import { AccountModel } from '../../models/account/account.js' import { VideoPlaylistElementModel } from '../../models/video/video-playlist-element.js' import { VideoPlaylistModel } from '../../models/video/video-playlist.js' -import { generateThumbnailForPlaylist } from '@server/lib/video-playlist.js' const reqThumbnailFile = createReqFiles([ 'thumbnailfile' ], MIMETYPES.IMAGE.MIMETYPE_EXT) diff --git a/server/core/models/video/video-playlist.ts b/server/core/models/video/video-playlist.ts index cb1e79da8..e49d9dd90 100644 --- a/server/core/models/video/video-playlist.ts +++ b/server/core/models/video/video-playlist.ts @@ -12,7 +12,7 @@ import { buildUUID, uuidToShort } from '@peertube/peertube-node-utils' import { activityPubCollectionPagination } from '@server/lib/activitypub/collection.js' import { MAccountId, MChannelId, MVideoPlaylistElement } from '@server/types/models/index.js' import { join } from 'path' -import { FindOptions, Includeable, literal, Op, ScopeOptions, Sequelize, Transaction, WhereOptions } from 'sequelize' +import { FindOptions, Includeable, Op, ScopeOptions, Sequelize, Transaction, WhereOptions, literal } from 'sequelize' import { AllowNull, BelongsTo, @@ -47,8 +47,9 @@ import { import { MThumbnail } from '../../types/models/video/thumbnail.js' import { MVideoPlaylist, + MVideoPlaylistAP, MVideoPlaylistAccountThumbnail, - MVideoPlaylistAP, MVideoPlaylistFormattable, + MVideoPlaylistFormattable, MVideoPlaylistFull, MVideoPlaylistFullSummary, MVideoPlaylistSummaryWithElements @@ -167,15 +168,15 @@ function getVideoLengthSelect () { privacy: VideoPlaylistPrivacy.PUBLIC }) - // Only list local playlists - const whereActorOr: WhereOptions[] = [ - { - serverId: null - } - ] - // … OR playlists that are on an instance followed by actorId if (options.followerActorId) { + // Only list local playlists + const whereActorOr: WhereOptions[] = [ + { + serverId: null + } + ] + const inQueryInstanceFollow = buildServerIdsFollowedBy(options.followerActorId) whereActorOr.push({ @@ -183,9 +184,9 @@ function getVideoLengthSelect () { [Op.in]: literal(inQueryInstanceFollow) } }) - } - Object.assign(whereActor, { [Op.or]: whereActorOr }) + Object.assign(whereActor, { [Op.or]: whereActorOr }) + } } if (options.accountId) {