Add missing channel playlists AP endpoint
authorChocobozzz <me@florianbigard.com>
Wed, 13 May 2020 12:49:11 +0000 (14:49 +0200)
committerChocobozzz <me@florianbigard.com>
Wed, 13 May 2020 12:49:11 +0000 (14:49 +0200)
server/controllers/activitypub/client.ts
server/models/video/video-playlist.ts

index e44f1c6ab8440ac742c4bb768bcc8be4a2bd1660..f94abf808572b2c8f07727a5c768e08188310ede 100644 (file)
@@ -35,7 +35,7 @@ import { buildDislikeActivity } from '../../lib/activitypub/send/send-dislike'
 import { videoPlaylistElementAPGetValidator, videoPlaylistsGetValidator } from '../../middlewares/validators/videos/video-playlists'
 import { VideoPlaylistModel } from '../../models/video/video-playlist'
 import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model'
-import { MAccountId, MActorId, MVideoAPWithoutCaption, MVideoId } from '@server/typings/models'
+import { MAccountId, MActorId, MVideoAPWithoutCaption, MVideoId, MChannelId } from '@server/typings/models'
 import { getServerActor } from '@server/models/application/application'
 import { getRateUrl } from '@server/lib/activitypub/video-rates'
 
@@ -137,6 +137,11 @@ activityPubClientRouter.get('/video-channels/:name/following',
   asyncMiddleware(localVideoChannelValidator),
   asyncMiddleware(videoChannelFollowingController)
 )
+activityPubClientRouter.get('/video-channels/:name/playlists',
+  executeIfActivityPub,
+  asyncMiddleware(localVideoChannelValidator),
+  asyncMiddleware(videoChannelPlaylistsController)
+)
 
 activityPubClientRouter.get('/redundancy/videos/:videoId/:resolution([0-9]+)(-:fps([0-9]+))?',
   executeIfActivityPub,
@@ -190,7 +195,14 @@ async function accountFollowingController (req: express.Request, res: express.Re
 
 async function accountPlaylistsController (req: express.Request, res: express.Response) {
   const account = res.locals.account
-  const activityPubResult = await actorPlaylists(req, account)
+  const activityPubResult = await actorPlaylists(req, { account })
+
+  return activityPubResponse(activityPubContextify(activityPubResult), res)
+}
+
+async function videoChannelPlaylistsController (req: express.Request, res: express.Response) {
+  const channel = res.locals.videoChannel
+  const activityPubResult = await actorPlaylists(req, { channel })
 
   return activityPubResponse(activityPubContextify(activityPubResult), res)
 }
@@ -381,9 +393,9 @@ async function actorFollowers (req: express.Request, actor: MActorId) {
   return activityPubCollectionPagination(WEBSERVER.URL + req.path, handler, req.query.page)
 }
 
-async function actorPlaylists (req: express.Request, account: MAccountId) {
+async function actorPlaylists (req: express.Request, options: { account: MAccountId } | { channel: MChannelId }) {
   const handler = (start: number, count: number) => {
-    return VideoPlaylistModel.listPublicUrlsOfForAP(account.id, start, count)
+    return VideoPlaylistModel.listPublicUrlsOfForAP(options, start, count)
   }
 
   return activityPubCollectionPagination(WEBSERVER.URL + req.path, handler, req.query.page)
index b9b95e06719ba6bb5bb126555bbbd34e9b377c50..d66518c9f2d7568c4a6c465d676cde572843fd16 100644 (file)
@@ -53,6 +53,7 @@ import {
   MVideoPlaylistIdWithElements
 } from '../../typings/models/video/video-playlist'
 import { MThumbnail } from '../../typings/models/video/thumbnail'
+import { MAccountId, MChannelId } from '@server/typings/models'
 
 enum ScopeNames {
   AVAILABLE_FOR_LIST = 'AVAILABLE_FOR_LIST',
@@ -340,15 +341,24 @@ export class VideoPlaylistModel extends Model<VideoPlaylistModel> {
       })
   }
 
-  static listPublicUrlsOfForAP (accountId: number, start: number, count: number) {
+  static listPublicUrlsOfForAP (options: { account?: MAccountId, channel?: MChannelId }, start: number, count: number) {
+    const where = {
+      privacy: VideoPlaylistPrivacy.PUBLIC
+    }
+
+    if (options.account) {
+      Object.assign(where, { ownerAccountId: options.account.id })
+    }
+
+    if (options.channel) {
+      Object.assign(where, { videoChannelId: options.channel.id })
+    }
+
     const query = {
       attributes: [ 'url' ],
       offset: start,
       limit: count,
-      where: {
-        ownerAccountId: accountId,
-        privacy: VideoPlaylistPrivacy.PUBLIC
-      }
+      where
     }
 
     return VideoPlaylistModel.findAndCountAll(query)