From 1fd61899eaea245a5844e33e21f04b2562f16e5e Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 3 May 2021 11:06:19 +0200 Subject: Add ability to filter my videos by live --- server/controllers/api/accounts.ts | 27 +++++++++++++----------- server/controllers/api/users/me.ts | 3 ++- server/controllers/api/users/my-subscriptions.ts | 23 ++++++++++---------- server/controllers/api/video-channel.ts | 23 ++++++++++---------- server/controllers/api/videos/index.ts | 25 +++++++++++----------- 5 files changed, 54 insertions(+), 47 deletions(-) (limited to 'server/controllers/api') diff --git a/server/controllers/api/accounts.ts b/server/controllers/api/accounts.ts index e31924a94..49a8e3195 100644 --- a/server/controllers/api/accounts.ts +++ b/server/controllers/api/accounts.ts @@ -1,9 +1,10 @@ import * as express from 'express' import { getServerActor } from '@server/models/application/application' +import { VideosWithSearchCommonQuery } from '@shared/models' import { buildNSFWFilter, getCountVideos, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils' import { getFormattedObjects } from '../../helpers/utils' -import { Hooks } from '../../lib/plugins/hooks' import { JobQueue } from '../../lib/job-queue' +import { Hooks } from '../../lib/plugins/hooks' import { asyncMiddleware, authenticate, @@ -158,25 +159,27 @@ 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 query = req.query as VideosWithSearchCommonQuery const apiOptions = await Hooks.wrapObject({ followerActorId, - start: req.query.start, - count: req.query.count, - sort: req.query.sort, + start: query.start, + count: query.count, + sort: query.sort, includeLocalVideos: true, - categoryOneOf: req.query.categoryOneOf, - licenceOneOf: req.query.licenceOneOf, - languageOneOf: req.query.languageOneOf, - tagsOneOf: req.query.tagsOneOf, - tagsAllOf: req.query.tagsAllOf, - filter: req.query.filter, - nsfw: buildNSFWFilter(res, req.query.nsfw), + categoryOneOf: query.categoryOneOf, + licenceOneOf: query.licenceOneOf, + languageOneOf: query.languageOneOf, + tagsOneOf: query.tagsOneOf, + tagsAllOf: query.tagsAllOf, + filter: query.filter, + isLive: query.isLive, + nsfw: buildNSFWFilter(res, query.nsfw), withFiles: false, accountId: account.id, user: res.locals.oauth ? res.locals.oauth.token.User : undefined, countVideos, - search: req.query.search + search: query.search }, 'filter:api.accounts.videos.list.params') const resultList = await Hooks.wrapPromiseFun( diff --git a/server/controllers/api/users/me.ts b/server/controllers/api/users/me.ts index 9f9d2d77f..0763d1900 100644 --- a/server/controllers/api/users/me.ts +++ b/server/controllers/api/users/me.ts @@ -111,7 +111,8 @@ async function getUserVideos (req: express.Request, res: express.Response) { start: req.query.start, count: req.query.count, sort: req.query.sort, - search: req.query.search + search: req.query.search, + isLive: req.query.isLive }, 'filter:api.user.me.videos.list.params') const resultList = await Hooks.wrapPromiseFun( diff --git a/server/controllers/api/users/my-subscriptions.ts b/server/controllers/api/users/my-subscriptions.ts index e8949ee59..56b93276f 100644 --- a/server/controllers/api/users/my-subscriptions.ts +++ b/server/controllers/api/users/my-subscriptions.ts @@ -2,8 +2,8 @@ import 'multer' import * as express from 'express' import { sendUndoFollow } from '@server/lib/activitypub/send' import { VideoChannelModel } from '@server/models/video/video-channel' +import { VideosCommonQuery } from '@shared/models' import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' -import { VideoFilter } from '../../../../shared/models/videos/video-query.type' import { buildNSFWFilter, getCountVideos } from '../../../helpers/express-utils' import { getFormattedObjects } from '../../../helpers/utils' import { WEBSERVER } from '../../../initializers/constants' @@ -170,19 +170,20 @@ async function getUserSubscriptions (req: express.Request, res: express.Response async function getUserSubscriptionVideos (req: express.Request, res: express.Response) { const user = res.locals.oauth.token.User const countVideos = getCountVideos(req) + const query = req.query as VideosCommonQuery const resultList = await VideoModel.listForApi({ - start: req.query.start, - count: req.query.count, - sort: req.query.sort, + start: query.start, + count: query.count, + sort: query.sort, includeLocalVideos: false, - 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, + categoryOneOf: query.categoryOneOf, + licenceOneOf: query.licenceOneOf, + languageOneOf: query.languageOneOf, + tagsOneOf: query.tagsOneOf, + tagsAllOf: query.tagsAllOf, + nsfw: buildNSFWFilter(res, query.nsfw), + filter: query.filter, withFiles: false, followerActorId: user.Account.Actor.id, user, diff --git a/server/controllers/api/video-channel.ts b/server/controllers/api/video-channel.ts index 149d6cfb4..a755d7e57 100644 --- a/server/controllers/api/video-channel.ts +++ b/server/controllers/api/video-channel.ts @@ -2,7 +2,7 @@ import * as express from 'express' import { Hooks } from '@server/lib/plugins/hooks' import { getServerActor } from '@server/models/application/application' import { MChannelBannerAccountDefault } from '@server/types/models' -import { ActorImageType, VideoChannelCreate, VideoChannelUpdate } from '../../../shared' +import { ActorImageType, VideoChannelCreate, VideoChannelUpdate, VideosCommonQuery } from '../../../shared' import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' import { auditLoggerFactory, getAuditIdFromRes, VideoChannelAuditView } from '../../helpers/audit-logger' import { resetSequelizeInstance } from '../../helpers/database-utils' @@ -312,20 +312,21 @@ async function listVideoChannelVideos (req: express.Request, res: express.Respon const videoChannelInstance = res.locals.videoChannel const followerActorId = isUserAbleToSearchRemoteURI(res) ? null : undefined const countVideos = getCountVideos(req) + const query = req.query as VideosCommonQuery const apiOptions = await Hooks.wrapObject({ followerActorId, - start: req.query.start, - count: req.query.count, - sort: req.query.sort, + start: query.start, + count: query.count, + sort: query.sort, includeLocalVideos: true, - categoryOneOf: req.query.categoryOneOf, - licenceOneOf: req.query.licenceOneOf, - languageOneOf: req.query.languageOneOf, - tagsOneOf: req.query.tagsOneOf, - tagsAllOf: req.query.tagsAllOf, - filter: req.query.filter, - nsfw: buildNSFWFilter(res, req.query.nsfw), + categoryOneOf: query.categoryOneOf, + licenceOneOf: query.licenceOneOf, + languageOneOf: query.languageOneOf, + tagsOneOf: query.tagsOneOf, + tagsAllOf: query.tagsAllOf, + filter: query.filter, + nsfw: buildNSFWFilter(res, query.nsfw), withFiles: false, videoChannelId: videoChannelInstance.id, user: res.locals.oauth ? res.locals.oauth.token.User : undefined, diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index 7fee278f2..6ec6478e4 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts @@ -10,9 +10,8 @@ import { addOptimizeOrMergeAudioJob, buildLocalVideoFromReq, buildVideoThumbnail import { generateVideoFilename, getVideoFilePath } from '@server/lib/video-paths' import { getServerActor } from '@server/models/application/application' import { MVideo, MVideoFile, MVideoFullLight } from '@server/types/models' -import { VideoCreate, VideoState, VideoUpdate } from '../../../../shared' +import { VideoCreate, VideosCommonQuery, VideoState, VideoUpdate } from '../../../../shared' import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' -import { VideoFilter } from '../../../../shared/models/videos/video-query.type' import { auditLoggerFactory, getAuditIdFromRes, VideoAuditView } from '../../../helpers/audit-logger' import { resetSequelizeInstance, retryTransactionWrapper } from '../../../helpers/database-utils' import { buildNSFWFilter, createReqFiles, getCountVideos } from '../../../helpers/express-utils' @@ -494,20 +493,22 @@ async function getVideoFileMetadata (req: express.Request, res: express.Response } async function listVideos (req: express.Request, res: express.Response) { + const query = req.query as VideosCommonQuery const countVideos = getCountVideos(req) const apiOptions = await Hooks.wrapObject({ - start: req.query.start, - count: req.query.count, - sort: req.query.sort, + start: query.start, + count: query.count, + sort: query.sort, includeLocalVideos: true, - 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, + categoryOneOf: query.categoryOneOf, + licenceOneOf: query.licenceOneOf, + languageOneOf: query.languageOneOf, + tagsOneOf: query.tagsOneOf, + tagsAllOf: query.tagsAllOf, + nsfw: buildNSFWFilter(res, query.nsfw), + isLive: query.isLive, + filter: query.filter, withFiles: false, user: res.locals.oauth ? res.locals.oauth.token.User : undefined, countVideos -- cgit v1.2.3