mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-04 18:29:27 +02:00
Begin advanced search
This commit is contained in:
parent
7279b45581
commit
57c36b277e
38 changed files with 584 additions and 247 deletions
|
@ -9,6 +9,7 @@ import { videosRouter } from './videos'
|
|||
import { badRequest } from '../../helpers/express-utils'
|
||||
import { videoChannelRouter } from './video-channel'
|
||||
import * as cors from 'cors'
|
||||
import { searchRouter } from './search'
|
||||
|
||||
const apiRouter = express.Router()
|
||||
|
||||
|
@ -26,6 +27,7 @@ apiRouter.use('/accounts', accountsRouter)
|
|||
apiRouter.use('/video-channels', videoChannelRouter)
|
||||
apiRouter.use('/videos', videosRouter)
|
||||
apiRouter.use('/jobs', jobsRouter)
|
||||
apiRouter.use('/search', searchRouter)
|
||||
apiRouter.use('/ping', pong)
|
||||
apiRouter.use('/*', badRequest)
|
||||
|
||||
|
|
43
server/controllers/api/search.ts
Normal file
43
server/controllers/api/search.ts
Normal file
|
@ -0,0 +1,43 @@
|
|||
import * as express from 'express'
|
||||
import { isNSFWHidden } from '../../helpers/express-utils'
|
||||
import { getFormattedObjects } from '../../helpers/utils'
|
||||
import { VideoModel } from '../../models/video/video'
|
||||
import {
|
||||
asyncMiddleware,
|
||||
optionalAuthenticate,
|
||||
paginationValidator,
|
||||
searchValidator,
|
||||
setDefaultPagination,
|
||||
setDefaultSearchSort,
|
||||
videosSearchSortValidator
|
||||
} from '../../middlewares'
|
||||
|
||||
const searchRouter = express.Router()
|
||||
|
||||
searchRouter.get('/videos',
|
||||
paginationValidator,
|
||||
setDefaultPagination,
|
||||
videosSearchSortValidator,
|
||||
setDefaultSearchSort,
|
||||
optionalAuthenticate,
|
||||
searchValidator,
|
||||
asyncMiddleware(searchVideos)
|
||||
)
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
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)
|
||||
)
|
||||
|
||||
return res.json(getFormattedObjects(resultList.data, resultList.total))
|
||||
}
|
|
@ -38,7 +38,6 @@ import {
|
|||
videosAddValidator,
|
||||
videosGetValidator,
|
||||
videosRemoveValidator,
|
||||
videosSearchValidator,
|
||||
videosSortValidator,
|
||||
videosUpdateValidator
|
||||
} from '../../../middlewares'
|
||||
|
@ -50,7 +49,6 @@ import { blacklistRouter } from './blacklist'
|
|||
import { videoCommentRouter } from './comment'
|
||||
import { rateVideoRouter } from './rate'
|
||||
import { VideoFilter } from '../../../../shared/models/videos/video-query.type'
|
||||
import { VideoSortField } from '../../../../client/src/app/shared/video/sort-field.type'
|
||||
import { createReqFiles, isNSFWHidden } from '../../../helpers/express-utils'
|
||||
import { ScheduleVideoUpdateModel } from '../../../models/video/schedule-video-update'
|
||||
import { videoCaptionsRouter } from './captions'
|
||||
|
@ -94,15 +92,6 @@ videosRouter.get('/',
|
|||
optionalAuthenticate,
|
||||
asyncMiddleware(listVideos)
|
||||
)
|
||||
videosRouter.get('/search',
|
||||
videosSearchValidator,
|
||||
paginationValidator,
|
||||
videosSortValidator,
|
||||
setDefaultSort,
|
||||
setDefaultPagination,
|
||||
optionalAuthenticate,
|
||||
asyncMiddleware(searchVideos)
|
||||
)
|
||||
videosRouter.put('/:id',
|
||||
authenticate,
|
||||
reqVideoFileUpdate,
|
||||
|
@ -432,15 +421,3 @@ async function removeVideo (req: express.Request, res: express.Response) {
|
|||
|
||||
return res.type('json').status(204).end()
|
||||
}
|
||||
|
||||
async function searchVideos (req: express.Request, res: express.Response, next: express.NextFunction) {
|
||||
const resultList = await VideoModel.searchAndPopulateAccountAndServer(
|
||||
req.query.search as string,
|
||||
req.query.start as number,
|
||||
req.query.count as number,
|
||||
req.query.sort as VideoSortField,
|
||||
isNSFWHidden(res)
|
||||
)
|
||||
|
||||
return res.json(getFormattedObjects(resultList.data, resultList.total))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue