1
0
Fork 0

Add user video list hooks

This commit is contained in:
Chocobozzz 2021-01-20 15:28:34 +01:00
parent 70fdff3d4e
commit a4d2ca0715
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
5 changed files with 52 additions and 13 deletions

View File

@ -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 = {

View File

@ -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,

View File

@ -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 => {

View File

@ -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)

View File

@ -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,