diff options
Diffstat (limited to 'server/controllers/api/videos')
-rw-r--r-- | server/controllers/api/videos/abuse.ts | 7 | ||||
-rw-r--r-- | server/controllers/api/videos/blacklist.ts | 17 | ||||
-rw-r--r-- | server/controllers/api/videos/captions.ts | 9 | ||||
-rw-r--r-- | server/controllers/api/videos/comment.ts | 17 | ||||
-rw-r--r-- | server/controllers/api/videos/import.ts | 34 | ||||
-rw-r--r-- | server/controllers/api/videos/index.ts | 17 | ||||
-rw-r--r-- | server/controllers/api/videos/ownership.ts | 5 | ||||
-rw-r--r-- | server/controllers/api/videos/rate.ts | 2 | ||||
-rw-r--r-- | server/controllers/api/videos/watching.ts | 2 |
9 files changed, 59 insertions, 51 deletions
diff --git a/server/controllers/api/videos/abuse.ts b/server/controllers/api/videos/abuse.ts index 77808466c..39c841ffe 100644 --- a/server/controllers/api/videos/abuse.ts +++ b/server/controllers/api/videos/abuse.ts | |||
@@ -21,6 +21,7 @@ import { VideoAbuseModel } from '../../../models/video/video-abuse' | |||
21 | import { auditLoggerFactory, VideoAbuseAuditView } from '../../../helpers/audit-logger' | 21 | import { auditLoggerFactory, VideoAbuseAuditView } from '../../../helpers/audit-logger' |
22 | import { Notifier } from '../../../lib/notifier' | 22 | import { Notifier } from '../../../lib/notifier' |
23 | import { sendVideoAbuse } from '../../../lib/activitypub/send/send-flag' | 23 | import { sendVideoAbuse } from '../../../lib/activitypub/send/send-flag' |
24 | import { MVideoAbuseAccountVideo } from '../../../typings/models/video' | ||
24 | 25 | ||
25 | const auditLogger = auditLoggerFactory('abuse') | 26 | const auditLogger = auditLoggerFactory('abuse') |
26 | const abuseVideoRouter = express.Router() | 27 | const abuseVideoRouter = express.Router() |
@@ -94,10 +95,10 @@ async function deleteVideoAbuse (req: express.Request, res: express.Response) { | |||
94 | } | 95 | } |
95 | 96 | ||
96 | async function reportVideoAbuse (req: express.Request, res: express.Response) { | 97 | async function reportVideoAbuse (req: express.Request, res: express.Response) { |
97 | const videoInstance = res.locals.video | 98 | const videoInstance = res.locals.videoAll |
98 | const body: VideoAbuseCreate = req.body | 99 | const body: VideoAbuseCreate = req.body |
99 | 100 | ||
100 | const videoAbuse: VideoAbuseModel = await sequelizeTypescript.transaction(async t => { | 101 | const videoAbuse = await sequelizeTypescript.transaction(async t => { |
101 | const reporterAccount = await AccountModel.load(res.locals.oauth.token.User.Account.id, t) | 102 | const reporterAccount = await AccountModel.load(res.locals.oauth.token.User.Account.id, t) |
102 | 103 | ||
103 | const abuseToCreate = { | 104 | const abuseToCreate = { |
@@ -107,7 +108,7 @@ async function reportVideoAbuse (req: express.Request, res: express.Response) { | |||
107 | state: VideoAbuseState.PENDING | 108 | state: VideoAbuseState.PENDING |
108 | } | 109 | } |
109 | 110 | ||
110 | const videoAbuseInstance = await VideoAbuseModel.create(abuseToCreate, { transaction: t }) | 111 | const videoAbuseInstance: MVideoAbuseAccountVideo = await VideoAbuseModel.create(abuseToCreate, { transaction: t }) |
111 | videoAbuseInstance.Video = videoInstance | 112 | videoAbuseInstance.Video = videoInstance |
112 | videoAbuseInstance.Account = reporterAccount | 113 | videoAbuseInstance.Account = reporterAccount |
113 | 114 | ||
diff --git a/server/controllers/api/videos/blacklist.ts b/server/controllers/api/videos/blacklist.ts index 9ff494def..2a667480d 100644 --- a/server/controllers/api/videos/blacklist.ts +++ b/server/controllers/api/videos/blacklist.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { VideoBlacklist, UserRight, VideoBlacklistCreate, VideoBlacklistType } from '../../../../shared' | 2 | import { UserRight, VideoBlacklistCreate, VideoBlacklistType } from '../../../../shared' |
3 | import { logger } from '../../../helpers/logger' | 3 | import { logger } from '../../../helpers/logger' |
4 | import { getFormattedObjects } from '../../../helpers/utils' | 4 | import { getFormattedObjects } from '../../../helpers/utils' |
5 | import { | 5 | import { |
@@ -11,15 +11,16 @@ import { | |||
11 | setBlacklistSort, | 11 | setBlacklistSort, |
12 | setDefaultPagination, | 12 | setDefaultPagination, |
13 | videosBlacklistAddValidator, | 13 | videosBlacklistAddValidator, |
14 | videosBlacklistFiltersValidator, | ||
14 | videosBlacklistRemoveValidator, | 15 | videosBlacklistRemoveValidator, |
15 | videosBlacklistUpdateValidator, | 16 | videosBlacklistUpdateValidator |
16 | videosBlacklistFiltersValidator | ||
17 | } from '../../../middlewares' | 17 | } from '../../../middlewares' |
18 | import { VideoBlacklistModel } from '../../../models/video/video-blacklist' | 18 | import { VideoBlacklistModel } from '../../../models/video/video-blacklist' |
19 | import { sequelizeTypescript } from '../../../initializers' | 19 | import { sequelizeTypescript } from '../../../initializers' |
20 | import { Notifier } from '../../../lib/notifier' | 20 | import { Notifier } from '../../../lib/notifier' |
21 | import { sendDeleteVideo } from '../../../lib/activitypub/send' | 21 | import { sendDeleteVideo } from '../../../lib/activitypub/send' |
22 | import { federateVideoIfNeeded } from '../../../lib/activitypub' | 22 | import { federateVideoIfNeeded } from '../../../lib/activitypub' |
23 | import { MVideoBlacklistVideo } from '@server/typings/models' | ||
23 | 24 | ||
24 | const blacklistRouter = express.Router() | 25 | const blacklistRouter = express.Router() |
25 | 26 | ||
@@ -64,7 +65,7 @@ export { | |||
64 | // --------------------------------------------------------------------------- | 65 | // --------------------------------------------------------------------------- |
65 | 66 | ||
66 | async function addVideoToBlacklist (req: express.Request, res: express.Response) { | 67 | async function addVideoToBlacklist (req: express.Request, res: express.Response) { |
67 | const videoInstance = res.locals.video | 68 | const videoInstance = res.locals.videoAll |
68 | const body: VideoBlacklistCreate = req.body | 69 | const body: VideoBlacklistCreate = req.body |
69 | 70 | ||
70 | const toCreate = { | 71 | const toCreate = { |
@@ -74,7 +75,7 @@ async function addVideoToBlacklist (req: express.Request, res: express.Response) | |||
74 | type: VideoBlacklistType.MANUAL | 75 | type: VideoBlacklistType.MANUAL |
75 | } | 76 | } |
76 | 77 | ||
77 | const blacklist = await VideoBlacklistModel.create(toCreate) | 78 | const blacklist: MVideoBlacklistVideo = await VideoBlacklistModel.create(toCreate) |
78 | blacklist.Video = videoInstance | 79 | blacklist.Video = videoInstance |
79 | 80 | ||
80 | if (body.unfederate === true) { | 81 | if (body.unfederate === true) { |
@@ -83,7 +84,7 @@ async function addVideoToBlacklist (req: express.Request, res: express.Response) | |||
83 | 84 | ||
84 | Notifier.Instance.notifyOnVideoBlacklist(blacklist) | 85 | Notifier.Instance.notifyOnVideoBlacklist(blacklist) |
85 | 86 | ||
86 | logger.info('Video %s blacklisted.', res.locals.video.uuid) | 87 | logger.info('Video %s blacklisted.', videoInstance.uuid) |
87 | 88 | ||
88 | return res.type('json').status(204).end() | 89 | return res.type('json').status(204).end() |
89 | } | 90 | } |
@@ -108,7 +109,7 @@ async function listBlacklist (req: express.Request, res: express.Response) { | |||
108 | 109 | ||
109 | async function removeVideoFromBlacklistController (req: express.Request, res: express.Response) { | 110 | async function removeVideoFromBlacklistController (req: express.Request, res: express.Response) { |
110 | const videoBlacklist = res.locals.videoBlacklist | 111 | const videoBlacklist = res.locals.videoBlacklist |
111 | const video = res.locals.video | 112 | const video = res.locals.videoAll |
112 | 113 | ||
113 | const videoBlacklistType = await sequelizeTypescript.transaction(async t => { | 114 | const videoBlacklistType = await sequelizeTypescript.transaction(async t => { |
114 | const unfederated = videoBlacklist.unfederated | 115 | const unfederated = videoBlacklist.unfederated |
@@ -135,7 +136,7 @@ async function removeVideoFromBlacklistController (req: express.Request, res: ex | |||
135 | Notifier.Instance.notifyOnNewVideoIfNeeded(video) | 136 | Notifier.Instance.notifyOnNewVideoIfNeeded(video) |
136 | } | 137 | } |
137 | 138 | ||
138 | logger.info('Video %s removed from blacklist.', res.locals.video.uuid) | 139 | logger.info('Video %s removed from blacklist.', video.uuid) |
139 | 140 | ||
140 | return res.type('json').status(204).end() | 141 | return res.type('json').status(204).end() |
141 | } | 142 | } |
diff --git a/server/controllers/api/videos/captions.ts b/server/controllers/api/videos/captions.ts index 44c255232..37481d12f 100644 --- a/server/controllers/api/videos/captions.ts +++ b/server/controllers/api/videos/captions.ts | |||
@@ -10,6 +10,7 @@ import { federateVideoIfNeeded } from '../../../lib/activitypub' | |||
10 | import { moveAndProcessCaptionFile } from '../../../helpers/captions-utils' | 10 | import { moveAndProcessCaptionFile } from '../../../helpers/captions-utils' |
11 | import { CONFIG } from '../../../initializers/config' | 11 | import { CONFIG } from '../../../initializers/config' |
12 | import { sequelizeTypescript } from '../../../initializers/database' | 12 | import { sequelizeTypescript } from '../../../initializers/database' |
13 | import { MVideoCaptionVideo } from '@server/typings/models' | ||
13 | 14 | ||
14 | const reqVideoCaptionAdd = createReqFiles( | 15 | const reqVideoCaptionAdd = createReqFiles( |
15 | [ 'captionfile' ], | 16 | [ 'captionfile' ], |
@@ -46,19 +47,19 @@ export { | |||
46 | // --------------------------------------------------------------------------- | 47 | // --------------------------------------------------------------------------- |
47 | 48 | ||
48 | async function listVideoCaptions (req: express.Request, res: express.Response) { | 49 | async function listVideoCaptions (req: express.Request, res: express.Response) { |
49 | const data = await VideoCaptionModel.listVideoCaptions(res.locals.video.id) | 50 | const data = await VideoCaptionModel.listVideoCaptions(res.locals.videoId.id) |
50 | 51 | ||
51 | return res.json(getFormattedObjects(data, data.length)) | 52 | return res.json(getFormattedObjects(data, data.length)) |
52 | } | 53 | } |
53 | 54 | ||
54 | async function addVideoCaption (req: express.Request, res: express.Response) { | 55 | async function addVideoCaption (req: express.Request, res: express.Response) { |
55 | const videoCaptionPhysicalFile = req.files['captionfile'][0] | 56 | const videoCaptionPhysicalFile = req.files['captionfile'][0] |
56 | const video = res.locals.video | 57 | const video = res.locals.videoAll |
57 | 58 | ||
58 | const videoCaption = new VideoCaptionModel({ | 59 | const videoCaption = new VideoCaptionModel({ |
59 | videoId: video.id, | 60 | videoId: video.id, |
60 | language: req.params.captionLanguage | 61 | language: req.params.captionLanguage |
61 | }) | 62 | }) as MVideoCaptionVideo |
62 | videoCaption.Video = video | 63 | videoCaption.Video = video |
63 | 64 | ||
64 | // Move physical file | 65 | // Move physical file |
@@ -75,7 +76,7 @@ async function addVideoCaption (req: express.Request, res: express.Response) { | |||
75 | } | 76 | } |
76 | 77 | ||
77 | async function deleteVideoCaption (req: express.Request, res: express.Response) { | 78 | async function deleteVideoCaption (req: express.Request, res: express.Response) { |
78 | const video = res.locals.video | 79 | const video = res.locals.videoAll |
79 | const videoCaption = res.locals.videoCaption | 80 | const videoCaption = res.locals.videoCaption |
80 | 81 | ||
81 | await sequelizeTypescript.transaction(async t => { | 82 | await sequelizeTypescript.transaction(async t => { |
diff --git a/server/controllers/api/videos/comment.ts b/server/controllers/api/videos/comment.ts index bc6d81a7c..b2b06b170 100644 --- a/server/controllers/api/videos/comment.ts +++ b/server/controllers/api/videos/comment.ts | |||
@@ -27,9 +27,6 @@ import { auditLoggerFactory, CommentAuditView, getAuditIdFromRes } from '../../. | |||
27 | import { AccountModel } from '../../../models/account/account' | 27 | import { AccountModel } from '../../../models/account/account' |
28 | import { Notifier } from '../../../lib/notifier' | 28 | import { Notifier } from '../../../lib/notifier' |
29 | import { Hooks } from '../../../lib/plugins/hooks' | 29 | import { Hooks } from '../../../lib/plugins/hooks' |
30 | import { ActorModel } from '../../../models/activitypub/actor' | ||
31 | import { VideoChannelModel } from '../../../models/video/video-channel' | ||
32 | import { VideoModel } from '../../../models/video/video' | ||
33 | import { sendDeleteVideoComment } from '../../../lib/activitypub/send' | 30 | import { sendDeleteVideoComment } from '../../../lib/activitypub/send' |
34 | 31 | ||
35 | const auditLogger = auditLoggerFactory('comments') | 32 | const auditLogger = auditLoggerFactory('comments') |
@@ -75,7 +72,7 @@ export { | |||
75 | // --------------------------------------------------------------------------- | 72 | // --------------------------------------------------------------------------- |
76 | 73 | ||
77 | async function listVideoThreads (req: express.Request, res: express.Response) { | 74 | async function listVideoThreads (req: express.Request, res: express.Response) { |
78 | const video = res.locals.video | 75 | const video = res.locals.onlyVideo |
79 | const user = res.locals.oauth ? res.locals.oauth.token.User : undefined | 76 | const user = res.locals.oauth ? res.locals.oauth.token.User : undefined |
80 | 77 | ||
81 | let resultList: ResultList<VideoCommentModel> | 78 | let resultList: ResultList<VideoCommentModel> |
@@ -86,7 +83,7 @@ async function listVideoThreads (req: express.Request, res: express.Response) { | |||
86 | start: req.query.start, | 83 | start: req.query.start, |
87 | count: req.query.count, | 84 | count: req.query.count, |
88 | sort: req.query.sort, | 85 | sort: req.query.sort, |
89 | user: user | 86 | user |
90 | }, 'filter:api.video-threads.list.params') | 87 | }, 'filter:api.video-threads.list.params') |
91 | 88 | ||
92 | resultList = await Hooks.wrapPromiseFun( | 89 | resultList = await Hooks.wrapPromiseFun( |
@@ -105,7 +102,7 @@ async function listVideoThreads (req: express.Request, res: express.Response) { | |||
105 | } | 102 | } |
106 | 103 | ||
107 | async function listVideoThreadComments (req: express.Request, res: express.Response) { | 104 | async function listVideoThreadComments (req: express.Request, res: express.Response) { |
108 | const video = res.locals.video | 105 | const video = res.locals.onlyVideo |
109 | const user = res.locals.oauth ? res.locals.oauth.token.User : undefined | 106 | const user = res.locals.oauth ? res.locals.oauth.token.User : undefined |
110 | 107 | ||
111 | let resultList: ResultList<VideoCommentModel> | 108 | let resultList: ResultList<VideoCommentModel> |
@@ -141,7 +138,7 @@ async function addVideoCommentThread (req: express.Request, res: express.Respons | |||
141 | return createVideoComment({ | 138 | return createVideoComment({ |
142 | text: videoCommentInfo.text, | 139 | text: videoCommentInfo.text, |
143 | inReplyToComment: null, | 140 | inReplyToComment: null, |
144 | video: res.locals.video, | 141 | video: res.locals.videoAll, |
145 | account | 142 | account |
146 | }, t) | 143 | }, t) |
147 | }) | 144 | }) |
@@ -164,8 +161,8 @@ async function addVideoCommentReply (req: express.Request, res: express.Response | |||
164 | 161 | ||
165 | return createVideoComment({ | 162 | return createVideoComment({ |
166 | text: videoCommentInfo.text, | 163 | text: videoCommentInfo.text, |
167 | inReplyToComment: res.locals.videoComment, | 164 | inReplyToComment: res.locals.videoCommentFull, |
168 | video: res.locals.video, | 165 | video: res.locals.videoAll, |
169 | account | 166 | account |
170 | }, t) | 167 | }, t) |
171 | }) | 168 | }) |
@@ -179,7 +176,7 @@ async function addVideoCommentReply (req: express.Request, res: express.Response | |||
179 | } | 176 | } |
180 | 177 | ||
181 | async function removeVideoComment (req: express.Request, res: express.Response) { | 178 | async function removeVideoComment (req: express.Request, res: express.Response) { |
182 | const videoCommentInstance = res.locals.videoComment | 179 | const videoCommentInstance = res.locals.videoCommentFull |
183 | 180 | ||
184 | await sequelizeTypescript.transaction(async t => { | 181 | await sequelizeTypescript.transaction(async t => { |
185 | await videoCommentInstance.destroy({ transaction: t }) | 182 | await videoCommentInstance.destroy({ transaction: t }) |
diff --git a/server/controllers/api/videos/import.ts b/server/controllers/api/videos/import.ts index 04c9b547b..8879f3442 100644 --- a/server/controllers/api/videos/import.ts +++ b/server/controllers/api/videos/import.ts | |||
@@ -1,6 +1,5 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import * as magnetUtil from 'magnet-uri' | 2 | import * as magnetUtil from 'magnet-uri' |
3 | import 'multer' | ||
4 | import { auditLoggerFactory, getAuditIdFromRes, VideoImportAuditView } from '../../../helpers/audit-logger' | 3 | import { auditLoggerFactory, getAuditIdFromRes, VideoImportAuditView } from '../../../helpers/audit-logger' |
5 | import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoImportAddValidator } from '../../../middlewares' | 4 | import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoImportAddValidator } from '../../../middlewares' |
6 | import { MIMETYPES } from '../../../initializers/constants' | 5 | import { MIMETYPES } from '../../../initializers/constants' |
@@ -15,7 +14,6 @@ import { VideoImportModel } from '../../../models/video/video-import' | |||
15 | import { JobQueue } from '../../../lib/job-queue/job-queue' | 14 | import { JobQueue } from '../../../lib/job-queue/job-queue' |
16 | import { join } from 'path' | 15 | import { join } from 'path' |
17 | import { isArray } from '../../../helpers/custom-validators/misc' | 16 | import { isArray } from '../../../helpers/custom-validators/misc' |
18 | import { VideoChannelModel } from '../../../models/video/video-channel' | ||
19 | import * as Bluebird from 'bluebird' | 17 | import * as Bluebird from 'bluebird' |
20 | import * as parseTorrent from 'parse-torrent' | 18 | import * as parseTorrent from 'parse-torrent' |
21 | import { getSecureTorrentName } from '../../../helpers/utils' | 19 | import { getSecureTorrentName } from '../../../helpers/utils' |
@@ -25,8 +23,16 @@ import { CONFIG } from '../../../initializers/config' | |||
25 | import { sequelizeTypescript } from '../../../initializers/database' | 23 | import { sequelizeTypescript } from '../../../initializers/database' |
26 | import { createVideoMiniatureFromExisting } from '../../../lib/thumbnail' | 24 | import { createVideoMiniatureFromExisting } from '../../../lib/thumbnail' |
27 | import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type' | 25 | import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type' |
28 | import { ThumbnailModel } from '../../../models/video/thumbnail' | 26 | import { |
29 | import { UserModel } from '../../../models/account/user' | 27 | MChannelAccountDefault, |
28 | MThumbnail, | ||
29 | MUser, | ||
30 | MVideoAccountDefault, | ||
31 | MVideoTag, | ||
32 | MVideoThumbnailAccountDefault, | ||
33 | MVideoWithBlacklistLight | ||
34 | } from '@server/typings/models' | ||
35 | import { MVideoImport, MVideoImportFormattable } from '@server/typings/models/video/video-import' | ||
30 | 36 | ||
31 | const auditLogger = auditLoggerFactory('video-imports') | 37 | const auditLogger = auditLoggerFactory('video-imports') |
32 | const videoImportsRouter = express.Router() | 38 | const videoImportsRouter = express.Router() |
@@ -225,28 +231,28 @@ async function processPreview (req: express.Request, video: VideoModel) { | |||
225 | } | 231 | } |
226 | 232 | ||
227 | function insertIntoDB (parameters: { | 233 | function insertIntoDB (parameters: { |
228 | video: VideoModel, | 234 | video: MVideoThumbnailAccountDefault, |
229 | thumbnailModel: ThumbnailModel, | 235 | thumbnailModel: MThumbnail, |
230 | previewModel: ThumbnailModel, | 236 | previewModel: MThumbnail, |
231 | videoChannel: VideoChannelModel, | 237 | videoChannel: MChannelAccountDefault, |
232 | tags: string[], | 238 | tags: string[], |
233 | videoImportAttributes: Partial<VideoImportModel>, | 239 | videoImportAttributes: Partial<MVideoImport>, |
234 | user: UserModel | 240 | user: MUser |
235 | }): Bluebird<VideoImportModel> { | 241 | }): Bluebird<MVideoImportFormattable> { |
236 | const { video, thumbnailModel, previewModel, videoChannel, tags, videoImportAttributes, user } = parameters | 242 | const { video, thumbnailModel, previewModel, videoChannel, tags, videoImportAttributes, user } = parameters |
237 | 243 | ||
238 | return sequelizeTypescript.transaction(async t => { | 244 | return sequelizeTypescript.transaction(async t => { |
239 | const sequelizeOptions = { transaction: t } | 245 | const sequelizeOptions = { transaction: t } |
240 | 246 | ||
241 | // Save video object in database | 247 | // Save video object in database |
242 | const videoCreated = await video.save(sequelizeOptions) | 248 | const videoCreated = await video.save(sequelizeOptions) as (MVideoAccountDefault & MVideoWithBlacklistLight & MVideoTag) |
243 | videoCreated.VideoChannel = videoChannel | 249 | videoCreated.VideoChannel = videoChannel |
244 | 250 | ||
245 | if (thumbnailModel) await videoCreated.addAndSaveThumbnail(thumbnailModel, t) | 251 | if (thumbnailModel) await videoCreated.addAndSaveThumbnail(thumbnailModel, t) |
246 | if (previewModel) await videoCreated.addAndSaveThumbnail(previewModel, t) | 252 | if (previewModel) await videoCreated.addAndSaveThumbnail(previewModel, t) |
247 | 253 | ||
248 | await autoBlacklistVideoIfNeeded({ | 254 | await autoBlacklistVideoIfNeeded({ |
249 | video, | 255 | video: videoCreated, |
250 | user, | 256 | user, |
251 | notify: false, | 257 | notify: false, |
252 | isRemote: false, | 258 | isRemote: false, |
@@ -268,7 +274,7 @@ function insertIntoDB (parameters: { | |||
268 | const videoImport = await VideoImportModel.create( | 274 | const videoImport = await VideoImportModel.create( |
269 | Object.assign({ videoId: videoCreated.id }, videoImportAttributes), | 275 | Object.assign({ videoId: videoCreated.id }, videoImportAttributes), |
270 | sequelizeOptions | 276 | sequelizeOptions |
271 | ) | 277 | ) as MVideoImportFormattable |
272 | videoImport.Video = videoCreated | 278 | videoImport.Video = videoCreated |
273 | 279 | ||
274 | return videoImport | 280 | return videoImport |
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index 155ca4678..b4f656575 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts | |||
@@ -63,6 +63,7 @@ import { createVideoMiniatureFromExisting, generateVideoMiniature } from '../../ | |||
63 | import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type' | 63 | import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type' |
64 | import { VideoTranscodingPayload } from '../../../lib/job-queue/handlers/video-transcoding' | 64 | import { VideoTranscodingPayload } from '../../../lib/job-queue/handlers/video-transcoding' |
65 | import { Hooks } from '../../../lib/plugins/hooks' | 65 | import { Hooks } from '../../../lib/plugins/hooks' |
66 | import { MVideoDetails, MVideoFullLight } from '@server/typings/models' | ||
66 | 67 | ||
67 | const auditLogger = auditLoggerFactory('videos') | 68 | const auditLogger = auditLoggerFactory('videos') |
68 | const videosRouter = express.Router() | 69 | const videosRouter = express.Router() |
@@ -197,7 +198,7 @@ async function addVideo (req: express.Request, res: express.Response) { | |||
197 | originallyPublishedAt: videoInfo.originallyPublishedAt | 198 | originallyPublishedAt: videoInfo.originallyPublishedAt |
198 | } | 199 | } |
199 | 200 | ||
200 | const video = new VideoModel(videoData) | 201 | const video = new VideoModel(videoData) as MVideoDetails |
201 | video.url = getVideoActivityPubUrl(video) // We use the UUID, so set the URL after building the object | 202 | video.url = getVideoActivityPubUrl(video) // We use the UUID, so set the URL after building the object |
202 | 203 | ||
203 | const videoFile = new VideoFileModel({ | 204 | const videoFile = new VideoFileModel({ |
@@ -238,7 +239,7 @@ async function addVideo (req: express.Request, res: express.Response) { | |||
238 | const { videoCreated } = await sequelizeTypescript.transaction(async t => { | 239 | const { videoCreated } = await sequelizeTypescript.transaction(async t => { |
239 | const sequelizeOptions = { transaction: t } | 240 | const sequelizeOptions = { transaction: t } |
240 | 241 | ||
241 | const videoCreated = await video.save(sequelizeOptions) | 242 | const videoCreated = await video.save(sequelizeOptions) as MVideoFullLight |
242 | 243 | ||
243 | await videoCreated.addAndSaveThumbnail(thumbnailModel, t) | 244 | await videoCreated.addAndSaveThumbnail(thumbnailModel, t) |
244 | await videoCreated.addAndSaveThumbnail(previewModel, t) | 245 | await videoCreated.addAndSaveThumbnail(previewModel, t) |
@@ -318,7 +319,7 @@ async function addVideo (req: express.Request, res: express.Response) { | |||
318 | } | 319 | } |
319 | 320 | ||
320 | async function updateVideo (req: express.Request, res: express.Response) { | 321 | async function updateVideo (req: express.Request, res: express.Response) { |
321 | const videoInstance = res.locals.video | 322 | const videoInstance = res.locals.videoAll |
322 | const videoFieldsSave = videoInstance.toJSON() | 323 | const videoFieldsSave = videoInstance.toJSON() |
323 | const oldVideoAuditView = new VideoAuditView(videoInstance.toFormattedDetailsJSON()) | 324 | const oldVideoAuditView = new VideoAuditView(videoInstance.toFormattedDetailsJSON()) |
324 | const videoInfoToUpdate: VideoUpdate = req.body | 325 | const videoInfoToUpdate: VideoUpdate = req.body |
@@ -371,7 +372,7 @@ async function updateVideo (req: express.Request, res: express.Response) { | |||
371 | } | 372 | } |
372 | } | 373 | } |
373 | 374 | ||
374 | const videoInstanceUpdated = await videoInstance.save(sequelizeOptions) | 375 | const videoInstanceUpdated = await videoInstance.save(sequelizeOptions) as MVideoFullLight |
375 | 376 | ||
376 | if (thumbnailModel) await videoInstanceUpdated.addAndSaveThumbnail(thumbnailModel, t) | 377 | if (thumbnailModel) await videoInstanceUpdated.addAndSaveThumbnail(thumbnailModel, t) |
377 | if (previewModel) await videoInstanceUpdated.addAndSaveThumbnail(previewModel, t) | 378 | if (previewModel) await videoInstanceUpdated.addAndSaveThumbnail(previewModel, t) |
@@ -447,7 +448,7 @@ async function getVideo (req: express.Request, res: express.Response) { | |||
447 | 448 | ||
448 | const video = await Hooks.wrapPromiseFun( | 449 | const video = await Hooks.wrapPromiseFun( |
449 | VideoModel.loadForGetAPI, | 450 | VideoModel.loadForGetAPI, |
450 | { id: res.locals.video.id, userId }, | 451 | { id: res.locals.onlyVideoWithRights.id, userId }, |
451 | 'filter:api.video.get.result' | 452 | 'filter:api.video.get.result' |
452 | ) | 453 | ) |
453 | 454 | ||
@@ -460,7 +461,7 @@ async function getVideo (req: express.Request, res: express.Response) { | |||
460 | } | 461 | } |
461 | 462 | ||
462 | async function viewVideo (req: express.Request, res: express.Response) { | 463 | async function viewVideo (req: express.Request, res: express.Response) { |
463 | const videoInstance = res.locals.video | 464 | const videoInstance = res.locals.videoAll |
464 | 465 | ||
465 | const ip = req.ip | 466 | const ip = req.ip |
466 | const exists = await Redis.Instance.doesVideoIPViewExist(ip, videoInstance.uuid) | 467 | const exists = await Redis.Instance.doesVideoIPViewExist(ip, videoInstance.uuid) |
@@ -483,7 +484,7 @@ async function viewVideo (req: express.Request, res: express.Response) { | |||
483 | } | 484 | } |
484 | 485 | ||
485 | async function getVideoDescription (req: express.Request, res: express.Response) { | 486 | async function getVideoDescription (req: express.Request, res: express.Response) { |
486 | const videoInstance = res.locals.video | 487 | const videoInstance = res.locals.videoAll |
487 | let description = '' | 488 | let description = '' |
488 | 489 | ||
489 | if (videoInstance.isOwned()) { | 490 | if (videoInstance.isOwned()) { |
@@ -522,7 +523,7 @@ async function listVideos (req: express.Request, res: express.Response) { | |||
522 | } | 523 | } |
523 | 524 | ||
524 | async function removeVideo (req: express.Request, res: express.Response) { | 525 | async function removeVideo (req: express.Request, res: express.Response) { |
525 | const videoInstance = res.locals.video | 526 | const videoInstance = res.locals.videoAll |
526 | 527 | ||
527 | await sequelizeTypescript.transaction(async t => { | 528 | await sequelizeTypescript.transaction(async t => { |
528 | await videoInstance.destroy({ transaction: t }) | 529 | await videoInstance.destroy({ transaction: t }) |
diff --git a/server/controllers/api/videos/ownership.ts b/server/controllers/api/videos/ownership.ts index 5272c1385..abb34082e 100644 --- a/server/controllers/api/videos/ownership.ts +++ b/server/controllers/api/videos/ownership.ts | |||
@@ -18,6 +18,7 @@ import { getFormattedObjects } from '../../../helpers/utils' | |||
18 | import { changeVideoChannelShare } from '../../../lib/activitypub' | 18 | import { changeVideoChannelShare } from '../../../lib/activitypub' |
19 | import { sendUpdateVideo } from '../../../lib/activitypub/send' | 19 | import { sendUpdateVideo } from '../../../lib/activitypub/send' |
20 | import { VideoModel } from '../../../models/video/video' | 20 | import { VideoModel } from '../../../models/video/video' |
21 | import { MVideoFullLight } from '@server/typings/models' | ||
21 | 22 | ||
22 | const ownershipVideoRouter = express.Router() | 23 | const ownershipVideoRouter = express.Router() |
23 | 24 | ||
@@ -56,7 +57,7 @@ export { | |||
56 | // --------------------------------------------------------------------------- | 57 | // --------------------------------------------------------------------------- |
57 | 58 | ||
58 | async function giveVideoOwnership (req: express.Request, res: express.Response) { | 59 | async function giveVideoOwnership (req: express.Request, res: express.Response) { |
59 | const videoInstance = res.locals.video | 60 | const videoInstance = res.locals.videoAll |
60 | const initiatorAccountId = res.locals.oauth.token.User.Account.id | 61 | const initiatorAccountId = res.locals.oauth.token.User.Account.id |
61 | const nextOwner = res.locals.nextOwner | 62 | const nextOwner = res.locals.nextOwner |
62 | 63 | ||
@@ -107,7 +108,7 @@ async function acceptOwnership (req: express.Request, res: express.Response) { | |||
107 | 108 | ||
108 | targetVideo.channelId = channel.id | 109 | targetVideo.channelId = channel.id |
109 | 110 | ||
110 | const targetVideoUpdated = await targetVideo.save({ transaction: t }) | 111 | const targetVideoUpdated = await targetVideo.save({ transaction: t }) as MVideoFullLight |
111 | targetVideoUpdated.VideoChannel = channel | 112 | targetVideoUpdated.VideoChannel = channel |
112 | 113 | ||
113 | if (targetVideoUpdated.privacy !== VideoPrivacy.PRIVATE && targetVideoUpdated.state === VideoState.PUBLISHED) { | 114 | if (targetVideoUpdated.privacy !== VideoPrivacy.PRIVATE && targetVideoUpdated.state === VideoState.PUBLISHED) { |
diff --git a/server/controllers/api/videos/rate.ts b/server/controllers/api/videos/rate.ts index b65babedf..3d2f3d728 100644 --- a/server/controllers/api/videos/rate.ts +++ b/server/controllers/api/videos/rate.ts | |||
@@ -27,7 +27,7 @@ export { | |||
27 | async function rateVideo (req: express.Request, res: express.Response) { | 27 | async function rateVideo (req: express.Request, res: express.Response) { |
28 | const body: UserVideoRateUpdate = req.body | 28 | const body: UserVideoRateUpdate = req.body |
29 | const rateType = body.rating | 29 | const rateType = body.rating |
30 | const videoInstance = res.locals.video | 30 | const videoInstance = res.locals.videoAll |
31 | const userAccount = res.locals.oauth.token.User.Account | 31 | const userAccount = res.locals.oauth.token.User.Account |
32 | 32 | ||
33 | await sequelizeTypescript.transaction(async t => { | 33 | await sequelizeTypescript.transaction(async t => { |
diff --git a/server/controllers/api/videos/watching.ts b/server/controllers/api/videos/watching.ts index dcd1f070d..036e16f3a 100644 --- a/server/controllers/api/videos/watching.ts +++ b/server/controllers/api/videos/watching.ts | |||
@@ -23,7 +23,7 @@ async function userWatchVideo (req: express.Request, res: express.Response) { | |||
23 | const user = res.locals.oauth.token.User | 23 | const user = res.locals.oauth.token.User |
24 | 24 | ||
25 | const body: UserWatchingVideo = req.body | 25 | const body: UserWatchingVideo = req.body |
26 | const { id: videoId } = res.locals.video as { id: number } | 26 | const { id: videoId } = res.locals.videoId |
27 | 27 | ||
28 | await UserVideoHistoryModel.upsert({ | 28 | await UserVideoHistoryModel.upsert({ |
29 | videoId, | 29 | videoId, |