import { AccountModel } from '../../models/account/account'
import { AccountVideoRateModel } from '../../models/account/account-video-rate'
import { VideoModel } from '../../models/video/video'
-import { buildNSFWFilter, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils'
+import { buildNSFWFilter, isUserAbleToSearchRemoteURI, getCountVideos } from '../../helpers/express-utils'
import { VideoChannelModel } from '../../models/video/video-channel'
import { JobQueue } from '../../lib/job-queue'
import { logger } from '../../helpers/logger'
async function listAccountVideos (req: express.Request, res: express.Response) {
const account = res.locals.account
const followerActorId = isUserAbleToSearchRemoteURI(res) ? null : undefined
+ const countVideos = getCountVideos(req)
const resultList = await VideoModel.listForApi({
followerActorId,
nsfw: buildNSFWFilter(res, req.query.nsfw),
withFiles: false,
accountId: account.id,
- user: res.locals.oauth ? res.locals.oauth.token.User : undefined
+ user: res.locals.oauth ? res.locals.oauth.token.User : undefined,
+ countVideos
})
return res.json(getFormattedObjects(resultList.data, resultList.total))
sort: '-createdAt',
includeLocalVideos: true,
nsfw: buildNSFWFilter(res),
- withFiles: false
+ withFiles: false,
+ countVideos: false
}, where)
- const { data } = await VideoModel.listForApi(query, false)
+ const { data } = await VideoModel.listForApi(query)
return data.map(d => d.toFormattedJSON())
}
} from '../../../middlewares'
import { areSubscriptionsExistValidator, userSubscriptionsSortValidator, videosSortValidator } from '../../../middlewares/validators'
import { VideoModel } from '../../../models/video/video'
-import { buildNSFWFilter } from '../../../helpers/express-utils'
+import { buildNSFWFilter, getCountVideos } from '../../../helpers/express-utils'
import { VideoFilter } from '../../../../shared/models/videos/video-query.type'
import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
import { JobQueue } from '../../../lib/job-queue'
async function getUserSubscriptionVideos (req: express.Request, res: express.Response) {
const user = res.locals.oauth.token.User
+ const countVideos = getCountVideos(req)
+
const resultList = await VideoModel.listForApi({
start: req.query.start,
count: req.query.count,
filter: req.query.filter as VideoFilter,
withFiles: false,
followerActorId: user.Account.Actor.id,
- user
+ user,
+ countVideos
})
return res.json(getFormattedObjects(resultList.data, resultList.total))
import { sendUpdateActor } from '../../lib/activitypub/send'
import { VideoChannelCreate, VideoChannelUpdate } from '../../../shared'
import { createLocalVideoChannel, federateAllVideosOfChannel } from '../../lib/video-channel'
-import { buildNSFWFilter, createReqFiles, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils'
+import { buildNSFWFilter, createReqFiles, getCountVideos, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils'
import { setAsyncActorKeys } from '../../lib/activitypub'
import { AccountModel } from '../../models/account/account'
import { MIMETYPES } from '../../initializers/constants'
async function listVideoChannelVideos (req: express.Request, res: express.Response) {
const videoChannelInstance = res.locals.videoChannel
const followerActorId = isUserAbleToSearchRemoteURI(res) ? null : undefined
+ const countVideos = getCountVideos(req)
const resultList = await VideoModel.listForApi({
followerActorId,
nsfw: buildNSFWFilter(res, req.query.nsfw),
withFiles: false,
videoChannelId: videoChannelInstance.id,
- user: res.locals.oauth ? res.locals.oauth.token.User : undefined
+ user: res.locals.oauth ? res.locals.oauth.token.User : undefined,
+ countVideos
})
return res.json(getFormattedObjects(resultList.data, resultList.total))
import { rateVideoRouter } from './rate'
import { ownershipVideoRouter } from './ownership'
import { VideoFilter } from '../../../../shared/models/videos/video-query.type'
-import { buildNSFWFilter, createReqFiles } from '../../../helpers/express-utils'
+import { buildNSFWFilter, createReqFiles, getCountVideos } from '../../../helpers/express-utils'
import { ScheduleVideoUpdateModel } from '../../../models/video/schedule-video-update'
import { videoCaptionsRouter } from './captions'
import { videoImportsRouter } from './import'
}
async function listVideos (req: express.Request, res: express.Response) {
+ const countVideos = getCountVideos(req)
+
const apiOptions = await Hooks.wrapObject({
start: req.query.start,
count: req.query.count,
nsfw: buildNSFWFilter(res, req.query.nsfw),
filter: req.query.filter as VideoFilter,
withFiles: false,
- user: res.locals.oauth ? res.locals.oauth.token.User : undefined
+ user: res.locals.oauth ? res.locals.oauth.token.User : undefined,
+ countVideos
}, 'filter:api.videos.list.params')
const resultList = await Hooks.wrapPromiseFun(
}
async function getSitemapLocalVideoUrls () {
- const resultList = await VideoModel.listForApi({
+ const { data } = await VideoModel.listForApi({
start: 0,
count: undefined,
sort: 'createdAt',
includeLocalVideos: true,
nsfw: buildNSFWFilter(),
filter: 'local',
- withFiles: false
+ withFiles: false,
+ countVideos: false
})
- return resultList.data.map(v => ({
+ return data.map(v => ({
url: WEBSERVER.URL + '/videos/watch/' + v.uuid,
video: [
{
(CONFIG.SEARCH.REMOTE_URI.USERS === true && user !== undefined)
}
+function getCountVideos (req: express.Request) {
+ return req.query.skipCount !== true
+}
+
// ---------------------------------------------------------------------------
export {
isUserAbleToSearchRemoteURI,
badRequest,
createReqFiles,
- cleanUpReqFiles
+ cleanUpReqFiles,
+ getCountVideos
}
query('filter')
.optional()
.custom(isVideoFilterValid).withMessage('Should have a valid filter attribute'),
+ query('skipCount')
+ .optional()
+ .customSanitizer(toBooleanOrNull)
+ .custom(isBooleanValid).withMessage('Should have a valid skip count boolean'),
(req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking commons video filters query', { parameters: req.query })
videoPlaylistId?: number,
trendingDays?: number,
user?: MUserAccountId,
- historyOfUser?: MUserId
- }, countVideos = true) {
+ historyOfUser?: MUserId,
+ countVideos?: boolean
+ }) {
if (options.filter && options.filter === 'all-local' && !options.user.hasRight(UserRight.SEE_ALL_VIDEOS)) {
throw new Error('Try to filter all-local but no user has not the see all videos right')
}
trendingDays
}
- return VideoModel.getAvailableForApi(query, queryOptions, countVideos)
+ return VideoModel.getAvailableForApi(query, queryOptions, options.countVideos)
}
static async searchAndPopulateAccountAndServer (options: {
let server: ServerInfo
let userAccessToken: string
let moderatorAccessToken: string
- let playlistUUID: string
// ---------------------------------------------------------------
await checkBadSortPagination(server.url, path)
})
+ it('Should fail with a bad skipVideos query', async function () {
+ await makeGetRequest({ url: server.url, path, statusCodeExpected: 200, query: { skipCount: 'toto' } })
+ })
+
it('Should success with the correct parameters', async function () {
- await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 })
+ await makeGetRequest({ url: server.url, path, statusCodeExpected: 200, query: { skipCount: false } })
})
})
expect(videos[0].name).to.equal(videosListBase[5].name)
})
+ it('Should not have the total field', async function () {
+ const res = await getVideosListPagination(server.url, 5, 6, 'name', true)
+
+ const videos = res.body.data
+ expect(res.body.total).to.not.exist
+ expect(videos.length).to.equal(1)
+ expect(videos[0].name).to.equal(videosListBase[5].name)
+ })
+
it('Should list and sort by name in descending order', async function () {
const res = await getVideosListSort(server.url, '-name')
})
}
-function getVideosListPagination (url: string, start: number, count: number, sort?: string) {
+function getVideosListPagination (url: string, start: number, count: number, sort?: string, skipCount?: boolean) {
const path = '/api/v1/videos'
const req = request(url)
.query({ count: count })
if (sort) req.query({ sort })
+ if (skipCount) req.query({ skipCount })
return req.set('Accept', 'application/json')
.expect(200)