mirror of https://github.com/Chocobozzz/PeerTube
parent
60520c7c85
commit
ebd822ca0b
|
@ -43,6 +43,7 @@ import { AccountModel } from '../../models/account/account'
|
|||
import { VideoPlaylistModel } from '../../models/video/video-playlist'
|
||||
import { VideoPlaylistElementModel } from '../../models/video/video-playlist-element'
|
||||
import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
|
||||
import { Hooks } from '@server/lib/plugins/hooks'
|
||||
|
||||
const reqThumbnailFile = createReqFiles([ 'thumbnailfile' ], MIMETYPES.IMAGE.MIMETYPE_EXT, { thumbnailfile: CONFIG.STORAGE.TMP_DIR })
|
||||
|
||||
|
@ -449,13 +450,19 @@ async function getVideoPlaylistVideos (req: express.Request, res: express.Respon
|
|||
const user = res.locals.oauth ? res.locals.oauth.token.User : undefined
|
||||
const server = await getServerActor()
|
||||
|
||||
const resultList = await VideoPlaylistElementModel.listForApi({
|
||||
const apiOptions = await Hooks.wrapObject({
|
||||
start: req.query.start,
|
||||
count: req.query.count,
|
||||
videoPlaylistId: videoPlaylistInstance.id,
|
||||
serverAccount: server.Account,
|
||||
user
|
||||
})
|
||||
}, 'filter:api.video-playlists.videos.list.params')
|
||||
|
||||
const resultList = await Hooks.wrapPromiseFun(
|
||||
VideoPlaylistElementModel.listForApi,
|
||||
apiOptions,
|
||||
'filter:api.video-playlists.videos.list.result'
|
||||
)
|
||||
|
||||
const options = {
|
||||
displayNSFW: buildNSFWFilter(res, req.query.nsfw),
|
||||
|
|
|
@ -59,6 +59,16 @@ async function register ({ registerHook, registerSetting, settingsManager, stora
|
|||
handler: obj => addToTotal(obj, 3)
|
||||
})
|
||||
|
||||
registerHook({
|
||||
target: 'filter:api.video-playlists.videos.list.params',
|
||||
handle: obj => addToCount(obj, 4)
|
||||
})
|
||||
|
||||
registerHook({
|
||||
target: 'filter:api.video-playlists.videos.list.result',
|
||||
handle: obj => addToTotal(obj, 7)
|
||||
})
|
||||
|
||||
registerHook({
|
||||
target: 'filter:api.user.me.videos.list.params',
|
||||
handler: obj => addToCount(obj, 4)
|
||||
|
|
|
@ -15,6 +15,7 @@ import {
|
|||
getAccountVideos,
|
||||
getConfig,
|
||||
getMyVideos,
|
||||
getPlaylistVideos,
|
||||
getPluginTestPath,
|
||||
getVideo,
|
||||
getVideoChannelVideos,
|
||||
|
@ -53,6 +54,7 @@ describe('Test plugin filter hooks', function () {
|
|||
let servers: ServerInfo[]
|
||||
let videoUUID: string
|
||||
let threadId: number
|
||||
let playlistId: number
|
||||
|
||||
before(async function () {
|
||||
this.timeout(60000)
|
||||
|
@ -78,6 +80,20 @@ describe('Test plugin filter hooks', function () {
|
|||
await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'default video ' + i })
|
||||
}
|
||||
|
||||
const createPlaylistRes = await createVideoPlaylist({
|
||||
url: servers[0].url,
|
||||
token: servers[0].accessToken,
|
||||
playlistAttrs: {
|
||||
displayName: 'my super playlist',
|
||||
privacy: VideoPlaylistPrivacy.PUBLIC,
|
||||
description: 'my super description',
|
||||
thumbnailfile: 'thumbnail.jpg',
|
||||
videoChannelId: servers[0].videoChannel.id
|
||||
}
|
||||
})
|
||||
|
||||
playlistId = createPlaylistRes.body.videoPlaylist.id
|
||||
|
||||
const res = await getVideosList(servers[0].url)
|
||||
videoUUID = res.body.data[0].uuid
|
||||
|
||||
|
@ -135,6 +151,20 @@ describe('Test plugin filter hooks', function () {
|
|||
expect(res.body.total).to.equal(13)
|
||||
})
|
||||
|
||||
it('Should run filter:api.video-playlists.videos.list.params', async function () {
|
||||
const res = await getPlaylistVideos(servers[0].url, servers[0].accessToken, playlistId, 0, 20)
|
||||
|
||||
// 1 plugin do +4 to the count parameter
|
||||
expect(res.body.data).to.have.lengthOf(4)
|
||||
})
|
||||
|
||||
it('Should run filter:api.video-playlists.videos.list.result', async function () {
|
||||
const res = await getPlaylistVideos(servers[0].url, servers[0].accessToken, playlistId, 0, 20)
|
||||
|
||||
// Plugin do +7 to the total result
|
||||
expect(res.body.total).to.equal(7)
|
||||
})
|
||||
|
||||
it('Should run filter:api.user.me.videos.list.params', async function () {
|
||||
const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 2)
|
||||
|
||||
|
|
|
@ -14,6 +14,10 @@ export const serverFilterHookObject = {
|
|||
'filter:api.video-channels.videos.list.params': true,
|
||||
'filter:api.video-channels.videos.list.result': true,
|
||||
|
||||
// Filter params/result used to list playlist videos for the REST API
|
||||
'filter:api.video-playlists.videos.list.params': true,
|
||||
'filter:api.video-playlists.videos.list.result': true,
|
||||
|
||||
// Filter params/result used to list my user videos for the REST API
|
||||
'filter:api.user.me.videos.list.params': true,
|
||||
'filter:api.user.me.videos.list.result': true,
|
||||
|
|
Loading…
Reference in New Issue