diff options
Diffstat (limited to 'server/controllers')
49 files changed, 213 insertions, 229 deletions
diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.ts index d7de1b9bd..bef4bc068 100644 --- a/server/controllers/activitypub/client.ts +++ b/server/controllers/activitypub/client.ts | |||
@@ -24,7 +24,7 @@ import { | |||
24 | videosCustomGetValidator, | 24 | videosCustomGetValidator, |
25 | videosShareValidator | 25 | videosShareValidator |
26 | } from '../../middlewares' | 26 | } from '../../middlewares' |
27 | import { cacheRoute } from '../../middlewares/cache' | 27 | import { cacheRoute } from '../../middlewares/cache/cache' |
28 | import { getAccountVideoRateValidatorFactory, videoCommentGetValidator } from '../../middlewares/validators' | 28 | import { getAccountVideoRateValidatorFactory, videoCommentGetValidator } from '../../middlewares/validators' |
29 | import { videoFileRedundancyGetValidator, videoPlaylistRedundancyGetValidator } from '../../middlewares/validators/redundancy' | 29 | import { videoFileRedundancyGetValidator, videoPlaylistRedundancyGetValidator } from '../../middlewares/validators/redundancy' |
30 | import { videoPlaylistElementAPGetValidator, videoPlaylistsGetValidator } from '../../middlewares/validators/videos/video-playlists' | 30 | import { videoPlaylistElementAPGetValidator, videoPlaylistsGetValidator } from '../../middlewares/validators/videos/video-playlists' |
@@ -77,7 +77,7 @@ activityPubClientRouter.get('/accounts?/:name/dislikes/:videoId', | |||
77 | activityPubClientRouter.get( | 77 | activityPubClientRouter.get( |
78 | [ '/videos/watch/:id', '/w/:id' ], | 78 | [ '/videos/watch/:id', '/w/:id' ], |
79 | executeIfActivityPub, | 79 | executeIfActivityPub, |
80 | asyncMiddleware(cacheRoute()(ROUTE_CACHE_LIFETIME.ACTIVITY_PUB.VIDEOS)), | 80 | cacheRoute(ROUTE_CACHE_LIFETIME.ACTIVITY_PUB.VIDEOS), |
81 | asyncMiddleware(videosCustomGetValidator('all')), | 81 | asyncMiddleware(videosCustomGetValidator('all')), |
82 | asyncMiddleware(videoController) | 82 | asyncMiddleware(videoController) |
83 | ) | 83 | ) |
diff --git a/server/controllers/activitypub/inbox.ts b/server/controllers/activitypub/inbox.ts index 14f301ab7..30662990a 100644 --- a/server/controllers/activitypub/inbox.ts +++ b/server/controllers/activitypub/inbox.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { InboxManager } from '@server/lib/activitypub/inbox-manager' | 2 | import { InboxManager } from '@server/lib/activitypub/inbox-manager' |
3 | import { Activity, ActivityPubCollection, ActivityPubOrderedCollection, RootActivity } from '../../../shared' | 3 | import { Activity, ActivityPubCollection, ActivityPubOrderedCollection, RootActivity } from '../../../shared' |
4 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | 4 | import { HttpStatusCode } from '../../../shared/models/http/http-error-codes' |
5 | import { isActivityValid } from '../../helpers/custom-validators/activitypub/activity' | 5 | import { isActivityValid } from '../../helpers/custom-validators/activitypub/activity' |
6 | import { logger } from '../../helpers/logger' | 6 | import { logger } from '../../helpers/logger' |
7 | import { asyncMiddleware, checkSignature, localAccountValidator, localVideoChannelValidator, signatureValidator } from '../../middlewares' | 7 | import { asyncMiddleware, checkSignature, localAccountValidator, localVideoChannelValidator, signatureValidator } from '../../middlewares' |
diff --git a/server/controllers/api/abuse.ts b/server/controllers/api/abuse.ts index ba5b94840..e851365e9 100644 --- a/server/controllers/api/abuse.ts +++ b/server/controllers/api/abuse.ts | |||
@@ -6,7 +6,7 @@ import { AbuseModel } from '@server/models/abuse/abuse' | |||
6 | import { AbuseMessageModel } from '@server/models/abuse/abuse-message' | 6 | import { AbuseMessageModel } from '@server/models/abuse/abuse-message' |
7 | import { getServerActor } from '@server/models/application/application' | 7 | import { getServerActor } from '@server/models/application/application' |
8 | import { abusePredefinedReasonsMap } from '@shared/core-utils/abuse' | 8 | import { abusePredefinedReasonsMap } from '@shared/core-utils/abuse' |
9 | import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' | 9 | import { HttpStatusCode } from '@shared/models' |
10 | import { AbuseCreate, AbuseState, UserRight } from '../../../shared' | 10 | import { AbuseCreate, AbuseState, UserRight } from '../../../shared' |
11 | import { getFormattedObjects } from '../../helpers/utils' | 11 | import { getFormattedObjects } from '../../helpers/utils' |
12 | import { sequelizeTypescript } from '../../initializers/database' | 12 | import { sequelizeTypescript } from '../../initializers/database' |
diff --git a/server/controllers/api/accounts.ts b/server/controllers/api/accounts.ts index 49a8e3195..55e2aaf62 100644 --- a/server/controllers/api/accounts.ts +++ b/server/controllers/api/accounts.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { pickCommonVideoQuery } from '@server/helpers/query' | ||
2 | import { getServerActor } from '@server/models/application/application' | 3 | import { getServerActor } from '@server/models/application/application' |
3 | import { VideosWithSearchCommonQuery } from '@shared/models' | ||
4 | import { buildNSFWFilter, getCountVideos, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils' | 4 | import { buildNSFWFilter, getCountVideos, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils' |
5 | import { getFormattedObjects } from '../../helpers/utils' | 5 | import { getFormattedObjects } from '../../helpers/utils' |
6 | import { JobQueue } from '../../lib/job-queue' | 6 | import { JobQueue } from '../../lib/job-queue' |
@@ -159,27 +159,19 @@ async function listAccountVideos (req: express.Request, res: express.Response) { | |||
159 | const account = res.locals.account | 159 | const account = res.locals.account |
160 | const followerActorId = isUserAbleToSearchRemoteURI(res) ? null : undefined | 160 | const followerActorId = isUserAbleToSearchRemoteURI(res) ? null : undefined |
161 | const countVideos = getCountVideos(req) | 161 | const countVideos = getCountVideos(req) |
162 | const query = req.query as VideosWithSearchCommonQuery | 162 | const query = pickCommonVideoQuery(req.query) |
163 | 163 | ||
164 | const apiOptions = await Hooks.wrapObject({ | 164 | const apiOptions = await Hooks.wrapObject({ |
165 | ...query, | ||
166 | |||
165 | followerActorId, | 167 | followerActorId, |
166 | start: query.start, | 168 | search: req.query.search, |
167 | count: query.count, | ||
168 | sort: query.sort, | ||
169 | includeLocalVideos: true, | 169 | includeLocalVideos: true, |
170 | categoryOneOf: query.categoryOneOf, | ||
171 | licenceOneOf: query.licenceOneOf, | ||
172 | languageOneOf: query.languageOneOf, | ||
173 | tagsOneOf: query.tagsOneOf, | ||
174 | tagsAllOf: query.tagsAllOf, | ||
175 | filter: query.filter, | ||
176 | isLive: query.isLive, | ||
177 | nsfw: buildNSFWFilter(res, query.nsfw), | 170 | nsfw: buildNSFWFilter(res, query.nsfw), |
178 | withFiles: false, | 171 | withFiles: false, |
179 | accountId: account.id, | 172 | accountId: account.id, |
180 | user: res.locals.oauth ? res.locals.oauth.token.User : undefined, | 173 | user: res.locals.oauth ? res.locals.oauth.token.User : undefined, |
181 | countVideos, | 174 | countVideos |
182 | search: query.search | ||
183 | }, 'filter:api.accounts.videos.list.params') | 175 | }, 'filter:api.accounts.videos.list.params') |
184 | 176 | ||
185 | const resultList = await Hooks.wrapPromiseFun( | 177 | const resultList = await Hooks.wrapPromiseFun( |
diff --git a/server/controllers/api/bulk.ts b/server/controllers/api/bulk.ts index 192daccde..62121ece5 100644 --- a/server/controllers/api/bulk.ts +++ b/server/controllers/api/bulk.ts | |||
@@ -1,10 +1,10 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { asyncMiddleware, authenticate } from '../../middlewares' | 2 | import { removeComment } from '@server/lib/video-comment' |
3 | import { bulkRemoveCommentsOfValidator } from '@server/middlewares/validators/bulk' | 3 | import { bulkRemoveCommentsOfValidator } from '@server/middlewares/validators/bulk' |
4 | import { VideoCommentModel } from '@server/models/video/video-comment' | 4 | import { VideoCommentModel } from '@server/models/video/video-comment' |
5 | import { removeComment } from '@server/lib/video-comment' | 5 | import { HttpStatusCode } from '@shared/models' |
6 | import { BulkRemoveCommentsOfBody } from '@shared/models/bulk/bulk-remove-comments-of-body.model' | 6 | import { BulkRemoveCommentsOfBody } from '@shared/models/bulk/bulk-remove-comments-of-body.model' |
7 | import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' | 7 | import { asyncMiddleware, authenticate } from '../../middlewares' |
8 | 8 | ||
9 | const bulkRouter = express.Router() | 9 | const bulkRouter = express.Router() |
10 | 10 | ||
diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.ts index 9bd8c21c5..ee733a38c 100644 --- a/server/controllers/api/config.ts +++ b/server/controllers/api/config.ts | |||
@@ -1,8 +1,8 @@ | |||
1 | import { ServerConfigManager } from '@server/lib/server-config-manager' | ||
2 | import * as express from 'express' | 1 | import * as express from 'express' |
3 | import { remove, writeJSON } from 'fs-extra' | 2 | import { remove, writeJSON } from 'fs-extra' |
4 | import { snakeCase } from 'lodash' | 3 | import { snakeCase } from 'lodash' |
5 | import validator from 'validator' | 4 | import validator from 'validator' |
5 | import { ServerConfigManager } from '@server/lib/server-config-manager' | ||
6 | import { UserRight } from '../../../shared' | 6 | import { UserRight } from '../../../shared' |
7 | import { About } from '../../../shared/models/server/about.model' | 7 | import { About } from '../../../shared/models/server/about.model' |
8 | import { CustomConfig } from '../../../shared/models/server/custom-config.model' | 8 | import { CustomConfig } from '../../../shared/models/server/custom-config.model' |
diff --git a/server/controllers/api/custom-page.ts b/server/controllers/api/custom-page.ts index c19f03c56..68d8c2ea4 100644 --- a/server/controllers/api/custom-page.ts +++ b/server/controllers/api/custom-page.ts | |||
@@ -1,8 +1,7 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { ServerConfigManager } from '@server/lib/server-config-manager' | 2 | import { ServerConfigManager } from '@server/lib/server-config-manager' |
3 | import { ActorCustomPageModel } from '@server/models/account/actor-custom-page' | 3 | import { ActorCustomPageModel } from '@server/models/account/actor-custom-page' |
4 | import { HttpStatusCode } from '@shared/core-utils' | 4 | import { HttpStatusCode, UserRight } from '@shared/models' |
5 | import { UserRight } from '@shared/models' | ||
6 | import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../middlewares' | 5 | import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../middlewares' |
7 | 6 | ||
8 | const customPageRouter = express.Router() | 7 | const customPageRouter = express.Router() |
diff --git a/server/controllers/api/index.ts b/server/controllers/api/index.ts index 28378654a..93b14dadb 100644 --- a/server/controllers/api/index.ts +++ b/server/controllers/api/index.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import * as cors from 'cors' | 1 | import * as cors from 'cors' |
2 | import * as express from 'express' | 2 | import * as express from 'express' |
3 | import * as RateLimit from 'express-rate-limit' | 3 | import * as RateLimit from 'express-rate-limit' |
4 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | 4 | import { HttpStatusCode } from '../../../shared/models' |
5 | import { badRequest } from '../../helpers/express-utils' | 5 | import { badRequest } from '../../helpers/express-utils' |
6 | import { CONFIG } from '../../initializers/config' | 6 | import { CONFIG } from '../../initializers/config' |
7 | import { abuseRouter } from './abuse' | 7 | import { abuseRouter } from './abuse' |
diff --git a/server/controllers/api/oauth-clients.ts b/server/controllers/api/oauth-clients.ts index 15bbf5c4d..f95f06864 100644 --- a/server/controllers/api/oauth-clients.ts +++ b/server/controllers/api/oauth-clients.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { OAuthClientLocal } from '../../../shared' | 2 | import { OAuthClientLocal } from '../../../shared' |
3 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | 3 | import { HttpStatusCode } from '../../../shared/models/http/http-error-codes' |
4 | import { logger } from '../../helpers/logger' | 4 | import { logger } from '../../helpers/logger' |
5 | import { CONFIG } from '../../initializers/config' | 5 | import { CONFIG } from '../../initializers/config' |
6 | import { asyncMiddleware, openapiOperationDoc } from '../../middlewares' | 6 | import { asyncMiddleware, openapiOperationDoc } from '../../middlewares' |
diff --git a/server/controllers/api/overviews.ts b/server/controllers/api/overviews.ts index ad879aad6..2dfac15ef 100644 --- a/server/controllers/api/overviews.ts +++ b/server/controllers/api/overviews.ts | |||
@@ -1,12 +1,13 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import * as memoizee from 'memoizee' | ||
3 | import { logger } from '@server/helpers/logger' | ||
4 | import { Hooks } from '@server/lib/plugins/hooks' | ||
5 | import { VideoModel } from '@server/models/video/video' | ||
6 | import { CategoryOverview, ChannelOverview, TagOverview, VideosOverview } from '../../../shared/models/overviews' | ||
2 | import { buildNSFWFilter } from '../../helpers/express-utils' | 7 | import { buildNSFWFilter } from '../../helpers/express-utils' |
3 | import { VideoModel } from '../../models/video/video' | 8 | import { MEMOIZE_TTL, OVERVIEWS } from '../../initializers/constants' |
4 | import { asyncMiddleware, optionalAuthenticate, videosOverviewValidator } from '../../middlewares' | 9 | import { asyncMiddleware, optionalAuthenticate, videosOverviewValidator } from '../../middlewares' |
5 | import { TagModel } from '../../models/video/tag' | 10 | import { TagModel } from '../../models/video/tag' |
6 | import { CategoryOverview, ChannelOverview, TagOverview, VideosOverview } from '../../../shared/models/overviews' | ||
7 | import { MEMOIZE_TTL, OVERVIEWS } from '../../initializers/constants' | ||
8 | import * as memoizee from 'memoizee' | ||
9 | import { logger } from '@server/helpers/logger' | ||
10 | 11 | ||
11 | const overviewsRouter = express.Router() | 12 | const overviewsRouter = express.Router() |
12 | 13 | ||
@@ -108,7 +109,7 @@ async function getVideos ( | |||
108 | res: express.Response, | 109 | res: express.Response, |
109 | where: { videoChannelId?: number, tagsOneOf?: string[], categoryOneOf?: number[] } | 110 | where: { videoChannelId?: number, tagsOneOf?: string[], categoryOneOf?: number[] } |
110 | ) { | 111 | ) { |
111 | const query = Object.assign({ | 112 | const query = await Hooks.wrapObject({ |
112 | start: 0, | 113 | start: 0, |
113 | count: 12, | 114 | count: 12, |
114 | sort: '-createdAt', | 115 | sort: '-createdAt', |
@@ -116,10 +117,16 @@ async function getVideos ( | |||
116 | nsfw: buildNSFWFilter(res), | 117 | nsfw: buildNSFWFilter(res), |
117 | user: res.locals.oauth ? res.locals.oauth.token.User : undefined, | 118 | user: res.locals.oauth ? res.locals.oauth.token.User : undefined, |
118 | withFiles: false, | 119 | withFiles: false, |
119 | countVideos: false | 120 | countVideos: false, |
120 | }, where) | 121 | |
122 | ...where | ||
123 | }, 'filter:api.overviews.videos.list.params') | ||
121 | 124 | ||
122 | const { data } = await VideoModel.listForApi(query) | 125 | const { data } = await Hooks.wrapPromiseFun( |
126 | VideoModel.listForApi, | ||
127 | query, | ||
128 | 'filter:api.overviews.videos.list.result' | ||
129 | ) | ||
123 | 130 | ||
124 | return data.map(d => d.toFormattedJSON()) | 131 | return data.map(d => d.toFormattedJSON()) |
125 | } | 132 | } |
diff --git a/server/controllers/api/plugins.ts b/server/controllers/api/plugins.ts index 1e6a02c49..3a9ef34e8 100644 --- a/server/controllers/api/plugins.ts +++ b/server/controllers/api/plugins.ts | |||
@@ -23,8 +23,8 @@ import { | |||
23 | updatePluginSettingsValidator | 23 | updatePluginSettingsValidator |
24 | } from '@server/middlewares/validators/plugins' | 24 | } from '@server/middlewares/validators/plugins' |
25 | import { PluginModel } from '@server/models/server/plugin' | 25 | import { PluginModel } from '@server/models/server/plugin' |
26 | import { HttpStatusCode } from '@shared/core-utils' | ||
27 | import { | 26 | import { |
27 | HttpStatusCode, | ||
28 | InstallOrUpdatePlugin, | 28 | InstallOrUpdatePlugin, |
29 | ManagePlugin, | 29 | ManagePlugin, |
30 | PeertubePluginIndexList, | 30 | PeertubePluginIndexList, |
diff --git a/server/controllers/api/search/search-video-channels.ts b/server/controllers/api/search/search-video-channels.ts index 16beeed60..eef222506 100644 --- a/server/controllers/api/search/search-video-channels.ts +++ b/server/controllers/api/search/search-video-channels.ts | |||
@@ -1,14 +1,14 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { sanitizeUrl } from '@server/helpers/core-utils' | 2 | import { sanitizeUrl } from '@server/helpers/core-utils' |
3 | import { pickSearchChannelQuery } from '@server/helpers/query' | ||
3 | import { doJSONRequest } from '@server/helpers/requests' | 4 | import { doJSONRequest } from '@server/helpers/requests' |
4 | import { CONFIG } from '@server/initializers/config' | 5 | import { CONFIG } from '@server/initializers/config' |
5 | import { WEBSERVER } from '@server/initializers/constants' | 6 | import { WEBSERVER } from '@server/initializers/constants' |
6 | import { Hooks } from '@server/lib/plugins/hooks' | 7 | import { Hooks } from '@server/lib/plugins/hooks' |
7 | import { buildMutedForSearchIndex, isSearchIndexSearch, isURISearch } from '@server/lib/search' | 8 | import { buildMutedForSearchIndex, isSearchIndexSearch, isURISearch } from '@server/lib/search' |
8 | import { getServerActor } from '@server/models/application/application' | 9 | import { getServerActor } from '@server/models/application/application' |
9 | import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' | 10 | import { HttpStatusCode, ResultList, VideoChannel } from '@shared/models' |
10 | import { ResultList, VideoChannel } from '@shared/models' | 11 | import { VideoChannelsSearchQueryAfterSanitize } from '../../../../shared/models/search' |
11 | import { VideoChannelsSearchQuery } from '../../../../shared/models/search' | ||
12 | import { isUserAbleToSearchRemoteURI } from '../../../helpers/express-utils' | 12 | import { isUserAbleToSearchRemoteURI } from '../../../helpers/express-utils' |
13 | import { logger } from '../../../helpers/logger' | 13 | import { logger } from '../../../helpers/logger' |
14 | import { getFormattedObjects } from '../../../helpers/utils' | 14 | import { getFormattedObjects } from '../../../helpers/utils' |
@@ -46,8 +46,8 @@ export { searchChannelsRouter } | |||
46 | // --------------------------------------------------------------------------- | 46 | // --------------------------------------------------------------------------- |
47 | 47 | ||
48 | function searchVideoChannels (req: express.Request, res: express.Response) { | 48 | function searchVideoChannels (req: express.Request, res: express.Response) { |
49 | const query: VideoChannelsSearchQuery = req.query | 49 | const query = pickSearchChannelQuery(req.query) |
50 | const search = query.search | 50 | let search = query.search || '' |
51 | 51 | ||
52 | const parts = search.split('@') | 52 | const parts = search.split('@') |
53 | 53 | ||
@@ -58,7 +58,7 @@ function searchVideoChannels (req: express.Request, res: express.Response) { | |||
58 | if (isURISearch(search) || isWebfingerSearch) return searchVideoChannelURI(search, isWebfingerSearch, res) | 58 | if (isURISearch(search) || isWebfingerSearch) return searchVideoChannelURI(search, isWebfingerSearch, res) |
59 | 59 | ||
60 | // @username -> username to search in DB | 60 | // @username -> username to search in DB |
61 | if (query.search.startsWith('@')) query.search = query.search.replace(/^@/, '') | 61 | if (search.startsWith('@')) search = search.replace(/^@/, '') |
62 | 62 | ||
63 | if (isSearchIndexSearch(query)) { | 63 | if (isSearchIndexSearch(query)) { |
64 | return searchVideoChannelsIndex(query, res) | 64 | return searchVideoChannelsIndex(query, res) |
@@ -67,7 +67,7 @@ function searchVideoChannels (req: express.Request, res: express.Response) { | |||
67 | return searchVideoChannelsDB(query, res) | 67 | return searchVideoChannelsDB(query, res) |
68 | } | 68 | } |
69 | 69 | ||
70 | async function searchVideoChannelsIndex (query: VideoChannelsSearchQuery, res: express.Response) { | 70 | async function searchVideoChannelsIndex (query: VideoChannelsSearchQueryAfterSanitize, res: express.Response) { |
71 | const result = await buildMutedForSearchIndex(res) | 71 | const result = await buildMutedForSearchIndex(res) |
72 | 72 | ||
73 | const body = await Hooks.wrapObject(Object.assign(query, result), 'filter:api.search.video-channels.index.list.params') | 73 | const body = await Hooks.wrapObject(Object.assign(query, result), 'filter:api.search.video-channels.index.list.params') |
@@ -91,15 +91,13 @@ async function searchVideoChannelsIndex (query: VideoChannelsSearchQuery, res: e | |||
91 | } | 91 | } |
92 | } | 92 | } |
93 | 93 | ||
94 | async function searchVideoChannelsDB (query: VideoChannelsSearchQuery, res: express.Response) { | 94 | async function searchVideoChannelsDB (query: VideoChannelsSearchQueryAfterSanitize, res: express.Response) { |
95 | const serverActor = await getServerActor() | 95 | const serverActor = await getServerActor() |
96 | 96 | ||
97 | const apiOptions = await Hooks.wrapObject({ | 97 | const apiOptions = await Hooks.wrapObject({ |
98 | actorId: serverActor.id, | 98 | ...query, |
99 | search: query.search, | 99 | |
100 | start: query.start, | 100 | actorId: serverActor.id |
101 | count: query.count, | ||
102 | sort: query.sort | ||
103 | }, 'filter:api.search.video-channels.local.list.params') | 101 | }, 'filter:api.search.video-channels.local.list.params') |
104 | 102 | ||
105 | const resultList = await Hooks.wrapPromiseFun( | 103 | const resultList = await Hooks.wrapPromiseFun( |
diff --git a/server/controllers/api/search/search-video-playlists.ts b/server/controllers/api/search/search-video-playlists.ts index b231ff1e2..0a56f19b7 100644 --- a/server/controllers/api/search/search-video-playlists.ts +++ b/server/controllers/api/search/search-video-playlists.ts | |||
@@ -2,17 +2,18 @@ import * as express from 'express' | |||
2 | import { sanitizeUrl } from '@server/helpers/core-utils' | 2 | import { sanitizeUrl } from '@server/helpers/core-utils' |
3 | import { isUserAbleToSearchRemoteURI } from '@server/helpers/express-utils' | 3 | import { isUserAbleToSearchRemoteURI } from '@server/helpers/express-utils' |
4 | import { logger } from '@server/helpers/logger' | 4 | import { logger } from '@server/helpers/logger' |
5 | import { pickSearchPlaylistQuery } from '@server/helpers/query' | ||
5 | import { doJSONRequest } from '@server/helpers/requests' | 6 | import { doJSONRequest } from '@server/helpers/requests' |
6 | import { getFormattedObjects } from '@server/helpers/utils' | 7 | import { getFormattedObjects } from '@server/helpers/utils' |
7 | import { CONFIG } from '@server/initializers/config' | 8 | import { CONFIG } from '@server/initializers/config' |
9 | import { WEBSERVER } from '@server/initializers/constants' | ||
8 | import { getOrCreateAPVideoPlaylist } from '@server/lib/activitypub/playlists/get' | 10 | import { getOrCreateAPVideoPlaylist } from '@server/lib/activitypub/playlists/get' |
9 | import { Hooks } from '@server/lib/plugins/hooks' | 11 | import { Hooks } from '@server/lib/plugins/hooks' |
10 | import { buildMutedForSearchIndex, isSearchIndexSearch, isURISearch } from '@server/lib/search' | 12 | import { buildMutedForSearchIndex, isSearchIndexSearch, isURISearch } from '@server/lib/search' |
11 | import { getServerActor } from '@server/models/application/application' | 13 | import { getServerActor } from '@server/models/application/application' |
12 | import { VideoPlaylistModel } from '@server/models/video/video-playlist' | 14 | import { VideoPlaylistModel } from '@server/models/video/video-playlist' |
13 | import { MVideoPlaylistFullSummary } from '@server/types/models' | 15 | import { MVideoPlaylistFullSummary } from '@server/types/models' |
14 | import { HttpStatusCode } from '@shared/core-utils' | 16 | import { HttpStatusCode, ResultList, VideoPlaylist, VideoPlaylistsSearchQueryAfterSanitize } from '@shared/models' |
15 | import { ResultList, VideoPlaylist, VideoPlaylistsSearchQuery } from '@shared/models' | ||
16 | import { | 17 | import { |
17 | asyncMiddleware, | 18 | asyncMiddleware, |
18 | openapiOperationDoc, | 19 | openapiOperationDoc, |
@@ -23,7 +24,6 @@ import { | |||
23 | videoPlaylistsListSearchValidator, | 24 | videoPlaylistsListSearchValidator, |
24 | videoPlaylistsSearchSortValidator | 25 | videoPlaylistsSearchSortValidator |
25 | } from '../../../middlewares' | 26 | } from '../../../middlewares' |
26 | import { WEBSERVER } from '@server/initializers/constants' | ||
27 | 27 | ||
28 | const searchPlaylistsRouter = express.Router() | 28 | const searchPlaylistsRouter = express.Router() |
29 | 29 | ||
@@ -45,7 +45,7 @@ export { searchPlaylistsRouter } | |||
45 | // --------------------------------------------------------------------------- | 45 | // --------------------------------------------------------------------------- |
46 | 46 | ||
47 | function searchVideoPlaylists (req: express.Request, res: express.Response) { | 47 | function searchVideoPlaylists (req: express.Request, res: express.Response) { |
48 | const query: VideoPlaylistsSearchQuery = req.query | 48 | const query = pickSearchPlaylistQuery(req.query) |
49 | const search = query.search | 49 | const search = query.search |
50 | 50 | ||
51 | if (isURISearch(search)) return searchVideoPlaylistsURI(search, res) | 51 | if (isURISearch(search)) return searchVideoPlaylistsURI(search, res) |
@@ -57,7 +57,7 @@ function searchVideoPlaylists (req: express.Request, res: express.Response) { | |||
57 | return searchVideoPlaylistsDB(query, res) | 57 | return searchVideoPlaylistsDB(query, res) |
58 | } | 58 | } |
59 | 59 | ||
60 | async function searchVideoPlaylistsIndex (query: VideoPlaylistsSearchQuery, res: express.Response) { | 60 | async function searchVideoPlaylistsIndex (query: VideoPlaylistsSearchQueryAfterSanitize, res: express.Response) { |
61 | const result = await buildMutedForSearchIndex(res) | 61 | const result = await buildMutedForSearchIndex(res) |
62 | 62 | ||
63 | const body = await Hooks.wrapObject(Object.assign(query, result), 'filter:api.search.video-playlists.index.list.params') | 63 | const body = await Hooks.wrapObject(Object.assign(query, result), 'filter:api.search.video-playlists.index.list.params') |
@@ -81,15 +81,13 @@ async function searchVideoPlaylistsIndex (query: VideoPlaylistsSearchQuery, res: | |||
81 | } | 81 | } |
82 | } | 82 | } |
83 | 83 | ||
84 | async function searchVideoPlaylistsDB (query: VideoPlaylistsSearchQuery, res: express.Response) { | 84 | async function searchVideoPlaylistsDB (query: VideoPlaylistsSearchQueryAfterSanitize, res: express.Response) { |
85 | const serverActor = await getServerActor() | 85 | const serverActor = await getServerActor() |
86 | 86 | ||
87 | const apiOptions = await Hooks.wrapObject({ | 87 | const apiOptions = await Hooks.wrapObject({ |
88 | followerActorId: serverActor.id, | 88 | ...query, |
89 | search: query.search, | 89 | |
90 | start: query.start, | 90 | followerActorId: serverActor.id |
91 | count: query.count, | ||
92 | sort: query.sort | ||
93 | }, 'filter:api.search.video-playlists.local.list.params') | 91 | }, 'filter:api.search.video-playlists.local.list.params') |
94 | 92 | ||
95 | const resultList = await Hooks.wrapPromiseFun( | 93 | const resultList = await Hooks.wrapPromiseFun( |
diff --git a/server/controllers/api/search/search-videos.ts b/server/controllers/api/search/search-videos.ts index b626baa28..4a6ce0de4 100644 --- a/server/controllers/api/search/search-videos.ts +++ b/server/controllers/api/search/search-videos.ts | |||
@@ -1,14 +1,14 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { sanitizeUrl } from '@server/helpers/core-utils' | 2 | import { sanitizeUrl } from '@server/helpers/core-utils' |
3 | import { pickSearchVideoQuery } from '@server/helpers/query' | ||
3 | import { doJSONRequest } from '@server/helpers/requests' | 4 | import { doJSONRequest } from '@server/helpers/requests' |
4 | import { CONFIG } from '@server/initializers/config' | 5 | import { CONFIG } from '@server/initializers/config' |
5 | import { WEBSERVER } from '@server/initializers/constants' | 6 | import { WEBSERVER } from '@server/initializers/constants' |
6 | import { getOrCreateAPVideo } from '@server/lib/activitypub/videos' | 7 | import { getOrCreateAPVideo } from '@server/lib/activitypub/videos' |
7 | import { Hooks } from '@server/lib/plugins/hooks' | 8 | import { Hooks } from '@server/lib/plugins/hooks' |
8 | import { buildMutedForSearchIndex, isSearchIndexSearch, isURISearch } from '@server/lib/search' | 9 | import { buildMutedForSearchIndex, isSearchIndexSearch, isURISearch } from '@server/lib/search' |
9 | import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' | 10 | import { HttpStatusCode, ResultList, Video } from '@shared/models' |
10 | import { ResultList, Video } from '@shared/models' | 11 | import { VideosSearchQueryAfterSanitize } from '../../../../shared/models/search' |
11 | import { VideosSearchQuery } from '../../../../shared/models/search' | ||
12 | import { buildNSFWFilter, isUserAbleToSearchRemoteURI } from '../../../helpers/express-utils' | 12 | import { buildNSFWFilter, isUserAbleToSearchRemoteURI } from '../../../helpers/express-utils' |
13 | import { logger } from '../../../helpers/logger' | 13 | import { logger } from '../../../helpers/logger' |
14 | import { getFormattedObjects } from '../../../helpers/utils' | 14 | import { getFormattedObjects } from '../../../helpers/utils' |
@@ -47,7 +47,7 @@ export { searchVideosRouter } | |||
47 | // --------------------------------------------------------------------------- | 47 | // --------------------------------------------------------------------------- |
48 | 48 | ||
49 | function searchVideos (req: express.Request, res: express.Response) { | 49 | function searchVideos (req: express.Request, res: express.Response) { |
50 | const query: VideosSearchQuery = req.query | 50 | const query = pickSearchVideoQuery(req.query) |
51 | const search = query.search | 51 | const search = query.search |
52 | 52 | ||
53 | if (isURISearch(search)) { | 53 | if (isURISearch(search)) { |
@@ -61,10 +61,10 @@ function searchVideos (req: express.Request, res: express.Response) { | |||
61 | return searchVideosDB(query, res) | 61 | return searchVideosDB(query, res) |
62 | } | 62 | } |
63 | 63 | ||
64 | async function searchVideosIndex (query: VideosSearchQuery, res: express.Response) { | 64 | async function searchVideosIndex (query: VideosSearchQueryAfterSanitize, res: express.Response) { |
65 | const result = await buildMutedForSearchIndex(res) | 65 | const result = await buildMutedForSearchIndex(res) |
66 | 66 | ||
67 | let body: VideosSearchQuery = Object.assign(query, result) | 67 | let body = { ...query, ...result } |
68 | 68 | ||
69 | // Use the default instance NSFW policy if not specified | 69 | // Use the default instance NSFW policy if not specified |
70 | if (!body.nsfw) { | 70 | if (!body.nsfw) { |
@@ -98,13 +98,18 @@ async function searchVideosIndex (query: VideosSearchQuery, res: express.Respons | |||
98 | } | 98 | } |
99 | } | 99 | } |
100 | 100 | ||
101 | async function searchVideosDB (query: VideosSearchQuery, res: express.Response) { | 101 | async function searchVideosDB (query: VideosSearchQueryAfterSanitize, res: express.Response) { |
102 | const apiOptions = await Hooks.wrapObject(Object.assign(query, { | 102 | const apiOptions = await Hooks.wrapObject({ |
103 | ...query, | ||
104 | |||
103 | includeLocalVideos: true, | 105 | includeLocalVideos: true, |
104 | nsfw: buildNSFWFilter(res, query.nsfw), | ||
105 | filter: query.filter, | 106 | filter: query.filter, |
106 | user: res.locals.oauth ? res.locals.oauth.token.User : undefined | 107 | |
107 | }), 'filter:api.search.videos.local.list.params') | 108 | nsfw: buildNSFWFilter(res, query.nsfw), |
109 | user: res.locals.oauth | ||
110 | ? res.locals.oauth.token.User | ||
111 | : undefined | ||
112 | }, 'filter:api.search.videos.local.list.params') | ||
108 | 113 | ||
109 | const resultList = await Hooks.wrapPromiseFun( | 114 | const resultList = await Hooks.wrapPromiseFun( |
110 | VideoModel.searchAndPopulateAccountAndServer, | 115 | VideoModel.searchAndPopulateAccountAndServer, |
diff --git a/server/controllers/api/server/contact.ts b/server/controllers/api/server/contact.ts index caddc0909..b315e99cf 100644 --- a/server/controllers/api/server/contact.ts +++ b/server/controllers/api/server/contact.ts | |||
@@ -1,9 +1,9 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { asyncMiddleware, contactAdministratorValidator } from '../../../middlewares' | 2 | import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' |
3 | import { Redis } from '../../../lib/redis' | ||
4 | import { Emailer } from '../../../lib/emailer' | ||
5 | import { ContactForm } from '../../../../shared/models/server' | 3 | import { ContactForm } from '../../../../shared/models/server' |
6 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | 4 | import { Emailer } from '../../../lib/emailer' |
5 | import { Redis } from '../../../lib/redis' | ||
6 | import { asyncMiddleware, contactAdministratorValidator } from '../../../middlewares' | ||
7 | 7 | ||
8 | const contactRouter = express.Router() | 8 | const contactRouter = express.Router() |
9 | 9 | ||
@@ -15,7 +15,7 @@ contactRouter.post('/contact', | |||
15 | async function contactAdministrator (req: express.Request, res: express.Response) { | 15 | async function contactAdministrator (req: express.Request, res: express.Response) { |
16 | const data = req.body as ContactForm | 16 | const data = req.body as ContactForm |
17 | 17 | ||
18 | await Emailer.Instance.addContactFormJob(data.fromEmail, data.fromName, data.subject, data.body) | 18 | Emailer.Instance.addContactFormJob(data.fromEmail, data.fromName, data.subject, data.body) |
19 | 19 | ||
20 | await Redis.Instance.setContactFormIp(req.ip) | 20 | await Redis.Instance.setContactFormIp(req.ip) |
21 | 21 | ||
diff --git a/server/controllers/api/server/debug.ts b/server/controllers/api/server/debug.ts index a6e9147f3..0601b89ce 100644 --- a/server/controllers/api/server/debug.ts +++ b/server/controllers/api/server/debug.ts | |||
@@ -1,8 +1,8 @@ | |||
1 | import * as express from 'express' | ||
1 | import { InboxManager } from '@server/lib/activitypub/inbox-manager' | 2 | import { InboxManager } from '@server/lib/activitypub/inbox-manager' |
2 | import { RemoveDanglingResumableUploadsScheduler } from '@server/lib/schedulers/remove-dangling-resumable-uploads-scheduler' | 3 | import { RemoveDanglingResumableUploadsScheduler } from '@server/lib/schedulers/remove-dangling-resumable-uploads-scheduler' |
3 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | 4 | import { Debug, SendDebugCommand } from '@shared/models' |
4 | import { SendDebugCommand } from '@shared/models' | 5 | import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' |
5 | import * as express from 'express' | ||
6 | import { UserRight } from '../../../../shared/models/users' | 6 | import { UserRight } from '../../../../shared/models/users' |
7 | import { authenticate, ensureUserHasRight } from '../../../middlewares' | 7 | import { authenticate, ensureUserHasRight } from '../../../middlewares' |
8 | 8 | ||
@@ -32,7 +32,7 @@ function getDebug (req: express.Request, res: express.Response) { | |||
32 | return res.json({ | 32 | return res.json({ |
33 | ip: req.ip, | 33 | ip: req.ip, |
34 | activityPubMessagesWaiting: InboxManager.Instance.getActivityPubMessagesWaiting() | 34 | activityPubMessagesWaiting: InboxManager.Instance.getActivityPubMessagesWaiting() |
35 | }) | 35 | } as Debug) |
36 | } | 36 | } |
37 | 37 | ||
38 | async function runCommand (req: express.Request, res: express.Response) { | 38 | async function runCommand (req: express.Request, res: express.Response) { |
diff --git a/server/controllers/api/server/follows.ts b/server/controllers/api/server/follows.ts index 12357a2ca..cbe6b7e4f 100644 --- a/server/controllers/api/server/follows.ts +++ b/server/controllers/api/server/follows.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { getServerActor } from '@server/models/application/application' | 2 | import { getServerActor } from '@server/models/application/application' |
3 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | 3 | import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' |
4 | import { UserRight } from '../../../../shared/models/users' | 4 | import { UserRight } from '../../../../shared/models/users' |
5 | import { logger } from '../../../helpers/logger' | 5 | import { logger } from '../../../helpers/logger' |
6 | import { getFormattedObjects } from '../../../helpers/utils' | 6 | import { getFormattedObjects } from '../../../helpers/utils' |
@@ -29,6 +29,7 @@ import { | |||
29 | removeFollowingValidator | 29 | removeFollowingValidator |
30 | } from '../../../middlewares/validators' | 30 | } from '../../../middlewares/validators' |
31 | import { ActorFollowModel } from '../../../models/actor/actor-follow' | 31 | import { ActorFollowModel } from '../../../models/actor/actor-follow' |
32 | import { ServerFollowCreate } from '@shared/models' | ||
32 | 33 | ||
33 | const serverFollowsRouter = express.Router() | 34 | const serverFollowsRouter = express.Router() |
34 | serverFollowsRouter.get('/following', | 35 | serverFollowsRouter.get('/following', |
@@ -45,10 +46,10 @@ serverFollowsRouter.post('/following', | |||
45 | ensureUserHasRight(UserRight.MANAGE_SERVER_FOLLOW), | 46 | ensureUserHasRight(UserRight.MANAGE_SERVER_FOLLOW), |
46 | followValidator, | 47 | followValidator, |
47 | setBodyHostsPort, | 48 | setBodyHostsPort, |
48 | asyncMiddleware(followInstance) | 49 | asyncMiddleware(addFollow) |
49 | ) | 50 | ) |
50 | 51 | ||
51 | serverFollowsRouter.delete('/following/:host', | 52 | serverFollowsRouter.delete('/following/:hostOrHandle', |
52 | authenticate, | 53 | authenticate, |
53 | ensureUserHasRight(UserRight.MANAGE_SERVER_FOLLOW), | 54 | ensureUserHasRight(UserRight.MANAGE_SERVER_FOLLOW), |
54 | asyncMiddleware(removeFollowingValidator), | 55 | asyncMiddleware(removeFollowingValidator), |
@@ -125,8 +126,8 @@ async function listFollowers (req: express.Request, res: express.Response) { | |||
125 | return res.json(getFormattedObjects(resultList.data, resultList.total)) | 126 | return res.json(getFormattedObjects(resultList.data, resultList.total)) |
126 | } | 127 | } |
127 | 128 | ||
128 | async function followInstance (req: express.Request, res: express.Response) { | 129 | async function addFollow (req: express.Request, res: express.Response) { |
129 | const hosts = req.body.hosts as string[] | 130 | const { hosts, handles } = req.body as ServerFollowCreate |
130 | const follower = await getServerActor() | 131 | const follower = await getServerActor() |
131 | 132 | ||
132 | for (const host of hosts) { | 133 | for (const host of hosts) { |
@@ -139,6 +140,18 @@ async function followInstance (req: express.Request, res: express.Response) { | |||
139 | JobQueue.Instance.createJob({ type: 'activitypub-follow', payload }) | 140 | JobQueue.Instance.createJob({ type: 'activitypub-follow', payload }) |
140 | } | 141 | } |
141 | 142 | ||
143 | for (const handle of handles) { | ||
144 | const [ name, host ] = handle.split('@') | ||
145 | |||
146 | const payload = { | ||
147 | host, | ||
148 | name, | ||
149 | followerActorId: follower.id | ||
150 | } | ||
151 | |||
152 | JobQueue.Instance.createJob({ type: 'activitypub-follow', payload }) | ||
153 | } | ||
154 | |||
142 | return res.status(HttpStatusCode.NO_CONTENT_204).end() | 155 | return res.status(HttpStatusCode.NO_CONTENT_204).end() |
143 | } | 156 | } |
144 | 157 | ||
diff --git a/server/controllers/api/server/index.ts b/server/controllers/api/server/index.ts index 6b8793a19..32fefefc0 100644 --- a/server/controllers/api/server/index.ts +++ b/server/controllers/api/server/index.ts | |||
@@ -1,11 +1,11 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { contactRouter } from './contact' | ||
3 | import { debugRouter } from './debug' | ||
2 | import { serverFollowsRouter } from './follows' | 4 | import { serverFollowsRouter } from './follows' |
3 | import { statsRouter } from './stats' | 5 | import { logsRouter } from './logs' |
4 | import { serverRedundancyRouter } from './redundancy' | 6 | import { serverRedundancyRouter } from './redundancy' |
5 | import { serverBlocklistRouter } from './server-blocklist' | 7 | import { serverBlocklistRouter } from './server-blocklist' |
6 | import { contactRouter } from './contact' | 8 | import { statsRouter } from './stats' |
7 | import { logsRouter } from './logs' | ||
8 | import { debugRouter } from './debug' | ||
9 | 9 | ||
10 | const serverRouter = express.Router() | 10 | const serverRouter = express.Router() |
11 | 11 | ||
diff --git a/server/controllers/api/server/logs.ts b/server/controllers/api/server/logs.ts index 4b543d686..39eceb654 100644 --- a/server/controllers/api/server/logs.ts +++ b/server/controllers/api/server/logs.ts | |||
@@ -1,14 +1,13 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { UserRight } from '../../../../shared/models/users' | ||
3 | import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../../middlewares' | ||
4 | import { mtimeSortFilesDesc } from '../../../../shared/core-utils/logs/logs' | ||
5 | import { readdir, readFile } from 'fs-extra' | 2 | import { readdir, readFile } from 'fs-extra' |
6 | import { AUDIT_LOG_FILENAME, MAX_LOGS_OUTPUT_CHARACTERS, LOG_FILENAME } from '../../../initializers/constants' | ||
7 | import { join } from 'path' | 3 | import { join } from 'path' |
8 | import { getAuditLogsValidator, getLogsValidator } from '../../../middlewares/validators/logs' | 4 | import { logger, mtimeSortFilesDesc } from '@server/helpers/logger' |
9 | import { LogLevel } from '../../../../shared/models/server/log-level.type' | 5 | import { LogLevel } from '../../../../shared/models/server/log-level.type' |
6 | import { UserRight } from '../../../../shared/models/users' | ||
10 | import { CONFIG } from '../../../initializers/config' | 7 | import { CONFIG } from '../../../initializers/config' |
11 | import { logger } from '@server/helpers/logger' | 8 | import { AUDIT_LOG_FILENAME, LOG_FILENAME, MAX_LOGS_OUTPUT_CHARACTERS } from '../../../initializers/constants' |
9 | import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../../middlewares' | ||
10 | import { getAuditLogsValidator, getLogsValidator } from '../../../middlewares/validators/logs' | ||
12 | 11 | ||
13 | const logsRouter = express.Router() | 12 | const logsRouter = express.Router() |
14 | 13 | ||
diff --git a/server/controllers/api/server/redundancy.ts b/server/controllers/api/server/redundancy.ts index bc593ad43..99d1c762b 100644 --- a/server/controllers/api/server/redundancy.ts +++ b/server/controllers/api/server/redundancy.ts | |||
@@ -1,5 +1,10 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { JobQueue } from '@server/lib/job-queue' | ||
3 | import { VideoRedundancyModel } from '@server/models/redundancy/video-redundancy' | ||
4 | import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' | ||
2 | import { UserRight } from '../../../../shared/models/users' | 5 | import { UserRight } from '../../../../shared/models/users' |
6 | import { logger } from '../../../helpers/logger' | ||
7 | import { removeRedundanciesOfServer, removeVideoRedundancy } from '../../../lib/redundancy' | ||
3 | import { | 8 | import { |
4 | asyncMiddleware, | 9 | asyncMiddleware, |
5 | authenticate, | 10 | authenticate, |
@@ -10,16 +15,11 @@ import { | |||
10 | videoRedundanciesSortValidator | 15 | videoRedundanciesSortValidator |
11 | } from '../../../middlewares' | 16 | } from '../../../middlewares' |
12 | import { | 17 | import { |
13 | listVideoRedundanciesValidator, | ||
14 | updateServerRedundancyValidator, | ||
15 | addVideoRedundancyValidator, | 18 | addVideoRedundancyValidator, |
16 | removeVideoRedundancyValidator | 19 | listVideoRedundanciesValidator, |
20 | removeVideoRedundancyValidator, | ||
21 | updateServerRedundancyValidator | ||
17 | } from '../../../middlewares/validators/redundancy' | 22 | } from '../../../middlewares/validators/redundancy' |
18 | import { removeRedundanciesOfServer, removeVideoRedundancy } from '../../../lib/redundancy' | ||
19 | import { logger } from '../../../helpers/logger' | ||
20 | import { VideoRedundancyModel } from '@server/models/redundancy/video-redundancy' | ||
21 | import { JobQueue } from '@server/lib/job-queue' | ||
22 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
23 | 23 | ||
24 | const serverRedundancyRouter = express.Router() | 24 | const serverRedundancyRouter = express.Router() |
25 | 25 | ||
diff --git a/server/controllers/api/server/server-blocklist.ts b/server/controllers/api/server/server-blocklist.ts index a86bc7d19..b3ee50d85 100644 --- a/server/controllers/api/server/server-blocklist.ts +++ b/server/controllers/api/server/server-blocklist.ts | |||
@@ -1,8 +1,9 @@ | |||
1 | import 'multer' | 1 | import 'multer' |
2 | import * as express from 'express' | 2 | import * as express from 'express' |
3 | import { logger } from '@server/helpers/logger' | 3 | import { logger } from '@server/helpers/logger' |
4 | import { UserNotificationModel } from '@server/models/user/user-notification' | ||
5 | import { getServerActor } from '@server/models/application/application' | 4 | import { getServerActor } from '@server/models/application/application' |
5 | import { UserNotificationModel } from '@server/models/user/user-notification' | ||
6 | import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' | ||
6 | import { UserRight } from '../../../../shared/models/users' | 7 | import { UserRight } from '../../../../shared/models/users' |
7 | import { getFormattedObjects } from '../../../helpers/utils' | 8 | import { getFormattedObjects } from '../../../helpers/utils' |
8 | import { addAccountInBlocklist, addServerInBlocklist, removeAccountFromBlocklist, removeServerFromBlocklist } from '../../../lib/blocklist' | 9 | import { addAccountInBlocklist, addServerInBlocklist, removeAccountFromBlocklist, removeServerFromBlocklist } from '../../../lib/blocklist' |
@@ -25,7 +26,6 @@ import { | |||
25 | } from '../../../middlewares/validators' | 26 | } from '../../../middlewares/validators' |
26 | import { AccountBlocklistModel } from '../../../models/account/account-blocklist' | 27 | import { AccountBlocklistModel } from '../../../models/account/account-blocklist' |
27 | import { ServerBlocklistModel } from '../../../models/server/server-blocklist' | 28 | import { ServerBlocklistModel } from '../../../models/server/server-blocklist' |
28 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
29 | 29 | ||
30 | const serverBlocklistRouter = express.Router() | 30 | const serverBlocklistRouter = express.Router() |
31 | 31 | ||
diff --git a/server/controllers/api/server/stats.ts b/server/controllers/api/server/stats.ts index 3aea12450..397702548 100644 --- a/server/controllers/api/server/stats.ts +++ b/server/controllers/api/server/stats.ts | |||
@@ -2,12 +2,12 @@ import * as express from 'express' | |||
2 | import { StatsManager } from '@server/lib/stat-manager' | 2 | import { StatsManager } from '@server/lib/stat-manager' |
3 | import { ROUTE_CACHE_LIFETIME } from '../../../initializers/constants' | 3 | import { ROUTE_CACHE_LIFETIME } from '../../../initializers/constants' |
4 | import { asyncMiddleware } from '../../../middlewares' | 4 | import { asyncMiddleware } from '../../../middlewares' |
5 | import { cacheRoute } from '../../../middlewares/cache' | 5 | import { cacheRoute } from '../../../middlewares/cache/cache' |
6 | 6 | ||
7 | const statsRouter = express.Router() | 7 | const statsRouter = express.Router() |
8 | 8 | ||
9 | statsRouter.get('/stats', | 9 | statsRouter.get('/stats', |
10 | asyncMiddleware(cacheRoute()(ROUTE_CACHE_LIFETIME.STATS)), | 10 | cacheRoute(ROUTE_CACHE_LIFETIME.STATS), |
11 | asyncMiddleware(getStats) | 11 | asyncMiddleware(getStats) |
12 | ) | 12 | ) |
13 | 13 | ||
diff --git a/server/controllers/api/users/index.ts b/server/controllers/api/users/index.ts index d907b49bf..be800e8b5 100644 --- a/server/controllers/api/users/index.ts +++ b/server/controllers/api/users/index.ts | |||
@@ -4,8 +4,8 @@ import { tokensRouter } from '@server/controllers/api/users/token' | |||
4 | import { Hooks } from '@server/lib/plugins/hooks' | 4 | import { Hooks } from '@server/lib/plugins/hooks' |
5 | import { OAuthTokenModel } from '@server/models/oauth/oauth-token' | 5 | import { OAuthTokenModel } from '@server/models/oauth/oauth-token' |
6 | import { MUser, MUserAccountDefault } from '@server/types/models' | 6 | import { MUser, MUserAccountDefault } from '@server/types/models' |
7 | import { UserCreate, UserRight, UserRole, UserUpdate } from '../../../../shared' | 7 | import { UserCreate, UserCreateResult, UserRight, UserRole, UserUpdate } from '../../../../shared' |
8 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | 8 | import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' |
9 | import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' | 9 | import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' |
10 | import { UserRegister } from '../../../../shared/models/users/user-register.model' | 10 | import { UserRegister } from '../../../../shared/models/users/user-register.model' |
11 | import { auditLoggerFactory, getAuditIdFromRes, UserAuditView } from '../../../helpers/audit-logger' | 11 | import { auditLoggerFactory, getAuditIdFromRes, UserAuditView } from '../../../helpers/audit-logger' |
@@ -220,7 +220,7 @@ async function createUser (req: express.Request, res: express.Response) { | |||
220 | account: { | 220 | account: { |
221 | id: account.id | 221 | id: account.id |
222 | } | 222 | } |
223 | } | 223 | } as UserCreateResult |
224 | }) | 224 | }) |
225 | } | 225 | } |
226 | 226 | ||
diff --git a/server/controllers/api/users/me.ts b/server/controllers/api/users/me.ts index 1f2b2f9dd..ac6faca9c 100644 --- a/server/controllers/api/users/me.ts +++ b/server/controllers/api/users/me.ts | |||
@@ -2,8 +2,9 @@ import 'multer' | |||
2 | import * as express from 'express' | 2 | import * as express from 'express' |
3 | import { auditLoggerFactory, getAuditIdFromRes, UserAuditView } from '@server/helpers/audit-logger' | 3 | import { auditLoggerFactory, getAuditIdFromRes, UserAuditView } from '@server/helpers/audit-logger' |
4 | import { Hooks } from '@server/lib/plugins/hooks' | 4 | import { Hooks } from '@server/lib/plugins/hooks' |
5 | import { AttributesOnly } from '@shared/core-utils' | ||
5 | import { ActorImageType, UserUpdateMe, UserVideoRate as FormattedUserVideoRate } from '../../../../shared' | 6 | import { ActorImageType, UserUpdateMe, UserVideoRate as FormattedUserVideoRate } from '../../../../shared' |
6 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | 7 | import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' |
7 | import { UserVideoQuota } from '../../../../shared/models/users/user-video-quota.model' | 8 | import { UserVideoQuota } from '../../../../shared/models/users/user-video-quota.model' |
8 | import { createReqFiles } from '../../../helpers/express-utils' | 9 | import { createReqFiles } from '../../../helpers/express-utils' |
9 | import { getFormattedObjects } from '../../../helpers/utils' | 10 | import { getFormattedObjects } from '../../../helpers/utils' |
@@ -31,7 +32,6 @@ import { AccountVideoRateModel } from '../../../models/account/account-video-rat | |||
31 | import { UserModel } from '../../../models/user/user' | 32 | import { UserModel } from '../../../models/user/user' |
32 | import { VideoModel } from '../../../models/video/video' | 33 | import { VideoModel } from '../../../models/video/video' |
33 | import { VideoImportModel } from '../../../models/video/video-import' | 34 | import { VideoImportModel } from '../../../models/video/video-import' |
34 | import { AttributesOnly } from '@shared/core-utils' | ||
35 | 35 | ||
36 | const auditLogger = auditLoggerFactory('users') | 36 | const auditLogger = auditLoggerFactory('users') |
37 | 37 | ||
diff --git a/server/controllers/api/users/my-blocklist.ts b/server/controllers/api/users/my-blocklist.ts index a1561b751..24fff83e3 100644 --- a/server/controllers/api/users/my-blocklist.ts +++ b/server/controllers/api/users/my-blocklist.ts | |||
@@ -1,6 +1,10 @@ | |||
1 | import * as express from 'express' | ||
2 | import 'multer' | 1 | import 'multer' |
2 | import * as express from 'express' | ||
3 | import { logger } from '@server/helpers/logger' | ||
4 | import { UserNotificationModel } from '@server/models/user/user-notification' | ||
5 | import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' | ||
3 | import { getFormattedObjects } from '../../../helpers/utils' | 6 | import { getFormattedObjects } from '../../../helpers/utils' |
7 | import { addAccountInBlocklist, addServerInBlocklist, removeAccountFromBlocklist, removeServerFromBlocklist } from '../../../lib/blocklist' | ||
4 | import { | 8 | import { |
5 | asyncMiddleware, | 9 | asyncMiddleware, |
6 | asyncRetryTransactionMiddleware, | 10 | asyncRetryTransactionMiddleware, |
@@ -18,11 +22,7 @@ import { | |||
18 | unblockServerByAccountValidator | 22 | unblockServerByAccountValidator |
19 | } from '../../../middlewares/validators' | 23 | } from '../../../middlewares/validators' |
20 | import { AccountBlocklistModel } from '../../../models/account/account-blocklist' | 24 | import { AccountBlocklistModel } from '../../../models/account/account-blocklist' |
21 | import { addAccountInBlocklist, addServerInBlocklist, removeAccountFromBlocklist, removeServerFromBlocklist } from '../../../lib/blocklist' | ||
22 | import { ServerBlocklistModel } from '../../../models/server/server-blocklist' | 25 | import { ServerBlocklistModel } from '../../../models/server/server-blocklist' |
23 | import { UserNotificationModel } from '@server/models/user/user-notification' | ||
24 | import { logger } from '@server/helpers/logger' | ||
25 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
26 | 26 | ||
27 | const myBlocklistRouter = express.Router() | 27 | const myBlocklistRouter = express.Router() |
28 | 28 | ||
diff --git a/server/controllers/api/users/my-history.ts b/server/controllers/api/users/my-history.ts index cff1697ab..a6e723103 100644 --- a/server/controllers/api/users/my-history.ts +++ b/server/controllers/api/users/my-history.ts | |||
@@ -1,4 +1,7 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' | ||
3 | import { getFormattedObjects } from '../../../helpers/utils' | ||
4 | import { sequelizeTypescript } from '../../../initializers/database' | ||
2 | import { | 5 | import { |
3 | asyncMiddleware, | 6 | asyncMiddleware, |
4 | asyncRetryTransactionMiddleware, | 7 | asyncRetryTransactionMiddleware, |
@@ -8,10 +11,7 @@ import { | |||
8 | userHistoryListValidator, | 11 | userHistoryListValidator, |
9 | userHistoryRemoveValidator | 12 | userHistoryRemoveValidator |
10 | } from '../../../middlewares' | 13 | } from '../../../middlewares' |
11 | import { getFormattedObjects } from '../../../helpers/utils' | ||
12 | import { UserVideoHistoryModel } from '../../../models/user/user-video-history' | 14 | import { UserVideoHistoryModel } from '../../../models/user/user-video-history' |
13 | import { sequelizeTypescript } from '../../../initializers/database' | ||
14 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
15 | 15 | ||
16 | const myVideosHistoryRouter = express.Router() | 16 | const myVideosHistoryRouter = express.Router() |
17 | 17 | ||
diff --git a/server/controllers/api/users/my-notifications.ts b/server/controllers/api/users/my-notifications.ts index 2909770da..3beee07c0 100644 --- a/server/controllers/api/users/my-notifications.ts +++ b/server/controllers/api/users/my-notifications.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import 'multer' | 1 | import 'multer' |
2 | import * as express from 'express' | 2 | import * as express from 'express' |
3 | import { UserNotificationModel } from '@server/models/user/user-notification' | 3 | import { UserNotificationModel } from '@server/models/user/user-notification' |
4 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | 4 | import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' |
5 | import { UserNotificationSetting } from '../../../../shared/models/users' | 5 | import { UserNotificationSetting } from '../../../../shared/models/users' |
6 | import { getFormattedObjects } from '../../../helpers/utils' | 6 | import { getFormattedObjects } from '../../../helpers/utils' |
7 | import { | 7 | import { |
diff --git a/server/controllers/api/users/my-subscriptions.ts b/server/controllers/api/users/my-subscriptions.ts index 46a73d49e..26a715704 100644 --- a/server/controllers/api/users/my-subscriptions.ts +++ b/server/controllers/api/users/my-subscriptions.ts | |||
@@ -1,9 +1,9 @@ | |||
1 | import 'multer' | 1 | import 'multer' |
2 | import * as express from 'express' | 2 | import * as express from 'express' |
3 | import { pickCommonVideoQuery } from '@server/helpers/query' | ||
3 | import { sendUndoFollow } from '@server/lib/activitypub/send' | 4 | import { sendUndoFollow } from '@server/lib/activitypub/send' |
4 | import { VideoChannelModel } from '@server/models/video/video-channel' | 5 | import { VideoChannelModel } from '@server/models/video/video-channel' |
5 | import { VideosCommonQuery } from '@shared/models' | 6 | import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' |
6 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
7 | import { buildNSFWFilter, getCountVideos } from '../../../helpers/express-utils' | 7 | import { buildNSFWFilter, getCountVideos } from '../../../helpers/express-utils' |
8 | import { getFormattedObjects } from '../../../helpers/utils' | 8 | import { getFormattedObjects } from '../../../helpers/utils' |
9 | import { WEBSERVER } from '../../../initializers/constants' | 9 | import { WEBSERVER } from '../../../initializers/constants' |
@@ -170,20 +170,13 @@ async function getUserSubscriptions (req: express.Request, res: express.Response | |||
170 | async function getUserSubscriptionVideos (req: express.Request, res: express.Response) { | 170 | async function getUserSubscriptionVideos (req: express.Request, res: express.Response) { |
171 | const user = res.locals.oauth.token.User | 171 | const user = res.locals.oauth.token.User |
172 | const countVideos = getCountVideos(req) | 172 | const countVideos = getCountVideos(req) |
173 | const query = req.query as VideosCommonQuery | 173 | const query = pickCommonVideoQuery(req.query) |
174 | 174 | ||
175 | const resultList = await VideoModel.listForApi({ | 175 | const resultList = await VideoModel.listForApi({ |
176 | start: query.start, | 176 | ...query, |
177 | count: query.count, | 177 | |
178 | sort: query.sort, | ||
179 | includeLocalVideos: false, | 178 | includeLocalVideos: false, |
180 | categoryOneOf: query.categoryOneOf, | ||
181 | licenceOneOf: query.licenceOneOf, | ||
182 | languageOneOf: query.languageOneOf, | ||
183 | tagsOneOf: query.tagsOneOf, | ||
184 | tagsAllOf: query.tagsAllOf, | ||
185 | nsfw: buildNSFWFilter(res, query.nsfw), | 179 | nsfw: buildNSFWFilter(res, query.nsfw), |
186 | filter: query.filter, | ||
187 | withFiles: false, | 180 | withFiles: false, |
188 | followerActorId: user.Account.Actor.id, | 181 | followerActorId: user.Account.Actor.id, |
189 | user, | 182 | user, |
diff --git a/server/controllers/api/users/my-video-playlists.ts b/server/controllers/api/users/my-video-playlists.ts index d0bd99463..76e741ba5 100644 --- a/server/controllers/api/users/my-video-playlists.ts +++ b/server/controllers/api/users/my-video-playlists.ts | |||
@@ -1,8 +1,8 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { VideosExistInPlaylists } from '../../../../shared/models/videos/playlist/video-exist-in-playlist.model' | ||
2 | import { asyncMiddleware, authenticate } from '../../../middlewares' | 3 | import { asyncMiddleware, authenticate } from '../../../middlewares' |
3 | import { doVideosInPlaylistExistValidator } from '../../../middlewares/validators/videos/video-playlists' | 4 | import { doVideosInPlaylistExistValidator } from '../../../middlewares/validators/videos/video-playlists' |
4 | import { VideoPlaylistModel } from '../../../models/video/video-playlist' | 5 | import { VideoPlaylistModel } from '../../../models/video/video-playlist' |
5 | import { VideosExistInPlaylists } from '../../../../shared/models/videos/playlist/video-exist-in-playlist.model' | ||
6 | 6 | ||
7 | const myVideoPlaylistsRouter = express.Router() | 7 | const myVideoPlaylistsRouter = express.Router() |
8 | 8 | ||
diff --git a/server/controllers/api/video-channel.ts b/server/controllers/api/video-channel.ts index bc8d203b0..7bdb33737 100644 --- a/server/controllers/api/video-channel.ts +++ b/server/controllers/api/video-channel.ts | |||
@@ -1,9 +1,10 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { pickCommonVideoQuery } from '@server/helpers/query' | ||
2 | import { Hooks } from '@server/lib/plugins/hooks' | 3 | import { Hooks } from '@server/lib/plugins/hooks' |
3 | import { getServerActor } from '@server/models/application/application' | 4 | import { getServerActor } from '@server/models/application/application' |
4 | import { MChannelBannerAccountDefault } from '@server/types/models' | 5 | import { MChannelBannerAccountDefault } from '@server/types/models' |
5 | import { ActorImageType, VideoChannelCreate, VideoChannelUpdate, VideosCommonQuery } from '../../../shared' | 6 | import { ActorImageType, VideoChannelCreate, VideoChannelUpdate } from '../../../shared' |
6 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | 7 | import { HttpStatusCode } from '../../../shared/models/http/http-error-codes' |
7 | import { auditLoggerFactory, getAuditIdFromRes, VideoChannelAuditView } from '../../helpers/audit-logger' | 8 | import { auditLoggerFactory, getAuditIdFromRes, VideoChannelAuditView } from '../../helpers/audit-logger' |
8 | import { resetSequelizeInstance } from '../../helpers/database-utils' | 9 | import { resetSequelizeInstance } from '../../helpers/database-utils' |
9 | import { buildNSFWFilter, createReqFiles, getCountVideos, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils' | 10 | import { buildNSFWFilter, createReqFiles, getCountVideos, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils' |
@@ -309,20 +310,13 @@ async function listVideoChannelVideos (req: express.Request, res: express.Respon | |||
309 | const videoChannelInstance = res.locals.videoChannel | 310 | const videoChannelInstance = res.locals.videoChannel |
310 | const followerActorId = isUserAbleToSearchRemoteURI(res) ? null : undefined | 311 | const followerActorId = isUserAbleToSearchRemoteURI(res) ? null : undefined |
311 | const countVideos = getCountVideos(req) | 312 | const countVideos = getCountVideos(req) |
312 | const query = req.query as VideosCommonQuery | 313 | const query = pickCommonVideoQuery(req.query) |
313 | 314 | ||
314 | const apiOptions = await Hooks.wrapObject({ | 315 | const apiOptions = await Hooks.wrapObject({ |
316 | ...query, | ||
317 | |||
315 | followerActorId, | 318 | followerActorId, |
316 | start: query.start, | ||
317 | count: query.count, | ||
318 | sort: query.sort, | ||
319 | includeLocalVideos: true, | 319 | includeLocalVideos: true, |
320 | categoryOneOf: query.categoryOneOf, | ||
321 | licenceOneOf: query.licenceOneOf, | ||
322 | languageOneOf: query.languageOneOf, | ||
323 | tagsOneOf: query.tagsOneOf, | ||
324 | tagsAllOf: query.tagsAllOf, | ||
325 | filter: query.filter, | ||
326 | nsfw: buildNSFWFilter(res, query.nsfw), | 320 | nsfw: buildNSFWFilter(res, query.nsfw), |
327 | withFiles: false, | 321 | withFiles: false, |
328 | videoChannelId: videoChannelInstance.id, | 322 | videoChannelId: videoChannelInstance.id, |
diff --git a/server/controllers/api/video-playlist.ts b/server/controllers/api/video-playlist.ts index 87a6f6bbe..4971d0a77 100644 --- a/server/controllers/api/video-playlist.ts +++ b/server/controllers/api/video-playlist.ts | |||
@@ -5,7 +5,8 @@ import { scheduleRefreshIfNeeded } from '@server/lib/activitypub/playlists' | |||
5 | import { Hooks } from '@server/lib/plugins/hooks' | 5 | import { Hooks } from '@server/lib/plugins/hooks' |
6 | import { getServerActor } from '@server/models/application/application' | 6 | import { getServerActor } from '@server/models/application/application' |
7 | import { MVideoPlaylistFull, MVideoPlaylistThumbnail, MVideoThumbnail } from '@server/types/models' | 7 | import { MVideoPlaylistFull, MVideoPlaylistThumbnail, MVideoThumbnail } from '@server/types/models' |
8 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | 8 | import { VideoPlaylistCreateResult, VideoPlaylistElementCreateResult } from '@shared/models' |
9 | import { HttpStatusCode } from '../../../shared/models/http/http-error-codes' | ||
9 | import { VideoPlaylistCreate } from '../../../shared/models/videos/playlist/video-playlist-create.model' | 10 | import { VideoPlaylistCreate } from '../../../shared/models/videos/playlist/video-playlist-create.model' |
10 | import { VideoPlaylistElementCreate } from '../../../shared/models/videos/playlist/video-playlist-element-create.model' | 11 | import { VideoPlaylistElementCreate } from '../../../shared/models/videos/playlist/video-playlist-element-create.model' |
11 | import { VideoPlaylistElementUpdate } from '../../../shared/models/videos/playlist/video-playlist-element-update.model' | 12 | import { VideoPlaylistElementUpdate } from '../../../shared/models/videos/playlist/video-playlist-element-update.model' |
@@ -202,7 +203,7 @@ async function addVideoPlaylist (req: express.Request, res: express.Response) { | |||
202 | id: videoPlaylistCreated.id, | 203 | id: videoPlaylistCreated.id, |
203 | shortUUID: uuidToShort(videoPlaylistCreated.uuid), | 204 | shortUUID: uuidToShort(videoPlaylistCreated.uuid), |
204 | uuid: videoPlaylistCreated.uuid | 205 | uuid: videoPlaylistCreated.uuid |
205 | } | 206 | } as VideoPlaylistCreateResult |
206 | }) | 207 | }) |
207 | } | 208 | } |
208 | 209 | ||
@@ -338,8 +339,8 @@ async function addVideoInPlaylist (req: express.Request, res: express.Response) | |||
338 | return res.json({ | 339 | return res.json({ |
339 | videoPlaylistElement: { | 340 | videoPlaylistElement: { |
340 | id: playlistElement.id | 341 | id: playlistElement.id |
341 | } | 342 | } as VideoPlaylistElementCreateResult |
342 | }).end() | 343 | }) |
343 | } | 344 | } |
344 | 345 | ||
345 | async function updateVideoPlaylistElement (req: express.Request, res: express.Response) { | 346 | async function updateVideoPlaylistElement (req: express.Request, res: express.Response) { |
diff --git a/server/controllers/api/videos/blacklist.ts b/server/controllers/api/videos/blacklist.ts index 530e17965..6bc768471 100644 --- a/server/controllers/api/videos/blacklist.ts +++ b/server/controllers/api/videos/blacklist.ts | |||
@@ -1,6 +1,7 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { blacklistVideo, unblacklistVideo } from '@server/lib/video-blacklist' | 2 | import { blacklistVideo, unblacklistVideo } from '@server/lib/video-blacklist' |
3 | import { UserRight, VideoBlacklistCreate } from '../../../../shared' | 3 | import { UserRight, VideoBlacklistCreate } from '../../../../shared' |
4 | import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' | ||
4 | import { logger } from '../../../helpers/logger' | 5 | import { logger } from '../../../helpers/logger' |
5 | import { getFormattedObjects } from '../../../helpers/utils' | 6 | import { getFormattedObjects } from '../../../helpers/utils' |
6 | import { sequelizeTypescript } from '../../../initializers/database' | 7 | import { sequelizeTypescript } from '../../../initializers/database' |
@@ -19,7 +20,6 @@ import { | |||
19 | videosBlacklistUpdateValidator | 20 | videosBlacklistUpdateValidator |
20 | } from '../../../middlewares' | 21 | } from '../../../middlewares' |
21 | import { VideoBlacklistModel } from '../../../models/video/video-blacklist' | 22 | import { VideoBlacklistModel } from '../../../models/video/video-blacklist' |
22 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
23 | 23 | ||
24 | const blacklistRouter = express.Router() | 24 | const blacklistRouter = express.Router() |
25 | 25 | ||
diff --git a/server/controllers/api/videos/captions.ts b/server/controllers/api/videos/captions.ts index ad7423a31..4008de60f 100644 --- a/server/controllers/api/videos/captions.ts +++ b/server/controllers/api/videos/captions.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { MVideoCaption } from '@server/types/models' | 2 | import { MVideoCaption } from '@server/types/models' |
3 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | 3 | import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' |
4 | import { moveAndProcessCaptionFile } from '../../../helpers/captions-utils' | 4 | import { moveAndProcessCaptionFile } from '../../../helpers/captions-utils' |
5 | import { createReqFiles } from '../../../helpers/express-utils' | 5 | import { createReqFiles } from '../../../helpers/express-utils' |
6 | import { logger } from '../../../helpers/logger' | 6 | import { logger } from '../../../helpers/logger' |
diff --git a/server/controllers/api/videos/comment.ts b/server/controllers/api/videos/comment.ts index e6f28c1cb..cb696f652 100644 --- a/server/controllers/api/videos/comment.ts +++ b/server/controllers/api/videos/comment.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | 2 | import { ResultList, ThreadsResultList, UserRight, VideoCommentCreate } from '../../../../shared/models' |
3 | import { ResultList, ThreadsResultList, UserRight } from '../../../../shared/models' | 3 | import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' |
4 | import { VideoCommentCreate } from '../../../../shared/models/videos/comment/video-comment.model' | 4 | import { VideoCommentThreads } from '../../../../shared/models/videos/comment/video-comment.model' |
5 | import { auditLoggerFactory, CommentAuditView, getAuditIdFromRes } from '../../../helpers/audit-logger' | 5 | import { auditLoggerFactory, CommentAuditView, getAuditIdFromRes } from '../../../helpers/audit-logger' |
6 | import { getFormattedObjects } from '../../../helpers/utils' | 6 | import { getFormattedObjects } from '../../../helpers/utils' |
7 | import { sequelizeTypescript } from '../../../initializers/database' | 7 | import { sequelizeTypescript } from '../../../initializers/database' |
@@ -136,7 +136,7 @@ async function listVideoThreads (req: express.Request, res: express.Response) { | |||
136 | return res.json({ | 136 | return res.json({ |
137 | ...getFormattedObjects(resultList.data, resultList.total), | 137 | ...getFormattedObjects(resultList.data, resultList.total), |
138 | totalNotDeletedComments: resultList.totalNotDeletedComments | 138 | totalNotDeletedComments: resultList.totalNotDeletedComments |
139 | }) | 139 | } as VideoCommentThreads) |
140 | } | 140 | } |
141 | 141 | ||
142 | async function listVideoThreadComments (req: express.Request, res: express.Response) { | 142 | async function listVideoThreadComments (req: express.Request, res: express.Response) { |
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index 74b100e59..49490f79b 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts | |||
@@ -1,12 +1,12 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import toInt from 'validator/lib/toInt' | 2 | import toInt from 'validator/lib/toInt' |
3 | import { pickCommonVideoQuery } from '@server/helpers/query' | ||
3 | import { doJSONRequest } from '@server/helpers/requests' | 4 | import { doJSONRequest } from '@server/helpers/requests' |
4 | import { LiveManager } from '@server/lib/live' | 5 | import { LiveManager } from '@server/lib/live' |
5 | import { openapiOperationDoc } from '@server/middlewares/doc' | 6 | import { openapiOperationDoc } from '@server/middlewares/doc' |
6 | import { getServerActor } from '@server/models/application/application' | 7 | import { getServerActor } from '@server/models/application/application' |
7 | import { MVideoAccountLight } from '@server/types/models' | 8 | import { MVideoAccountLight } from '@server/types/models' |
8 | import { VideosCommonQuery } from '../../../../shared' | 9 | import { HttpStatusCode } from '../../../../shared/models' |
9 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs' | ||
10 | import { auditLoggerFactory, getAuditIdFromRes, VideoAuditView } from '../../../helpers/audit-logger' | 10 | import { auditLoggerFactory, getAuditIdFromRes, VideoAuditView } from '../../../helpers/audit-logger' |
11 | import { buildNSFWFilter, getCountVideos } from '../../../helpers/express-utils' | 11 | import { buildNSFWFilter, getCountVideos } from '../../../helpers/express-utils' |
12 | import { logger } from '../../../helpers/logger' | 12 | import { logger } from '../../../helpers/logger' |
@@ -211,22 +211,14 @@ async function getVideoFileMetadata (req: express.Request, res: express.Response | |||
211 | } | 211 | } |
212 | 212 | ||
213 | async function listVideos (req: express.Request, res: express.Response) { | 213 | async function listVideos (req: express.Request, res: express.Response) { |
214 | const query = req.query as VideosCommonQuery | 214 | const query = pickCommonVideoQuery(req.query) |
215 | const countVideos = getCountVideos(req) | 215 | const countVideos = getCountVideos(req) |
216 | 216 | ||
217 | const apiOptions = await Hooks.wrapObject({ | 217 | const apiOptions = await Hooks.wrapObject({ |
218 | start: query.start, | 218 | ...query, |
219 | count: query.count, | 219 | |
220 | sort: query.sort, | ||
221 | includeLocalVideos: true, | 220 | includeLocalVideos: true, |
222 | categoryOneOf: query.categoryOneOf, | ||
223 | licenceOneOf: query.licenceOneOf, | ||
224 | languageOneOf: query.languageOneOf, | ||
225 | tagsOneOf: query.tagsOneOf, | ||
226 | tagsAllOf: query.tagsAllOf, | ||
227 | nsfw: buildNSFWFilter(res, query.nsfw), | 221 | nsfw: buildNSFWFilter(res, query.nsfw), |
228 | isLive: query.isLive, | ||
229 | filter: query.filter, | ||
230 | withFiles: false, | 222 | withFiles: false, |
231 | user: res.locals.oauth ? res.locals.oauth.token.User : undefined, | 223 | user: res.locals.oauth ? res.locals.oauth.token.User : undefined, |
232 | countVideos | 224 | countVideos |
diff --git a/server/controllers/api/videos/live.ts b/server/controllers/api/videos/live.ts index d8c51c2d4..ed4da8f47 100644 --- a/server/controllers/api/videos/live.ts +++ b/server/controllers/api/videos/live.ts | |||
@@ -11,7 +11,7 @@ import { videoLiveAddValidator, videoLiveGetValidator, videoLiveUpdateValidator | |||
11 | import { VideoLiveModel } from '@server/models/video/video-live' | 11 | import { VideoLiveModel } from '@server/models/video/video-live' |
12 | import { MVideoDetails, MVideoFullLight } from '@server/types/models' | 12 | import { MVideoDetails, MVideoFullLight } from '@server/types/models' |
13 | import { LiveVideoCreate, LiveVideoUpdate, VideoState } from '../../../../shared' | 13 | import { LiveVideoCreate, LiveVideoUpdate, VideoState } from '../../../../shared' |
14 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | 14 | import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' |
15 | import { logger } from '../../../helpers/logger' | 15 | import { logger } from '../../../helpers/logger' |
16 | import { sequelizeTypescript } from '../../../initializers/database' | 16 | import { sequelizeTypescript } from '../../../initializers/database' |
17 | import { updateVideoMiniatureFromExisting } from '../../../lib/thumbnail' | 17 | import { updateVideoMiniatureFromExisting } from '../../../lib/thumbnail' |
diff --git a/server/controllers/api/videos/ownership.ts b/server/controllers/api/videos/ownership.ts index 1bb96e046..f48acbc68 100644 --- a/server/controllers/api/videos/ownership.ts +++ b/server/controllers/api/videos/ownership.ts | |||
@@ -1,6 +1,12 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { MVideoFullLight } from '@server/types/models' | ||
3 | import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' | ||
4 | import { VideoChangeOwnershipStatus, VideoState } from '../../../../shared/models/videos' | ||
2 | import { logger } from '../../../helpers/logger' | 5 | import { logger } from '../../../helpers/logger' |
6 | import { getFormattedObjects } from '../../../helpers/utils' | ||
3 | import { sequelizeTypescript } from '../../../initializers/database' | 7 | import { sequelizeTypescript } from '../../../initializers/database' |
8 | import { sendUpdateVideo } from '../../../lib/activitypub/send' | ||
9 | import { changeVideoChannelShare } from '../../../lib/activitypub/share' | ||
4 | import { | 10 | import { |
5 | asyncMiddleware, | 11 | asyncMiddleware, |
6 | asyncRetryTransactionMiddleware, | 12 | asyncRetryTransactionMiddleware, |
@@ -11,15 +17,9 @@ import { | |||
11 | videosChangeOwnershipValidator, | 17 | videosChangeOwnershipValidator, |
12 | videosTerminateChangeOwnershipValidator | 18 | videosTerminateChangeOwnershipValidator |
13 | } from '../../../middlewares' | 19 | } from '../../../middlewares' |
20 | import { VideoModel } from '../../../models/video/video' | ||
14 | import { VideoChangeOwnershipModel } from '../../../models/video/video-change-ownership' | 21 | import { VideoChangeOwnershipModel } from '../../../models/video/video-change-ownership' |
15 | import { VideoChangeOwnershipStatus, VideoState } from '../../../../shared/models/videos' | ||
16 | import { VideoChannelModel } from '../../../models/video/video-channel' | 22 | import { VideoChannelModel } from '../../../models/video/video-channel' |
17 | import { getFormattedObjects } from '../../../helpers/utils' | ||
18 | import { changeVideoChannelShare } from '../../../lib/activitypub/share' | ||
19 | import { sendUpdateVideo } from '../../../lib/activitypub/send' | ||
20 | import { VideoModel } from '../../../models/video/video' | ||
21 | import { MVideoFullLight } from '@server/types/models' | ||
22 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
23 | 23 | ||
24 | const ownershipVideoRouter = express.Router() | 24 | const ownershipVideoRouter = express.Router() |
25 | 25 | ||
diff --git a/server/controllers/api/videos/rate.ts b/server/controllers/api/videos/rate.ts index 84f42633e..96f6cd886 100644 --- a/server/controllers/api/videos/rate.ts +++ b/server/controllers/api/videos/rate.ts | |||
@@ -1,13 +1,13 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { UserVideoRateUpdate } from '../../../../shared' | 2 | import { UserVideoRateUpdate } from '../../../../shared' |
3 | import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' | ||
3 | import { logger } from '../../../helpers/logger' | 4 | import { logger } from '../../../helpers/logger' |
4 | import { VIDEO_RATE_TYPES } from '../../../initializers/constants' | 5 | import { VIDEO_RATE_TYPES } from '../../../initializers/constants' |
6 | import { sequelizeTypescript } from '../../../initializers/database' | ||
5 | import { getLocalRateUrl, sendVideoRateChange } from '../../../lib/activitypub/video-rates' | 7 | import { getLocalRateUrl, sendVideoRateChange } from '../../../lib/activitypub/video-rates' |
6 | import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoUpdateRateValidator } from '../../../middlewares' | 8 | import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoUpdateRateValidator } from '../../../middlewares' |
7 | import { AccountModel } from '../../../models/account/account' | 9 | import { AccountModel } from '../../../models/account/account' |
8 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' | 10 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' |
9 | import { sequelizeTypescript } from '../../../initializers/database' | ||
10 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
11 | 11 | ||
12 | const rateVideoRouter = express.Router() | 12 | const rateVideoRouter = express.Router() |
13 | 13 | ||
diff --git a/server/controllers/api/videos/update.ts b/server/controllers/api/videos/update.ts index 8affe71c6..49639060b 100644 --- a/server/controllers/api/videos/update.ts +++ b/server/controllers/api/videos/update.ts | |||
@@ -2,10 +2,11 @@ import * as express from 'express' | |||
2 | import { Transaction } from 'sequelize/types' | 2 | import { Transaction } from 'sequelize/types' |
3 | import { changeVideoChannelShare } from '@server/lib/activitypub/share' | 3 | import { changeVideoChannelShare } from '@server/lib/activitypub/share' |
4 | import { buildVideoThumbnailsFromReq, setVideoTags } from '@server/lib/video' | 4 | import { buildVideoThumbnailsFromReq, setVideoTags } from '@server/lib/video' |
5 | import { openapiOperationDoc } from '@server/middlewares/doc' | ||
5 | import { FilteredModelAttributes } from '@server/types' | 6 | import { FilteredModelAttributes } from '@server/types' |
6 | import { MVideoFullLight } from '@server/types/models' | 7 | import { MVideoFullLight } from '@server/types/models' |
7 | import { VideoUpdate } from '../../../../shared' | 8 | import { VideoUpdate } from '../../../../shared' |
8 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs' | 9 | import { HttpStatusCode } from '../../../../shared/models' |
9 | import { auditLoggerFactory, getAuditIdFromRes, VideoAuditView } from '../../../helpers/audit-logger' | 10 | import { auditLoggerFactory, getAuditIdFromRes, VideoAuditView } from '../../../helpers/audit-logger' |
10 | import { resetSequelizeInstance } from '../../../helpers/database-utils' | 11 | import { resetSequelizeInstance } from '../../../helpers/database-utils' |
11 | import { createReqFiles } from '../../../helpers/express-utils' | 12 | import { createReqFiles } from '../../../helpers/express-utils' |
@@ -20,7 +21,6 @@ import { autoBlacklistVideoIfNeeded } from '../../../lib/video-blacklist' | |||
20 | import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videosUpdateValidator } from '../../../middlewares' | 21 | import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videosUpdateValidator } from '../../../middlewares' |
21 | import { ScheduleVideoUpdateModel } from '../../../models/video/schedule-video-update' | 22 | import { ScheduleVideoUpdateModel } from '../../../models/video/schedule-video-update' |
22 | import { VideoModel } from '../../../models/video/video' | 23 | import { VideoModel } from '../../../models/video/video' |
23 | import { openapiOperationDoc } from '@server/middlewares/doc' | ||
24 | 24 | ||
25 | const lTags = loggerTagsFactory('api', 'video') | 25 | const lTags = loggerTagsFactory('api', 'video') |
26 | const auditLogger = auditLoggerFactory('videos') | 26 | const auditLogger = auditLoggerFactory('videos') |
diff --git a/server/controllers/api/videos/upload.ts b/server/controllers/api/videos/upload.ts index bcd21ac99..408f677ff 100644 --- a/server/controllers/api/videos/upload.ts +++ b/server/controllers/api/videos/upload.ts | |||
@@ -6,12 +6,12 @@ import { uuidToShort } from '@server/helpers/uuid' | |||
6 | import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent' | 6 | import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent' |
7 | import { getLocalVideoActivityPubUrl } from '@server/lib/activitypub/url' | 7 | import { getLocalVideoActivityPubUrl } from '@server/lib/activitypub/url' |
8 | import { addOptimizeOrMergeAudioJob, buildLocalVideoFromReq, buildVideoThumbnailsFromReq, setVideoTags } from '@server/lib/video' | 8 | import { addOptimizeOrMergeAudioJob, buildLocalVideoFromReq, buildVideoThumbnailsFromReq, setVideoTags } from '@server/lib/video' |
9 | import { generateVideoFilename, getVideoFilePath } from '@server/lib/video-paths' | 9 | import { generateWebTorrentVideoFilename, getVideoFilePath } from '@server/lib/video-paths' |
10 | import { openapiOperationDoc } from '@server/middlewares/doc' | 10 | import { openapiOperationDoc } from '@server/middlewares/doc' |
11 | import { MVideo, MVideoFile, MVideoFullLight } from '@server/types/models' | 11 | import { MVideo, MVideoFile, MVideoFullLight } from '@server/types/models' |
12 | import { uploadx } from '@uploadx/core' | 12 | import { uploadx } from '@uploadx/core' |
13 | import { VideoCreate, VideoState } from '../../../../shared' | 13 | import { VideoCreate, VideoState } from '../../../../shared' |
14 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs' | 14 | import { HttpStatusCode } from '../../../../shared/models' |
15 | import { auditLoggerFactory, getAuditIdFromRes, VideoAuditView } from '../../../helpers/audit-logger' | 15 | import { auditLoggerFactory, getAuditIdFromRes, VideoAuditView } from '../../../helpers/audit-logger' |
16 | import { retryTransactionWrapper } from '../../../helpers/database-utils' | 16 | import { retryTransactionWrapper } from '../../../helpers/database-utils' |
17 | import { createReqFiles } from '../../../helpers/express-utils' | 17 | import { createReqFiles } from '../../../helpers/express-utils' |
@@ -209,10 +209,12 @@ async function addVideo (options: { | |||
209 | }) | 209 | }) |
210 | 210 | ||
211 | createTorrentFederate(video, videoFile) | 211 | createTorrentFederate(video, videoFile) |
212 | .then(() => { | ||
213 | if (video.state !== VideoState.TO_TRANSCODE) return | ||
212 | 214 | ||
213 | if (video.state === VideoState.TO_TRANSCODE) { | 215 | return addOptimizeOrMergeAudioJob(videoCreated, videoFile, user) |
214 | await addOptimizeOrMergeAudioJob(videoCreated, videoFile, user) | 216 | }) |
215 | } | 217 | .catch(err => logger.error('Cannot add optimize/merge audio job for %s.', videoCreated.uuid, { err, ...lTags(videoCreated.uuid) })) |
216 | 218 | ||
217 | Hooks.runAction('action:api.video.uploaded', { video: videoCreated }) | 219 | Hooks.runAction('action:api.video.uploaded', { video: videoCreated }) |
218 | 220 | ||
@@ -240,7 +242,7 @@ async function buildNewFile (video: MVideo, videoPhysicalFile: express.VideoUplo | |||
240 | videoFile.resolution = (await getVideoFileResolution(videoPhysicalFile.path)).videoFileResolution | 242 | videoFile.resolution = (await getVideoFileResolution(videoPhysicalFile.path)).videoFileResolution |
241 | } | 243 | } |
242 | 244 | ||
243 | videoFile.filename = generateVideoFilename(video, false, videoFile.resolution, videoFile.extname) | 245 | videoFile.filename = generateWebTorrentVideoFilename(videoFile.resolution, videoFile.extname) |
244 | 246 | ||
245 | return videoFile | 247 | return videoFile |
246 | } | 248 | } |
@@ -259,9 +261,9 @@ async function createTorrentAndSetInfoHashAsync (video: MVideo, fileArg: MVideoF | |||
259 | return refreshedFile.save() | 261 | return refreshedFile.save() |
260 | } | 262 | } |
261 | 263 | ||
262 | function createTorrentFederate (video: MVideoFullLight, videoFile: MVideoFile): void { | 264 | function createTorrentFederate (video: MVideoFullLight, videoFile: MVideoFile) { |
263 | // Create the torrent file in async way because it could be long | 265 | // Create the torrent file in async way because it could be long |
264 | createTorrentAndSetInfoHashAsync(video, videoFile) | 266 | return createTorrentAndSetInfoHashAsync(video, videoFile) |
265 | .catch(err => logger.error('Cannot create torrent file for video %s', video.url, { err, ...lTags(video.uuid) })) | 267 | .catch(err => logger.error('Cannot create torrent file for video %s', video.url, { err, ...lTags(video.uuid) })) |
266 | .then(() => VideoModel.loadAndPopulateAccountAndServerAndTags(video.id)) | 268 | .then(() => VideoModel.loadAndPopulateAccountAndServerAndTags(video.id)) |
267 | .then(refreshedVideo => { | 269 | .then(refreshedVideo => { |
diff --git a/server/controllers/api/videos/watching.ts b/server/controllers/api/videos/watching.ts index 8b15525aa..05c75e543 100644 --- a/server/controllers/api/videos/watching.ts +++ b/server/controllers/api/videos/watching.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { UserWatchingVideo } from '../../../../shared' | 2 | import { UserWatchingVideo } from '../../../../shared' |
3 | import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' | ||
3 | import { | 4 | import { |
4 | asyncMiddleware, | 5 | asyncMiddleware, |
5 | asyncRetryTransactionMiddleware, | 6 | asyncRetryTransactionMiddleware, |
@@ -8,7 +9,6 @@ import { | |||
8 | videoWatchingValidator | 9 | videoWatchingValidator |
9 | } from '../../../middlewares' | 10 | } from '../../../middlewares' |
10 | import { UserVideoHistoryModel } from '../../../models/user/user-video-history' | 11 | import { UserVideoHistoryModel } from '../../../models/user/user-video-history' |
11 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
12 | 12 | ||
13 | const watchingRouter = express.Router() | 13 | const watchingRouter = express.Router() |
14 | 14 | ||
diff --git a/server/controllers/bots.ts b/server/controllers/bots.ts index 9e92063d4..de0411608 100644 --- a/server/controllers/bots.ts +++ b/server/controllers/bots.ts | |||
@@ -1,20 +1,20 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { asyncMiddleware } from '../middlewares' | 2 | import { truncate } from 'lodash' |
3 | import { ROUTE_CACHE_LIFETIME, WEBSERVER } from '../initializers/constants' | ||
4 | import { SitemapStream, streamToPromise } from 'sitemap' | 3 | import { SitemapStream, streamToPromise } from 'sitemap' |
4 | import { buildNSFWFilter } from '../helpers/express-utils' | ||
5 | import { ROUTE_CACHE_LIFETIME, WEBSERVER } from '../initializers/constants' | ||
6 | import { asyncMiddleware } from '../middlewares' | ||
7 | import { cacheRoute } from '../middlewares/cache/cache' | ||
8 | import { AccountModel } from '../models/account/account' | ||
5 | import { VideoModel } from '../models/video/video' | 9 | import { VideoModel } from '../models/video/video' |
6 | import { VideoChannelModel } from '../models/video/video-channel' | 10 | import { VideoChannelModel } from '../models/video/video-channel' |
7 | import { AccountModel } from '../models/account/account' | ||
8 | import { cacheRoute } from '../middlewares/cache' | ||
9 | import { buildNSFWFilter } from '../helpers/express-utils' | ||
10 | import { truncate } from 'lodash' | ||
11 | 11 | ||
12 | const botsRouter = express.Router() | 12 | const botsRouter = express.Router() |
13 | 13 | ||
14 | // Special route that add OpenGraph and oEmbed tags | 14 | // Special route that add OpenGraph and oEmbed tags |
15 | // Do not use a template engine for a so little thing | 15 | // Do not use a template engine for a so little thing |
16 | botsRouter.use('/sitemap.xml', | 16 | botsRouter.use('/sitemap.xml', |
17 | asyncMiddleware(cacheRoute()(ROUTE_CACHE_LIFETIME.SITEMAP)), | 17 | cacheRoute(ROUTE_CACHE_LIFETIME.SITEMAP), |
18 | asyncMiddleware(getSitemap) | 18 | asyncMiddleware(getSitemap) |
19 | ) | 19 | ) |
20 | 20 | ||
@@ -75,13 +75,13 @@ async function getSitemapLocalVideoUrls () { | |||
75 | }) | 75 | }) |
76 | 76 | ||
77 | return data.map(v => ({ | 77 | return data.map(v => ({ |
78 | url: WEBSERVER.URL + '/w/' + v.uuid, | 78 | url: WEBSERVER.URL + v.getWatchStaticPath(), |
79 | video: [ | 79 | video: [ |
80 | { | 80 | { |
81 | title: v.name, | 81 | title: v.name, |
82 | // Sitemap description should be < 2000 characters | 82 | // Sitemap description should be < 2000 characters |
83 | description: truncate(v.description || v.name, { length: 2000, omission: '...' }), | 83 | description: truncate(v.description || v.name, { length: 2000, omission: '...' }), |
84 | player_loc: WEBSERVER.URL + '/videos/embed/' + v.uuid, | 84 | player_loc: WEBSERVER.URL + v.getEmbedStaticPath(), |
85 | thumbnail_loc: WEBSERVER.URL + v.getMiniatureStaticPath() | 85 | thumbnail_loc: WEBSERVER.URL + v.getMiniatureStaticPath() |
86 | } | 86 | } |
87 | ] | 87 | ] |
diff --git a/server/controllers/client.ts b/server/controllers/client.ts index eb1ee6cbd..ba3c54440 100644 --- a/server/controllers/client.ts +++ b/server/controllers/client.ts | |||
@@ -5,7 +5,7 @@ import { join } from 'path' | |||
5 | import { logger } from '@server/helpers/logger' | 5 | import { logger } from '@server/helpers/logger' |
6 | import { CONFIG } from '@server/initializers/config' | 6 | import { CONFIG } from '@server/initializers/config' |
7 | import { Hooks } from '@server/lib/plugins/hooks' | 7 | import { Hooks } from '@server/lib/plugins/hooks' |
8 | import { HttpStatusCode } from '@shared/core-utils' | 8 | import { HttpStatusCode } from '@shared/models' |
9 | import { buildFileLocale, getCompleteLocale, is18nLocale, LOCALE_FILES } from '@shared/core-utils/i18n' | 9 | import { buildFileLocale, getCompleteLocale, is18nLocale, LOCALE_FILES } from '@shared/core-utils/i18n' |
10 | import { root } from '../helpers/core-utils' | 10 | import { root } from '../helpers/core-utils' |
11 | import { STATIC_MAX_AGE } from '../initializers/constants' | 11 | import { STATIC_MAX_AGE } from '../initializers/constants' |
diff --git a/server/controllers/download.ts b/server/controllers/download.ts index 4293a32e2..ddacc1b68 100644 --- a/server/controllers/download.ts +++ b/server/controllers/download.ts | |||
@@ -5,8 +5,7 @@ import { VideosTorrentCache } from '@server/lib/files-cache/videos-torrent-cache | |||
5 | import { Hooks } from '@server/lib/plugins/hooks' | 5 | import { Hooks } from '@server/lib/plugins/hooks' |
6 | import { getVideoFilePath } from '@server/lib/video-paths' | 6 | import { getVideoFilePath } from '@server/lib/video-paths' |
7 | import { MStreamingPlaylist, MVideo, MVideoFile, MVideoFullLight } from '@server/types/models' | 7 | import { MStreamingPlaylist, MVideo, MVideoFile, MVideoFullLight } from '@server/types/models' |
8 | import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' | 8 | import { HttpStatusCode, VideoStreamingPlaylistType } from '@shared/models' |
9 | import { VideoStreamingPlaylistType } from '@shared/models' | ||
10 | import { STATIC_DOWNLOAD_PATHS } from '../initializers/constants' | 9 | import { STATIC_DOWNLOAD_PATHS } from '../initializers/constants' |
11 | import { asyncMiddleware, videosDownloadValidator } from '../middlewares' | 10 | import { asyncMiddleware, videosDownloadValidator } from '../middlewares' |
12 | 11 | ||
diff --git a/server/controllers/feeds.ts b/server/controllers/feeds.ts index 435b12193..9fa70a7c8 100644 --- a/server/controllers/feeds.ts +++ b/server/controllers/feeds.ts | |||
@@ -16,20 +16,20 @@ import { | |||
16 | videosSortValidator, | 16 | videosSortValidator, |
17 | videoSubscriptionFeedsValidator | 17 | videoSubscriptionFeedsValidator |
18 | } from '../middlewares' | 18 | } from '../middlewares' |
19 | import { cacheRoute } from '../middlewares/cache' | 19 | import { cacheRouteFactory } from '../middlewares/cache/cache' |
20 | import { VideoModel } from '../models/video/video' | 20 | import { VideoModel } from '../models/video/video' |
21 | import { VideoCommentModel } from '../models/video/video-comment' | 21 | import { VideoCommentModel } from '../models/video/video-comment' |
22 | 22 | ||
23 | const feedsRouter = express.Router() | 23 | const feedsRouter = express.Router() |
24 | 24 | ||
25 | const cacheRoute = cacheRouteFactory({ | ||
26 | headerBlacklist: [ 'Content-Type' ] | ||
27 | }) | ||
28 | |||
25 | feedsRouter.get('/feeds/video-comments.:format', | 29 | feedsRouter.get('/feeds/video-comments.:format', |
26 | feedsFormatValidator, | 30 | feedsFormatValidator, |
27 | setFeedFormatContentType, | 31 | setFeedFormatContentType, |
28 | asyncMiddleware(cacheRoute({ | 32 | cacheRoute(ROUTE_CACHE_LIFETIME.FEEDS), |
29 | headerBlacklist: [ | ||
30 | 'Content-Type' | ||
31 | ] | ||
32 | })(ROUTE_CACHE_LIFETIME.FEEDS)), | ||
33 | asyncMiddleware(videoFeedsValidator), | 33 | asyncMiddleware(videoFeedsValidator), |
34 | asyncMiddleware(videoCommentsFeedsValidator), | 34 | asyncMiddleware(videoCommentsFeedsValidator), |
35 | asyncMiddleware(generateVideoCommentsFeed) | 35 | asyncMiddleware(generateVideoCommentsFeed) |
@@ -40,11 +40,7 @@ feedsRouter.get('/feeds/videos.:format', | |||
40 | setDefaultVideosSort, | 40 | setDefaultVideosSort, |
41 | feedsFormatValidator, | 41 | feedsFormatValidator, |
42 | setFeedFormatContentType, | 42 | setFeedFormatContentType, |
43 | asyncMiddleware(cacheRoute({ | 43 | cacheRoute(ROUTE_CACHE_LIFETIME.FEEDS), |
44 | headerBlacklist: [ | ||
45 | 'Content-Type' | ||
46 | ] | ||
47 | })(ROUTE_CACHE_LIFETIME.FEEDS)), | ||
48 | commonVideosFiltersValidator, | 44 | commonVideosFiltersValidator, |
49 | asyncMiddleware(videoFeedsValidator), | 45 | asyncMiddleware(videoFeedsValidator), |
50 | asyncMiddleware(generateVideoFeed) | 46 | asyncMiddleware(generateVideoFeed) |
@@ -55,11 +51,7 @@ feedsRouter.get('/feeds/subscriptions.:format', | |||
55 | setDefaultVideosSort, | 51 | setDefaultVideosSort, |
56 | feedsFormatValidator, | 52 | feedsFormatValidator, |
57 | setFeedFormatContentType, | 53 | setFeedFormatContentType, |
58 | asyncMiddleware(cacheRoute({ | 54 | cacheRoute(ROUTE_CACHE_LIFETIME.FEEDS), |
59 | headerBlacklist: [ | ||
60 | 'Content-Type' | ||
61 | ] | ||
62 | })(ROUTE_CACHE_LIFETIME.FEEDS)), | ||
63 | commonVideosFiltersValidator, | 55 | commonVideosFiltersValidator, |
64 | asyncMiddleware(videoSubscriptionFeedsValidator), | 56 | asyncMiddleware(videoSubscriptionFeedsValidator), |
65 | asyncMiddleware(generateVideoFeedForSubscriptions) | 57 | asyncMiddleware(generateVideoFeedForSubscriptions) |
@@ -294,7 +286,7 @@ function addVideosToFeed (feed, videos: VideoModel[]) { | |||
294 | feed.addItem({ | 286 | feed.addItem({ |
295 | title: video.name, | 287 | title: video.name, |
296 | id: video.url, | 288 | id: video.url, |
297 | link: WEBSERVER.URL + '/w/' + video.uuid, | 289 | link: WEBSERVER.URL + video.getWatchStaticPath(), |
298 | description: video.getTruncatedDescription(), | 290 | description: video.getTruncatedDescription(), |
299 | content: video.description, | 291 | content: video.description, |
300 | author: [ | 292 | author: [ |
diff --git a/server/controllers/lazy-static.ts b/server/controllers/lazy-static.ts index 9a7dacba0..632e4dcd8 100644 --- a/server/controllers/lazy-static.ts +++ b/server/controllers/lazy-static.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import * as cors from 'cors' | 1 | import * as cors from 'cors' |
2 | import * as express from 'express' | 2 | import * as express from 'express' |
3 | import { VideosTorrentCache } from '@server/lib/files-cache/videos-torrent-cache' | 3 | import { VideosTorrentCache } from '@server/lib/files-cache/videos-torrent-cache' |
4 | import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes' | 4 | import { HttpStatusCode } from '../../shared/models/http/http-error-codes' |
5 | import { logger } from '../helpers/logger' | 5 | import { logger } from '../helpers/logger' |
6 | import { LAZY_STATIC_PATHS, STATIC_MAX_AGE } from '../initializers/constants' | 6 | import { LAZY_STATIC_PATHS, STATIC_MAX_AGE } from '../initializers/constants' |
7 | import { VideosCaptionCache, VideosPreviewCache } from '../lib/files-cache' | 7 | import { VideosCaptionCache, VideosPreviewCache } from '../lib/files-cache' |
diff --git a/server/controllers/live.ts b/server/controllers/live.ts index f2686fb23..95d5c0135 100644 --- a/server/controllers/live.ts +++ b/server/controllers/live.ts | |||
@@ -2,7 +2,7 @@ import * as cors from 'cors' | |||
2 | import * as express from 'express' | 2 | import * as express from 'express' |
3 | import { mapToJSON } from '@server/helpers/core-utils' | 3 | import { mapToJSON } from '@server/helpers/core-utils' |
4 | import { LiveSegmentShaStore } from '@server/lib/live' | 4 | import { LiveSegmentShaStore } from '@server/lib/live' |
5 | import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' | 5 | import { HttpStatusCode } from '@shared/models' |
6 | 6 | ||
7 | const liveRouter = express.Router() | 7 | const liveRouter = express.Router() |
8 | 8 | ||
diff --git a/server/controllers/plugins.ts b/server/controllers/plugins.ts index 7213e3f15..11ab3f10a 100644 --- a/server/controllers/plugins.ts +++ b/server/controllers/plugins.ts | |||
@@ -3,7 +3,7 @@ import { join } from 'path' | |||
3 | import { logger } from '@server/helpers/logger' | 3 | import { logger } from '@server/helpers/logger' |
4 | import { optionalAuthenticate } from '@server/middlewares/auth' | 4 | import { optionalAuthenticate } from '@server/middlewares/auth' |
5 | import { getCompleteLocale, is18nLocale } from '../../shared/core-utils/i18n' | 5 | import { getCompleteLocale, is18nLocale } from '../../shared/core-utils/i18n' |
6 | import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes' | 6 | import { HttpStatusCode } from '../../shared/models/http/http-error-codes' |
7 | import { PluginType } from '../../shared/models/plugins/plugin.type' | 7 | import { PluginType } from '../../shared/models/plugins/plugin.type' |
8 | import { isTestInstance } from '../helpers/core-utils' | 8 | import { isTestInstance } from '../helpers/core-utils' |
9 | import { PLUGIN_GLOBAL_CSS_PATH } from '../initializers/constants' | 9 | import { PLUGIN_GLOBAL_CSS_PATH } from '../initializers/constants' |
diff --git a/server/controllers/static.ts b/server/controllers/static.ts index 35e024dda..912d7e36c 100644 --- a/server/controllers/static.ts +++ b/server/controllers/static.ts | |||
@@ -3,7 +3,7 @@ import * as express from 'express' | |||
3 | import { join } from 'path' | 3 | import { join } from 'path' |
4 | import { serveIndexHTML } from '@server/lib/client-html' | 4 | import { serveIndexHTML } from '@server/lib/client-html' |
5 | import { ServerConfigManager } from '@server/lib/server-config-manager' | 5 | import { ServerConfigManager } from '@server/lib/server-config-manager' |
6 | import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' | 6 | import { HttpStatusCode } from '@shared/models' |
7 | import { HttpNodeinfoDiasporaSoftwareNsSchema20 } from '../../shared/models/nodeinfo/nodeinfo.model' | 7 | import { HttpNodeinfoDiasporaSoftwareNsSchema20 } from '../../shared/models/nodeinfo/nodeinfo.model' |
8 | import { root } from '../helpers/core-utils' | 8 | import { root } from '../helpers/core-utils' |
9 | import { CONFIG, isEmailEnabled } from '../initializers/config' | 9 | import { CONFIG, isEmailEnabled } from '../initializers/config' |
@@ -19,7 +19,7 @@ import { | |||
19 | } from '../initializers/constants' | 19 | } from '../initializers/constants' |
20 | import { getThemeOrDefault } from '../lib/plugins/theme-utils' | 20 | import { getThemeOrDefault } from '../lib/plugins/theme-utils' |
21 | import { asyncMiddleware } from '../middlewares' | 21 | import { asyncMiddleware } from '../middlewares' |
22 | import { cacheRoute } from '../middlewares/cache' | 22 | import { cacheRoute } from '../middlewares/cache/cache' |
23 | import { UserModel } from '../models/user/user' | 23 | import { UserModel } from '../models/user/user' |
24 | import { VideoModel } from '../models/video/video' | 24 | import { VideoModel } from '../models/video/video' |
25 | import { VideoCommentModel } from '../models/video/video-comment' | 25 | import { VideoCommentModel } from '../models/video/video-comment' |
@@ -66,7 +66,7 @@ staticRouter.use( | |||
66 | 66 | ||
67 | // robots.txt service | 67 | // robots.txt service |
68 | staticRouter.get('/robots.txt', | 68 | staticRouter.get('/robots.txt', |
69 | asyncMiddleware(cacheRoute()(ROUTE_CACHE_LIFETIME.ROBOTS)), | 69 | cacheRoute(ROUTE_CACHE_LIFETIME.ROBOTS), |
70 | (_, res: express.Response) => { | 70 | (_, res: express.Response) => { |
71 | res.type('text/plain') | 71 | res.type('text/plain') |
72 | return res.send(CONFIG.INSTANCE.ROBOTS) | 72 | return res.send(CONFIG.INSTANCE.ROBOTS) |
@@ -86,7 +86,7 @@ staticRouter.get('/security.txt', | |||
86 | ) | 86 | ) |
87 | 87 | ||
88 | staticRouter.get('/.well-known/security.txt', | 88 | staticRouter.get('/.well-known/security.txt', |
89 | asyncMiddleware(cacheRoute()(ROUTE_CACHE_LIFETIME.SECURITYTXT)), | 89 | cacheRoute(ROUTE_CACHE_LIFETIME.SECURITYTXT), |
90 | (_, res: express.Response) => { | 90 | (_, res: express.Response) => { |
91 | res.type('text/plain') | 91 | res.type('text/plain') |
92 | return res.send(CONFIG.INSTANCE.SECURITYTXT + CONFIG.INSTANCE.SECURITYTXT_CONTACT) | 92 | return res.send(CONFIG.INSTANCE.SECURITYTXT + CONFIG.INSTANCE.SECURITYTXT_CONTACT) |
@@ -95,7 +95,7 @@ staticRouter.get('/.well-known/security.txt', | |||
95 | 95 | ||
96 | // nodeinfo service | 96 | // nodeinfo service |
97 | staticRouter.use('/.well-known/nodeinfo', | 97 | staticRouter.use('/.well-known/nodeinfo', |
98 | asyncMiddleware(cacheRoute()(ROUTE_CACHE_LIFETIME.NODEINFO)), | 98 | cacheRoute(ROUTE_CACHE_LIFETIME.NODEINFO), |
99 | (_, res: express.Response) => { | 99 | (_, res: express.Response) => { |
100 | return res.json({ | 100 | return res.json({ |
101 | links: [ | 101 | links: [ |
@@ -108,13 +108,13 @@ staticRouter.use('/.well-known/nodeinfo', | |||
108 | } | 108 | } |
109 | ) | 109 | ) |
110 | staticRouter.use('/nodeinfo/:version.json', | 110 | staticRouter.use('/nodeinfo/:version.json', |
111 | asyncMiddleware(cacheRoute()(ROUTE_CACHE_LIFETIME.NODEINFO)), | 111 | cacheRoute(ROUTE_CACHE_LIFETIME.NODEINFO), |
112 | asyncMiddleware(generateNodeinfo) | 112 | asyncMiddleware(generateNodeinfo) |
113 | ) | 113 | ) |
114 | 114 | ||
115 | // dnt-policy.txt service (see https://www.eff.org/dnt-policy) | 115 | // dnt-policy.txt service (see https://www.eff.org/dnt-policy) |
116 | staticRouter.use('/.well-known/dnt-policy.txt', | 116 | staticRouter.use('/.well-known/dnt-policy.txt', |
117 | asyncMiddleware(cacheRoute()(ROUTE_CACHE_LIFETIME.DNT_POLICY)), | 117 | cacheRoute(ROUTE_CACHE_LIFETIME.DNT_POLICY), |
118 | (_, res: express.Response) => { | 118 | (_, res: express.Response) => { |
119 | res.type('text/plain') | 119 | res.type('text/plain') |
120 | 120 | ||