mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2024-11-28 03:23:57 -06:00
Add user video list hooks
This commit is contained in:
parent
70fdff3d4e
commit
a4d2ca0715
@ -1,7 +1,8 @@
|
||||
import 'multer'
|
||||
import * as express from 'express'
|
||||
import { auditLoggerFactory, getAuditIdFromRes, UserAuditView } from '@server/helpers/audit-logger'
|
||||
import { UserUpdateMe, UserVideoRate as FormattedUserVideoRate, VideoSortField } from '../../../../shared'
|
||||
import { Hooks } from '@server/lib/plugins/hooks'
|
||||
import { UserUpdateMe, UserVideoRate as FormattedUserVideoRate } from '../../../../shared'
|
||||
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
|
||||
import { UserVideoQuota } from '../../../../shared/models/users/user-video-quota.model'
|
||||
import { createReqFiles } from '../../../helpers/express-utils'
|
||||
@ -104,12 +105,19 @@ export {
|
||||
|
||||
async function getUserVideos (req: express.Request, res: express.Response) {
|
||||
const user = res.locals.oauth.token.User
|
||||
const resultList = await VideoModel.listUserVideosForApi(
|
||||
user.Account.id,
|
||||
req.query.start as number,
|
||||
req.query.count as number,
|
||||
req.query.sort as VideoSortField,
|
||||
req.query.search as string
|
||||
|
||||
const apiOptions = await Hooks.wrapObject({
|
||||
accountId: user.Account.id,
|
||||
start: req.query.start,
|
||||
count: req.query.count,
|
||||
sort: req.query.sort,
|
||||
search: req.query.search
|
||||
}, 'filter:api.user.me.videos.list.params')
|
||||
|
||||
const resultList = await Hooks.wrapPromiseFun(
|
||||
VideoModel.listUserVideosForApi,
|
||||
apiOptions,
|
||||
'filter:api.user.me.videos.list.result'
|
||||
)
|
||||
|
||||
const additionalAttributes = {
|
||||
|
@ -1004,13 +1004,15 @@ export class VideoModel extends Model {
|
||||
return result.map(v => v.id)
|
||||
}
|
||||
|
||||
static listUserVideosForApi (
|
||||
accountId: number,
|
||||
start: number,
|
||||
count: number,
|
||||
sort: string,
|
||||
static listUserVideosForApi (options: {
|
||||
accountId: number
|
||||
start: number
|
||||
count: number
|
||||
sort: string
|
||||
search?: string
|
||||
) {
|
||||
}) {
|
||||
const { accountId, start, count, sort, search } = options
|
||||
|
||||
function buildBaseQuery (): FindOptions {
|
||||
let baseQuery = {
|
||||
offset: start,
|
||||
|
@ -59,6 +59,16 @@ async function register ({ registerHook, registerSetting, settingsManager, stora
|
||||
handler: obj => addToTotal(obj, 3)
|
||||
})
|
||||
|
||||
registerHook({
|
||||
target: 'filter:api.user.me.videos.list.params',
|
||||
handler: obj => addToCount(obj, 4)
|
||||
})
|
||||
|
||||
registerHook({
|
||||
target: 'filter:api.user.me.videos.list.result',
|
||||
handler: obj => addToTotal(obj, 4)
|
||||
})
|
||||
|
||||
registerHook({
|
||||
target: 'filter:api.video.get.result',
|
||||
handler: video => {
|
||||
|
@ -10,6 +10,7 @@ import {
|
||||
doubleFollow,
|
||||
getAccountVideos,
|
||||
getConfig,
|
||||
getMyVideos,
|
||||
getPluginTestPath,
|
||||
getVideo,
|
||||
getVideoChannelVideos,
|
||||
@ -121,6 +122,20 @@ describe('Test plugin filter hooks', function () {
|
||||
expect(res.body.total).to.equal(13)
|
||||
})
|
||||
|
||||
it('Should run filter:api.user.me.videos.list.params', async function () {
|
||||
const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 2)
|
||||
|
||||
// 1 plugin do +4 to the count parameter
|
||||
expect(res.body.data).to.have.lengthOf(6)
|
||||
})
|
||||
|
||||
it('Should run filter:api.user.me.videos.list.result', async function () {
|
||||
const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 2)
|
||||
|
||||
// Plugin do +4 to the total result
|
||||
expect(res.body.total).to.equal(14)
|
||||
})
|
||||
|
||||
it('Should run filter:api.video.get.result', async function () {
|
||||
const res = await getVideo(servers[0].url, videoUUID)
|
||||
|
||||
|
@ -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 my user videos for the REST API
|
||||
'filter:api.user.me.videos.list.params': true,
|
||||
'filter:api.user.me.videos.list.result': true,
|
||||
|
||||
// Filter the result of the get function
|
||||
// Used to get detailed video information (video watch page for example)
|
||||
'filter:api.video.get.result': true,
|
||||
|
Loading…
Reference in New Issue
Block a user