mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 19:42:24 +02:00
Add videos list filters
This commit is contained in:
parent
57c36b277e
commit
d525fc399a
26 changed files with 835 additions and 271 deletions
|
@ -1,7 +1,7 @@
|
|||
import * as express from 'express'
|
||||
import { getFormattedObjects } from '../../helpers/utils'
|
||||
import {
|
||||
asyncMiddleware,
|
||||
asyncMiddleware, commonVideosFiltersValidator,
|
||||
listVideoAccountChannelsValidator,
|
||||
optionalAuthenticate,
|
||||
paginationValidator,
|
||||
|
@ -11,7 +11,7 @@ import {
|
|||
import { accountsNameWithHostGetValidator, accountsSortValidator, videosSortValidator } from '../../middlewares/validators'
|
||||
import { AccountModel } from '../../models/account/account'
|
||||
import { VideoModel } from '../../models/video/video'
|
||||
import { isNSFWHidden } from '../../helpers/express-utils'
|
||||
import { buildNSFWFilter } from '../../helpers/express-utils'
|
||||
import { VideoChannelModel } from '../../models/video/video-channel'
|
||||
|
||||
const accountsRouter = express.Router()
|
||||
|
@ -36,6 +36,7 @@ accountsRouter.get('/:accountName/videos',
|
|||
setDefaultSort,
|
||||
setDefaultPagination,
|
||||
optionalAuthenticate,
|
||||
commonVideosFiltersValidator,
|
||||
asyncMiddleware(listAccountVideos)
|
||||
)
|
||||
|
||||
|
@ -77,7 +78,12 @@ async function listAccountVideos (req: express.Request, res: express.Response, n
|
|||
start: req.query.start,
|
||||
count: req.query.count,
|
||||
sort: req.query.sort,
|
||||
hideNSFW: isNSFWHidden(res),
|
||||
categoryOneOf: req.query.categoryOneOf,
|
||||
licenceOneOf: req.query.licenceOneOf,
|
||||
languageOneOf: req.query.languageOneOf,
|
||||
tagsOneOf: req.query.tagsOneOf,
|
||||
tagsAllOf: req.query.tagsAllOf,
|
||||
nsfw: buildNSFWFilter(res, req.query.nsfw),
|
||||
withFiles: false,
|
||||
accountId: account.id
|
||||
})
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
import * as express from 'express'
|
||||
import { isNSFWHidden } from '../../helpers/express-utils'
|
||||
import { buildNSFWFilter } from '../../helpers/express-utils'
|
||||
import { getFormattedObjects } from '../../helpers/utils'
|
||||
import { VideoModel } from '../../models/video/video'
|
||||
import {
|
||||
asyncMiddleware,
|
||||
commonVideosFiltersValidator,
|
||||
optionalAuthenticate,
|
||||
paginationValidator,
|
||||
searchValidator,
|
||||
|
@ -11,6 +12,7 @@ import {
|
|||
setDefaultSearchSort,
|
||||
videosSearchSortValidator
|
||||
} from '../../middlewares'
|
||||
import { VideosSearchQuery } from '../../../shared/models/search'
|
||||
|
||||
const searchRouter = express.Router()
|
||||
|
||||
|
@ -20,6 +22,7 @@ searchRouter.get('/videos',
|
|||
videosSearchSortValidator,
|
||||
setDefaultSearchSort,
|
||||
optionalAuthenticate,
|
||||
commonVideosFiltersValidator,
|
||||
searchValidator,
|
||||
asyncMiddleware(searchVideos)
|
||||
)
|
||||
|
@ -31,13 +34,10 @@ export { searchRouter }
|
|||
// ---------------------------------------------------------------------------
|
||||
|
||||
async function searchVideos (req: express.Request, res: express.Response) {
|
||||
const resultList = await VideoModel.searchAndPopulateAccountAndServer(
|
||||
req.query.search as string,
|
||||
req.query.start as number,
|
||||
req.query.count as number,
|
||||
req.query.sort as string,
|
||||
isNSFWHidden(res)
|
||||
)
|
||||
const query: VideosSearchQuery = req.query
|
||||
|
||||
const options = Object.assign(query, { nsfw: buildNSFWFilter(res, query.nsfw) })
|
||||
const resultList = await VideoModel.searchAndPopulateAccountAndServer(options)
|
||||
|
||||
return res.json(getFormattedObjects(resultList.data, resultList.total))
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ import { getFormattedObjects, resetSequelizeInstance } from '../../helpers/utils
|
|||
import {
|
||||
asyncMiddleware,
|
||||
asyncRetryTransactionMiddleware,
|
||||
authenticate,
|
||||
authenticate, commonVideosFiltersValidator,
|
||||
optionalAuthenticate,
|
||||
paginationValidator,
|
||||
setDefaultPagination,
|
||||
|
@ -19,7 +19,7 @@ import { videosSortValidator } from '../../middlewares/validators'
|
|||
import { sendUpdateActor } from '../../lib/activitypub/send'
|
||||
import { VideoChannelCreate, VideoChannelUpdate } from '../../../shared'
|
||||
import { createVideoChannel } from '../../lib/video-channel'
|
||||
import { createReqFiles, isNSFWHidden } from '../../helpers/express-utils'
|
||||
import { createReqFiles, buildNSFWFilter } from '../../helpers/express-utils'
|
||||
import { setAsyncActorKeys } from '../../lib/activitypub'
|
||||
import { AccountModel } from '../../models/account/account'
|
||||
import { CONFIG, IMAGE_MIMETYPE_EXT, sequelizeTypescript } from '../../initializers'
|
||||
|
@ -79,6 +79,7 @@ videoChannelRouter.get('/:id/videos',
|
|||
setDefaultSort,
|
||||
setDefaultPagination,
|
||||
optionalAuthenticate,
|
||||
commonVideosFiltersValidator,
|
||||
asyncMiddleware(listVideoChannelVideos)
|
||||
)
|
||||
|
||||
|
@ -189,7 +190,12 @@ async function listVideoChannelVideos (req: express.Request, res: express.Respon
|
|||
start: req.query.start,
|
||||
count: req.query.count,
|
||||
sort: req.query.sort,
|
||||
hideNSFW: isNSFWHidden(res),
|
||||
categoryOneOf: req.query.categoryOneOf,
|
||||
licenceOneOf: req.query.licenceOneOf,
|
||||
languageOneOf: req.query.languageOneOf,
|
||||
tagsOneOf: req.query.tagsOneOf,
|
||||
tagsAllOf: req.query.tagsAllOf,
|
||||
nsfw: buildNSFWFilter(res, req.query.nsfw),
|
||||
withFiles: false,
|
||||
videoChannelId: videoChannelInstance.id
|
||||
})
|
||||
|
|
|
@ -31,6 +31,7 @@ import {
|
|||
asyncMiddleware,
|
||||
asyncRetryTransactionMiddleware,
|
||||
authenticate,
|
||||
commonVideosFiltersValidator,
|
||||
optionalAuthenticate,
|
||||
paginationValidator,
|
||||
setDefaultPagination,
|
||||
|
@ -49,7 +50,7 @@ import { blacklistRouter } from './blacklist'
|
|||
import { videoCommentRouter } from './comment'
|
||||
import { rateVideoRouter } from './rate'
|
||||
import { VideoFilter } from '../../../../shared/models/videos/video-query.type'
|
||||
import { createReqFiles, isNSFWHidden } from '../../../helpers/express-utils'
|
||||
import { createReqFiles, buildNSFWFilter } from '../../../helpers/express-utils'
|
||||
import { ScheduleVideoUpdateModel } from '../../../models/video/schedule-video-update'
|
||||
import { videoCaptionsRouter } from './captions'
|
||||
|
||||
|
@ -90,6 +91,7 @@ videosRouter.get('/',
|
|||
setDefaultSort,
|
||||
setDefaultPagination,
|
||||
optionalAuthenticate,
|
||||
commonVideosFiltersValidator,
|
||||
asyncMiddleware(listVideos)
|
||||
)
|
||||
videosRouter.put('/:id',
|
||||
|
@ -401,8 +403,12 @@ async function listVideos (req: express.Request, res: express.Response, next: ex
|
|||
start: req.query.start,
|
||||
count: req.query.count,
|
||||
sort: req.query.sort,
|
||||
category: req.query.category,
|
||||
hideNSFW: isNSFWHidden(res),
|
||||
categoryOneOf: req.query.categoryOneOf,
|
||||
licenceOneOf: req.query.licenceOneOf,
|
||||
languageOneOf: req.query.languageOneOf,
|
||||
tagsOneOf: req.query.tagsOneOf,
|
||||
tagsAllOf: req.query.tagsAllOf,
|
||||
nsfw: buildNSFWFilter(res, req.query.nsfw),
|
||||
filter: req.query.filter as VideoFilter,
|
||||
withFiles: false
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue