aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api')
-rw-r--r--server/controllers/api/accounts.ts15
-rw-r--r--server/controllers/api/users/me.ts3
-rw-r--r--server/controllers/api/users/my-subscriptions.ts19
-rw-r--r--server/controllers/api/video-channel.ts41
-rw-r--r--server/controllers/api/videos/index.ts54
5 files changed, 68 insertions, 64 deletions
diff --git a/server/controllers/api/accounts.ts b/server/controllers/api/accounts.ts
index b1c05c6c0..0a73dfcbf 100644
--- a/server/controllers/api/accounts.ts
+++ b/server/controllers/api/accounts.ts
@@ -1,5 +1,8 @@
1import * as express from 'express' 1import * as express from 'express'
2import { getServerActor } from '@server/models/application/application'
3import { buildNSFWFilter, getCountVideos, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils'
2import { getFormattedObjects } from '../../helpers/utils' 4import { getFormattedObjects } from '../../helpers/utils'
5import { JobQueue } from '../../lib/job-queue'
3import { 6import {
4 asyncMiddleware, 7 asyncMiddleware,
5 authenticate, 8 authenticate,
@@ -8,6 +11,7 @@ import {
8 paginationValidator, 11 paginationValidator,
9 setDefaultPagination, 12 setDefaultPagination,
10 setDefaultSort, 13 setDefaultSort,
14 setDefaultVideosSort,
11 videoPlaylistsSortValidator, 15 videoPlaylistsSortValidator,
12 videoRatesSortValidator, 16 videoRatesSortValidator,
13 videoRatingValidator 17 videoRatingValidator
@@ -17,18 +21,15 @@ import {
17 accountsSortValidator, 21 accountsSortValidator,
18 ensureAuthUserOwnsAccountValidator, 22 ensureAuthUserOwnsAccountValidator,
19 videoChannelsSortValidator, 23 videoChannelsSortValidator,
20 videosSortValidator, 24 videoChannelStatsValidator,
21 videoChannelStatsValidator 25 videosSortValidator
22} from '../../middlewares/validators' 26} from '../../middlewares/validators'
27import { commonVideoPlaylistFiltersValidator, videoPlaylistsSearchValidator } from '../../middlewares/validators/videos/video-playlists'
23import { AccountModel } from '../../models/account/account' 28import { AccountModel } from '../../models/account/account'
24import { AccountVideoRateModel } from '../../models/account/account-video-rate' 29import { AccountVideoRateModel } from '../../models/account/account-video-rate'
25import { VideoModel } from '../../models/video/video' 30import { VideoModel } from '../../models/video/video'
26import { buildNSFWFilter, getCountVideos, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils'
27import { VideoChannelModel } from '../../models/video/video-channel' 31import { VideoChannelModel } from '../../models/video/video-channel'
28import { JobQueue } from '../../lib/job-queue'
29import { VideoPlaylistModel } from '../../models/video/video-playlist' 32import { VideoPlaylistModel } from '../../models/video/video-playlist'
30import { commonVideoPlaylistFiltersValidator, videoPlaylistsSearchValidator } from '../../middlewares/validators/videos/video-playlists'
31import { getServerActor } from '@server/models/application/application'
32 33
33const accountsRouter = express.Router() 34const accountsRouter = express.Router()
34 35
@@ -49,7 +50,7 @@ accountsRouter.get('/:accountName/videos',
49 asyncMiddleware(accountNameWithHostGetValidator), 50 asyncMiddleware(accountNameWithHostGetValidator),
50 paginationValidator, 51 paginationValidator,
51 videosSortValidator, 52 videosSortValidator,
52 setDefaultSort, 53 setDefaultVideosSort,
53 setDefaultPagination, 54 setDefaultPagination,
54 optionalAuthenticate, 55 optionalAuthenticate,
55 commonVideosFiltersValidator, 56 commonVideosFiltersValidator,
diff --git a/server/controllers/api/users/me.ts b/server/controllers/api/users/me.ts
index 914c52e27..ba60a3d2a 100644
--- a/server/controllers/api/users/me.ts
+++ b/server/controllers/api/users/me.ts
@@ -17,6 +17,7 @@ import {
17 paginationValidator, 17 paginationValidator,
18 setDefaultPagination, 18 setDefaultPagination,
19 setDefaultSort, 19 setDefaultSort,
20 setDefaultVideosSort,
20 usersUpdateMeValidator, 21 usersUpdateMeValidator,
21 usersVideoRatingValidator 22 usersVideoRatingValidator
22} from '../../../middlewares' 23} from '../../../middlewares'
@@ -60,7 +61,7 @@ meRouter.get('/me/videos',
60 authenticate, 61 authenticate,
61 paginationValidator, 62 paginationValidator,
62 videosSortValidator, 63 videosSortValidator,
63 setDefaultSort, 64 setDefaultVideosSort,
64 setDefaultPagination, 65 setDefaultPagination,
65 asyncMiddleware(getUserVideos) 66 asyncMiddleware(getUserVideos)
66) 67)
diff --git a/server/controllers/api/users/my-subscriptions.ts b/server/controllers/api/users/my-subscriptions.ts
index 8b88feaf3..b8c234eef 100644
--- a/server/controllers/api/users/my-subscriptions.ts
+++ b/server/controllers/api/users/my-subscriptions.ts
@@ -1,7 +1,11 @@
1import * as express from 'express'
2import 'multer' 1import 'multer'
2import * as express from 'express'
3import { VideoFilter } from '../../../../shared/models/videos/video-query.type'
4import { buildNSFWFilter, getCountVideos } from '../../../helpers/express-utils'
3import { getFormattedObjects } from '../../../helpers/utils' 5import { getFormattedObjects } from '../../../helpers/utils'
4import { WEBSERVER } from '../../../initializers/constants' 6import { WEBSERVER } from '../../../initializers/constants'
7import { sequelizeTypescript } from '../../../initializers/database'
8import { JobQueue } from '../../../lib/job-queue'
5import { 9import {
6 asyncMiddleware, 10 asyncMiddleware,
7 asyncRetryTransactionMiddleware, 11 asyncRetryTransactionMiddleware,
@@ -10,21 +14,18 @@ import {
10 paginationValidator, 14 paginationValidator,
11 setDefaultPagination, 15 setDefaultPagination,
12 setDefaultSort, 16 setDefaultSort,
17 setDefaultVideosSort,
13 userSubscriptionAddValidator, 18 userSubscriptionAddValidator,
14 userSubscriptionGetValidator 19 userSubscriptionGetValidator
15} from '../../../middlewares' 20} from '../../../middlewares'
16import { 21import {
17 areSubscriptionsExistValidator, 22 areSubscriptionsExistValidator,
23 userSubscriptionListValidator,
18 userSubscriptionsSortValidator, 24 userSubscriptionsSortValidator,
19 videosSortValidator, 25 videosSortValidator
20 userSubscriptionListValidator
21} from '../../../middlewares/validators' 26} from '../../../middlewares/validators'
22import { VideoModel } from '../../../models/video/video'
23import { buildNSFWFilter, getCountVideos } from '../../../helpers/express-utils'
24import { VideoFilter } from '../../../../shared/models/videos/video-query.type'
25import { ActorFollowModel } from '../../../models/activitypub/actor-follow' 27import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
26import { JobQueue } from '../../../lib/job-queue' 28import { VideoModel } from '../../../models/video/video'
27import { sequelizeTypescript } from '../../../initializers/database'
28 29
29const mySubscriptionsRouter = express.Router() 30const mySubscriptionsRouter = express.Router()
30 31
@@ -32,7 +33,7 @@ mySubscriptionsRouter.get('/me/subscriptions/videos',
32 authenticate, 33 authenticate,
33 paginationValidator, 34 paginationValidator,
34 videosSortValidator, 35 videosSortValidator,
35 setDefaultSort, 36 setDefaultVideosSort,
36 setDefaultPagination, 37 setDefaultPagination,
37 commonVideosFiltersValidator, 38 commonVideosFiltersValidator,
38 asyncMiddleware(getUserSubscriptionVideos) 39 asyncMiddleware(getUserSubscriptionVideos)
diff --git a/server/controllers/api/video-channel.ts b/server/controllers/api/video-channel.ts
index f705034fd..45c936978 100644
--- a/server/controllers/api/video-channel.ts
+++ b/server/controllers/api/video-channel.ts
@@ -1,5 +1,20 @@
1import * as express from 'express' 1import * as express from 'express'
2import { getServerActor } from '@server/models/application/application'
3import { MChannelAccountDefault } from '@server/types/models'
4import { VideoChannelCreate, VideoChannelUpdate } from '../../../shared'
5import { auditLoggerFactory, getAuditIdFromRes, VideoChannelAuditView } from '../../helpers/audit-logger'
6import { resetSequelizeInstance } from '../../helpers/database-utils'
7import { buildNSFWFilter, createReqFiles, getCountVideos, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils'
8import { logger } from '../../helpers/logger'
2import { getFormattedObjects } from '../../helpers/utils' 9import { getFormattedObjects } from '../../helpers/utils'
10import { CONFIG } from '../../initializers/config'
11import { MIMETYPES } from '../../initializers/constants'
12import { sequelizeTypescript } from '../../initializers/database'
13import { setAsyncActorKeys } from '../../lib/activitypub/actor'
14import { sendUpdateActor } from '../../lib/activitypub/send'
15import { updateActorAvatarFile } from '../../lib/avatar'
16import { JobQueue } from '../../lib/job-queue'
17import { createLocalVideoChannel, federateAllVideosOfChannel } from '../../lib/video-channel'
3import { 18import {
4 asyncMiddleware, 19 asyncMiddleware,
5 asyncRetryTransactionMiddleware, 20 asyncRetryTransactionMiddleware,
@@ -9,34 +24,20 @@ import {
9 paginationValidator, 24 paginationValidator,
10 setDefaultPagination, 25 setDefaultPagination,
11 setDefaultSort, 26 setDefaultSort,
27 setDefaultVideosSort,
12 videoChannelsAddValidator, 28 videoChannelsAddValidator,
13 videoChannelsRemoveValidator, 29 videoChannelsRemoveValidator,
14 videoChannelsSortValidator, 30 videoChannelsSortValidator,
15 videoChannelsUpdateValidator, 31 videoChannelsUpdateValidator,
16 videoPlaylistsSortValidator 32 videoPlaylistsSortValidator
17} from '../../middlewares' 33} from '../../middlewares'
18import { VideoChannelModel } from '../../models/video/video-channel' 34import { videoChannelsNameWithHostValidator, videoChannelsOwnSearchValidator, videosSortValidator } from '../../middlewares/validators'
19import { videoChannelsNameWithHostValidator, videosSortValidator, videoChannelsOwnSearchValidator } from '../../middlewares/validators' 35import { updateAvatarValidator } from '../../middlewares/validators/avatar'
20import { sendUpdateActor } from '../../lib/activitypub/send' 36import { commonVideoPlaylistFiltersValidator } from '../../middlewares/validators/videos/video-playlists'
21import { VideoChannelCreate, VideoChannelUpdate } from '../../../shared'
22import { createLocalVideoChannel, federateAllVideosOfChannel } from '../../lib/video-channel'
23import { buildNSFWFilter, createReqFiles, getCountVideos, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils'
24import { setAsyncActorKeys } from '../../lib/activitypub/actor'
25import { AccountModel } from '../../models/account/account' 37import { AccountModel } from '../../models/account/account'
26import { MIMETYPES } from '../../initializers/constants'
27import { logger } from '../../helpers/logger'
28import { VideoModel } from '../../models/video/video' 38import { VideoModel } from '../../models/video/video'
29import { updateAvatarValidator } from '../../middlewares/validators/avatar' 39import { VideoChannelModel } from '../../models/video/video-channel'
30import { updateActorAvatarFile } from '../../lib/avatar'
31import { auditLoggerFactory, getAuditIdFromRes, VideoChannelAuditView } from '../../helpers/audit-logger'
32import { resetSequelizeInstance } from '../../helpers/database-utils'
33import { JobQueue } from '../../lib/job-queue'
34import { VideoPlaylistModel } from '../../models/video/video-playlist' 40import { VideoPlaylistModel } from '../../models/video/video-playlist'
35import { commonVideoPlaylistFiltersValidator } from '../../middlewares/validators/videos/video-playlists'
36import { CONFIG } from '../../initializers/config'
37import { sequelizeTypescript } from '../../initializers/database'
38import { MChannelAccountDefault } from '@server/types/models'
39import { getServerActor } from '@server/models/application/application'
40 41
41const auditLogger = auditLoggerFactory('channels') 42const auditLogger = auditLoggerFactory('channels')
42const reqAvatarFile = createReqFiles([ 'avatarfile' ], MIMETYPES.IMAGE.MIMETYPE_EXT, { avatarfile: CONFIG.STORAGE.TMP_DIR }) 43const reqAvatarFile = createReqFiles([ 'avatarfile' ], MIMETYPES.IMAGE.MIMETYPE_EXT, { avatarfile: CONFIG.STORAGE.TMP_DIR })
@@ -98,7 +99,7 @@ videoChannelRouter.get('/:nameWithHost/videos',
98 asyncMiddleware(videoChannelsNameWithHostValidator), 99 asyncMiddleware(videoChannelsNameWithHostValidator),
99 paginationValidator, 100 paginationValidator,
100 videosSortValidator, 101 videosSortValidator,
101 setDefaultSort, 102 setDefaultVideosSort,
102 setDefaultPagination, 103 setDefaultPagination,
103 optionalAuthenticate, 104 optionalAuthenticate,
104 commonVideosFiltersValidator, 105 commonVideosFiltersValidator,
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts
index 1dfd7c7a0..c05acfd2f 100644
--- a/server/controllers/api/videos/index.ts
+++ b/server/controllers/api/videos/index.ts
@@ -1,11 +1,24 @@
1import * as express from 'express' 1import * as express from 'express'
2import { move } from 'fs-extra'
2import { extname } from 'path' 3import { extname } from 'path'
4import toInt from 'validator/lib/toInt'
5import { addOptimizeOrMergeAudioJob } from '@server/helpers/video'
6import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent'
7import { changeVideoChannelShare } from '@server/lib/activitypub/share'
8import { getVideoActivityPubUrl } from '@server/lib/activitypub/url'
9import { getVideoFilePath } from '@server/lib/video-paths'
10import { getServerActor } from '@server/models/application/application'
11import { MVideoDetails, MVideoFullLight } from '@server/types/models'
3import { VideoCreate, VideoPrivacy, VideoState, VideoUpdate } from '../../../../shared' 12import { VideoCreate, VideoPrivacy, VideoState, VideoUpdate } from '../../../../shared'
13import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type'
14import { VideoFilter } from '../../../../shared/models/videos/video-query.type'
15import { auditLoggerFactory, getAuditIdFromRes, VideoAuditView } from '../../../helpers/audit-logger'
16import { resetSequelizeInstance } from '../../../helpers/database-utils'
17import { buildNSFWFilter, createReqFiles, getCountVideos } from '../../../helpers/express-utils'
4import { getMetadataFromFile, getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffmpeg-utils' 18import { getMetadataFromFile, getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffmpeg-utils'
5import { logger } from '../../../helpers/logger' 19import { logger } from '../../../helpers/logger'
6import { auditLoggerFactory, getAuditIdFromRes, VideoAuditView } from '../../../helpers/audit-logger'
7import { getFormattedObjects } from '../../../helpers/utils' 20import { getFormattedObjects } from '../../../helpers/utils'
8import { autoBlacklistVideoIfNeeded } from '../../../lib/video-blacklist' 21import { CONFIG } from '../../../initializers/config'
9import { 22import {
10 DEFAULT_AUDIO_RESOLUTION, 23 DEFAULT_AUDIO_RESOLUTION,
11 MIMETYPES, 24 MIMETYPES,
@@ -14,9 +27,15 @@ import {
14 VIDEO_LICENCES, 27 VIDEO_LICENCES,
15 VIDEO_PRIVACIES 28 VIDEO_PRIVACIES
16} from '../../../initializers/constants' 29} from '../../../initializers/constants'
30import { sequelizeTypescript } from '../../../initializers/database'
31import { sendView } from '../../../lib/activitypub/send/send-view'
17import { federateVideoIfNeeded, fetchRemoteVideoDescription } from '../../../lib/activitypub/videos' 32import { federateVideoIfNeeded, fetchRemoteVideoDescription } from '../../../lib/activitypub/videos'
18import { JobQueue } from '../../../lib/job-queue' 33import { JobQueue } from '../../../lib/job-queue'
34import { Notifier } from '../../../lib/notifier'
35import { Hooks } from '../../../lib/plugins/hooks'
19import { Redis } from '../../../lib/redis' 36import { Redis } from '../../../lib/redis'
37import { createVideoMiniatureFromExisting, generateVideoMiniature } from '../../../lib/thumbnail'
38import { autoBlacklistVideoIfNeeded } from '../../../lib/video-blacklist'
20import { 39import {
21 asyncMiddleware, 40 asyncMiddleware,
22 asyncRetryTransactionMiddleware, 41 asyncRetryTransactionMiddleware,
@@ -26,7 +45,7 @@ import {
26 optionalAuthenticate, 45 optionalAuthenticate,
27 paginationValidator, 46 paginationValidator,
28 setDefaultPagination, 47 setDefaultPagination,
29 setDefaultSort, 48 setDefaultVideosSort,
30 videoFileMetadataGetValidator, 49 videoFileMetadataGetValidator,
31 videosAddValidator, 50 videosAddValidator,
32 videosCustomGetValidator, 51 videosCustomGetValidator,
@@ -35,37 +54,18 @@ import {
35 videosSortValidator, 54 videosSortValidator,
36 videosUpdateValidator 55 videosUpdateValidator
37} from '../../../middlewares' 56} from '../../../middlewares'
57import { ScheduleVideoUpdateModel } from '../../../models/video/schedule-video-update'
38import { TagModel } from '../../../models/video/tag' 58import { TagModel } from '../../../models/video/tag'
39import { VideoModel } from '../../../models/video/video' 59import { VideoModel } from '../../../models/video/video'
40import { VideoFileModel } from '../../../models/video/video-file' 60import { VideoFileModel } from '../../../models/video/video-file'
41import { abuseVideoRouter } from './abuse' 61import { abuseVideoRouter } from './abuse'
42import { blacklistRouter } from './blacklist' 62import { blacklistRouter } from './blacklist'
43import { videoCommentRouter } from './comment'
44import { rateVideoRouter } from './rate'
45import { ownershipVideoRouter } from './ownership'
46import { VideoFilter } from '../../../../shared/models/videos/video-query.type'
47import { buildNSFWFilter, createReqFiles, getCountVideos } from '../../../helpers/express-utils'
48import { ScheduleVideoUpdateModel } from '../../../models/video/schedule-video-update'
49import { videoCaptionsRouter } from './captions' 63import { videoCaptionsRouter } from './captions'
64import { videoCommentRouter } from './comment'
50import { videoImportsRouter } from './import' 65import { videoImportsRouter } from './import'
51import { resetSequelizeInstance } from '../../../helpers/database-utils' 66import { ownershipVideoRouter } from './ownership'
52import { move } from 'fs-extra' 67import { rateVideoRouter } from './rate'
53import { watchingRouter } from './watching' 68import { watchingRouter } from './watching'
54import { Notifier } from '../../../lib/notifier'
55import { sendView } from '../../../lib/activitypub/send/send-view'
56import { CONFIG } from '../../../initializers/config'
57import { sequelizeTypescript } from '../../../initializers/database'
58import { createVideoMiniatureFromExisting, generateVideoMiniature } from '../../../lib/thumbnail'
59import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type'
60import { Hooks } from '../../../lib/plugins/hooks'
61import { MVideoDetails, MVideoFullLight } from '@server/types/models'
62import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent'
63import { getVideoFilePath } from '@server/lib/video-paths'
64import toInt from 'validator/lib/toInt'
65import { addOptimizeOrMergeAudioJob } from '@server/helpers/video'
66import { getServerActor } from '@server/models/application/application'
67import { changeVideoChannelShare } from '@server/lib/activitypub/share'
68import { getVideoActivityPubUrl } from '@server/lib/activitypub/url'
69 69
70const auditLogger = auditLoggerFactory('videos') 70const auditLogger = auditLoggerFactory('videos')
71const videosRouter = express.Router() 71const videosRouter = express.Router()
@@ -105,7 +105,7 @@ videosRouter.get('/privacies', listVideoPrivacies)
105videosRouter.get('/', 105videosRouter.get('/',
106 paginationValidator, 106 paginationValidator,
107 videosSortValidator, 107 videosSortValidator,
108 setDefaultSort, 108 setDefaultVideosSort,
109 setDefaultPagination, 109 setDefaultPagination,
110 optionalAuthenticate, 110 optionalAuthenticate,
111 commonVideosFiltersValidator, 111 commonVideosFiltersValidator,