Add server hooks for listing subscription
This commit is contained in:
parent
d41f4a6dc6
commit
c0687c91b9
|
@ -30,6 +30,7 @@ import {
|
||||||
} from '../../../middlewares/validators'
|
} from '../../../middlewares/validators'
|
||||||
import { ActorFollowModel } from '../../../models/actor/actor-follow'
|
import { ActorFollowModel } from '../../../models/actor/actor-follow'
|
||||||
import { VideoModel } from '../../../models/video/video'
|
import { VideoModel } from '../../../models/video/video'
|
||||||
|
import { Hooks } from '@server/lib/plugins/hooks'
|
||||||
|
|
||||||
const mySubscriptionsRouter = express.Router()
|
const mySubscriptionsRouter = express.Router()
|
||||||
|
|
||||||
|
@ -170,7 +171,7 @@ async function getUserSubscriptionVideos (req: express.Request, res: express.Res
|
||||||
const countVideos = getCountVideos(req)
|
const countVideos = getCountVideos(req)
|
||||||
const query = pickCommonVideoQuery(req.query)
|
const query = pickCommonVideoQuery(req.query)
|
||||||
|
|
||||||
const resultList = await VideoModel.listForApi({
|
const apiOptions = await Hooks.wrapObject({
|
||||||
...query,
|
...query,
|
||||||
|
|
||||||
displayOnlyForFollower: {
|
displayOnlyForFollower: {
|
||||||
|
@ -180,7 +181,13 @@ async function getUserSubscriptionVideos (req: express.Request, res: express.Res
|
||||||
nsfw: buildNSFWFilter(res, query.nsfw),
|
nsfw: buildNSFWFilter(res, query.nsfw),
|
||||||
user,
|
user,
|
||||||
countVideos
|
countVideos
|
||||||
})
|
}, 'filter:api.user.me.subscription-videos.list.params')
|
||||||
|
|
||||||
|
const resultList = await Hooks.wrapPromiseFun(
|
||||||
|
VideoModel.listForApi,
|
||||||
|
apiOptions,
|
||||||
|
'filter:api.user.me.subscription-videos.list.result'
|
||||||
|
)
|
||||||
|
|
||||||
return res.json(getFormattedObjects(resultList.data, resultList.total, guessAdditionalAttributesFromQuery(query)))
|
return res.json(getFormattedObjects(resultList.data, resultList.total, guessAdditionalAttributesFromQuery(query)))
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,6 +89,16 @@ async function register ({ registerHook, registerSetting, settingsManager, stora
|
||||||
handler: obj => addToTotal(obj, 4)
|
handler: obj => addToTotal(obj, 4)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
registerHook({
|
||||||
|
target: 'filter:api.user.me.subscription-videos.list.params',
|
||||||
|
handler: obj => Object.assign({}, obj, { count: 1 })
|
||||||
|
})
|
||||||
|
|
||||||
|
registerHook({
|
||||||
|
target: 'filter:api.user.me.subscription-videos.list.result',
|
||||||
|
handler: obj => addToTotal(obj, 4)
|
||||||
|
})
|
||||||
|
|
||||||
registerHook({
|
registerHook({
|
||||||
target: 'filter:api.video.get.result',
|
target: 'filter:api.video.get.result',
|
||||||
handler: video => {
|
handler: video => {
|
||||||
|
|
|
@ -71,6 +71,9 @@ describe('Test plugin filter hooks', function () {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Root subscribes to itself
|
||||||
|
await servers[0].subscriptions.add({ targetUri: 'root_channel@' + servers[0].host })
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('Videos', function () {
|
describe('Videos', function () {
|
||||||
|
@ -151,6 +154,20 @@ describe('Test plugin filter hooks', function () {
|
||||||
expect(total).to.equal(14)
|
expect(total).to.equal(14)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('Should run filter:api.user.me.subscription-videos.list.params', async function () {
|
||||||
|
const { data } = await servers[0].subscriptions.listVideos()
|
||||||
|
|
||||||
|
// 1 plugin set the count parameter to 1
|
||||||
|
expect(data).to.have.lengthOf(1)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Should run filter:api.user.me.subscription-videos.list.result', async function () {
|
||||||
|
const { total } = await servers[0].subscriptions.listVideos()
|
||||||
|
|
||||||
|
// Plugin do +4 to the total result
|
||||||
|
expect(total).to.equal(14)
|
||||||
|
})
|
||||||
|
|
||||||
it('Should run filter:api.video.get.result', async function () {
|
it('Should run filter:api.video.get.result', async function () {
|
||||||
const video = await servers[0].videos.get({ id: videoUUID })
|
const video = await servers[0].videos.get({ id: videoUUID })
|
||||||
expect(video.name).to.contain('<3')
|
expect(video.name).to.contain('<3')
|
||||||
|
|
|
@ -27,6 +27,10 @@ export const serverFilterHookObject = {
|
||||||
'filter:api.overviews.videos.list.params': true,
|
'filter:api.overviews.videos.list.params': true,
|
||||||
'filter:api.overviews.videos.list.result': true,
|
'filter:api.overviews.videos.list.result': true,
|
||||||
|
|
||||||
|
// Filter params/result used to list subscription videos for the REST API
|
||||||
|
'filter:api.user.me.subscription-videos.list.params': true,
|
||||||
|
'filter:api.user.me.subscription-videos.list.result': true,
|
||||||
|
|
||||||
// Filter params/results to search videos/channels in the DB or on the remote index
|
// Filter params/results to search videos/channels in the DB or on the remote index
|
||||||
'filter:api.search.videos.local.list.params': true,
|
'filter:api.search.videos.local.list.params': true,
|
||||||
'filter:api.search.videos.local.list.result': true,
|
'filter:api.search.videos.local.list.result': true,
|
||||||
|
|
Loading…
Reference in New Issue