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