diff options
author | Chocobozzz <me@florianbigard.com> | 2019-03-19 10:35:15 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-03-19 10:35:15 +0100 |
commit | dae86118ed5d4026d04acb9d0e36829b9ad8eb4e (patch) | |
tree | a5bf9c4487240bf75a9b328cad459a0587f90dea /server/controllers/api | |
parent | e65c0c5b1fab9c3d93f51721b2458cf5cf471f20 (diff) | |
download | PeerTube-dae86118ed5d4026d04acb9d0e36829b9ad8eb4e.tar.gz PeerTube-dae86118ed5d4026d04acb9d0e36829b9ad8eb4e.tar.zst PeerTube-dae86118ed5d4026d04acb9d0e36829b9ad8eb4e.zip |
Cleanup express locals typings
Diffstat (limited to 'server/controllers/api')
23 files changed, 122 insertions, 141 deletions
diff --git a/server/controllers/api/accounts.ts b/server/controllers/api/accounts.ts index e24545de8..adbf69781 100644 --- a/server/controllers/api/accounts.ts +++ b/server/controllers/api/accounts.ts | |||
@@ -17,7 +17,6 @@ import { VideoChannelModel } from '../../models/video/video-channel' | |||
17 | import { JobQueue } from '../../lib/job-queue' | 17 | import { JobQueue } from '../../lib/job-queue' |
18 | import { logger } from '../../helpers/logger' | 18 | import { logger } from '../../helpers/logger' |
19 | import { VideoPlaylistModel } from '../../models/video/video-playlist' | 19 | import { VideoPlaylistModel } from '../../models/video/video-playlist' |
20 | import { UserModel } from '../../models/account/user' | ||
21 | import { commonVideoPlaylistFiltersValidator } from '../../middlewares/validators/videos/video-playlists' | 20 | import { commonVideoPlaylistFiltersValidator } from '../../middlewares/validators/videos/video-playlists' |
22 | 21 | ||
23 | const accountsRouter = express.Router() | 22 | const accountsRouter = express.Router() |
@@ -71,7 +70,7 @@ export { | |||
71 | // --------------------------------------------------------------------------- | 70 | // --------------------------------------------------------------------------- |
72 | 71 | ||
73 | function getAccount (req: express.Request, res: express.Response) { | 72 | function getAccount (req: express.Request, res: express.Response) { |
74 | const account: AccountModel = res.locals.account | 73 | const account = res.locals.account |
75 | 74 | ||
76 | if (account.isOutdated()) { | 75 | if (account.isOutdated()) { |
77 | JobQueue.Instance.createJob({ type: 'activitypub-refresher', payload: { type: 'actor', url: account.Actor.url } }) | 76 | JobQueue.Instance.createJob({ type: 'activitypub-refresher', payload: { type: 'actor', url: account.Actor.url } }) |
@@ -98,7 +97,7 @@ async function listAccountPlaylists (req: express.Request, res: express.Response | |||
98 | 97 | ||
99 | // Allow users to see their private/unlisted video playlists | 98 | // Allow users to see their private/unlisted video playlists |
100 | let privateAndUnlisted = false | 99 | let privateAndUnlisted = false |
101 | if (res.locals.oauth && (res.locals.oauth.token.User as UserModel).Account.id === res.locals.account.id) { | 100 | if (res.locals.oauth && res.locals.oauth.token.User.Account.id === res.locals.account.id) { |
102 | privateAndUnlisted = true | 101 | privateAndUnlisted = true |
103 | } | 102 | } |
104 | 103 | ||
@@ -116,7 +115,7 @@ async function listAccountPlaylists (req: express.Request, res: express.Response | |||
116 | } | 115 | } |
117 | 116 | ||
118 | async function listAccountVideos (req: express.Request, res: express.Response) { | 117 | async function listAccountVideos (req: express.Request, res: express.Response) { |
119 | const account: AccountModel = res.locals.account | 118 | const account = res.locals.account |
120 | const followerActorId = isUserAbleToSearchRemoteURI(res) ? null : undefined | 119 | const followerActorId = isUserAbleToSearchRemoteURI(res) ? null : undefined |
121 | 120 | ||
122 | const resultList = await VideoModel.listForApi({ | 121 | const resultList = await VideoModel.listForApi({ |
diff --git a/server/controllers/api/index.ts b/server/controllers/api/index.ts index ed4b33dea..60a84036e 100644 --- a/server/controllers/api/index.ts +++ b/server/controllers/api/index.ts | |||
@@ -41,6 +41,6 @@ export { apiRouter } | |||
41 | 41 | ||
42 | // --------------------------------------------------------------------------- | 42 | // --------------------------------------------------------------------------- |
43 | 43 | ||
44 | function pong (req: express.Request, res: express.Response, next: express.NextFunction) { | 44 | function pong (req: express.Request, res: express.Response) { |
45 | return res.send('pong').status(200).end() | 45 | return res.send('pong').status(200).end() |
46 | } | 46 | } |
diff --git a/server/controllers/api/server/follows.ts b/server/controllers/api/server/follows.ts index 9fa6c34ba..99d211bfc 100644 --- a/server/controllers/api/server/follows.ts +++ b/server/controllers/api/server/follows.ts | |||
@@ -59,7 +59,7 @@ export { | |||
59 | 59 | ||
60 | // --------------------------------------------------------------------------- | 60 | // --------------------------------------------------------------------------- |
61 | 61 | ||
62 | async function listFollowing (req: express.Request, res: express.Response, next: express.NextFunction) { | 62 | async function listFollowing (req: express.Request, res: express.Response) { |
63 | const serverActor = await getServerActor() | 63 | const serverActor = await getServerActor() |
64 | const resultList = await ActorFollowModel.listFollowingForApi( | 64 | const resultList = await ActorFollowModel.listFollowingForApi( |
65 | serverActor.id, | 65 | serverActor.id, |
@@ -72,7 +72,7 @@ async function listFollowing (req: express.Request, res: express.Response, next: | |||
72 | return res.json(getFormattedObjects(resultList.data, resultList.total)) | 72 | return res.json(getFormattedObjects(resultList.data, resultList.total)) |
73 | } | 73 | } |
74 | 74 | ||
75 | async function listFollowers (req: express.Request, res: express.Response, next: express.NextFunction) { | 75 | async function listFollowers (req: express.Request, res: express.Response) { |
76 | const serverActor = await getServerActor() | 76 | const serverActor = await getServerActor() |
77 | const resultList = await ActorFollowModel.listFollowersForApi( | 77 | const resultList = await ActorFollowModel.listFollowersForApi( |
78 | serverActor.id, | 78 | serverActor.id, |
@@ -85,7 +85,7 @@ async function listFollowers (req: express.Request, res: express.Response, next: | |||
85 | return res.json(getFormattedObjects(resultList.data, resultList.total)) | 85 | return res.json(getFormattedObjects(resultList.data, resultList.total)) |
86 | } | 86 | } |
87 | 87 | ||
88 | async function followInstance (req: express.Request, res: express.Response, next: express.NextFunction) { | 88 | async function followInstance (req: express.Request, res: express.Response) { |
89 | const hosts = req.body.hosts as string[] | 89 | const hosts = req.body.hosts as string[] |
90 | const follower = await getServerActor() | 90 | const follower = await getServerActor() |
91 | 91 | ||
@@ -103,8 +103,8 @@ async function followInstance (req: express.Request, res: express.Response, next | |||
103 | return res.status(204).end() | 103 | return res.status(204).end() |
104 | } | 104 | } |
105 | 105 | ||
106 | async function removeFollow (req: express.Request, res: express.Response, next: express.NextFunction) { | 106 | async function removeFollow (req: express.Request, res: express.Response) { |
107 | const follow: ActorFollowModel = res.locals.follow | 107 | const follow = res.locals.follow |
108 | 108 | ||
109 | await sequelizeTypescript.transaction(async t => { | 109 | await sequelizeTypescript.transaction(async t => { |
110 | if (follow.state === 'accepted') await sendUndoFollow(follow, t) | 110 | if (follow.state === 'accepted') await sendUndoFollow(follow, t) |
diff --git a/server/controllers/api/server/redundancy.ts b/server/controllers/api/server/redundancy.ts index 4140c4991..f8109070d 100644 --- a/server/controllers/api/server/redundancy.ts +++ b/server/controllers/api/server/redundancy.ts | |||
@@ -2,7 +2,6 @@ import * as express from 'express' | |||
2 | import { UserRight } from '../../../../shared/models/users' | 2 | import { UserRight } from '../../../../shared/models/users' |
3 | import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../../middlewares' | 3 | import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../../middlewares' |
4 | import { updateServerRedundancyValidator } from '../../../middlewares/validators/redundancy' | 4 | import { updateServerRedundancyValidator } from '../../../middlewares/validators/redundancy' |
5 | import { ServerModel } from '../../../models/server/server' | ||
6 | import { removeRedundancyOf } from '../../../lib/redundancy' | 5 | import { removeRedundancyOf } from '../../../lib/redundancy' |
7 | import { logger } from '../../../helpers/logger' | 6 | import { logger } from '../../../helpers/logger' |
8 | 7 | ||
@@ -23,8 +22,8 @@ export { | |||
23 | 22 | ||
24 | // --------------------------------------------------------------------------- | 23 | // --------------------------------------------------------------------------- |
25 | 24 | ||
26 | async function updateRedundancy (req: express.Request, res: express.Response, next: express.NextFunction) { | 25 | async function updateRedundancy (req: express.Request, res: express.Response) { |
27 | const server = res.locals.server as ServerModel | 26 | const server = res.locals.server |
28 | 27 | ||
29 | server.redundancyAllowed = req.body.redundancyAllowed | 28 | server.redundancyAllowed = req.body.redundancyAllowed |
30 | 29 | ||
diff --git a/server/controllers/api/server/server-blocklist.ts b/server/controllers/api/server/server-blocklist.ts index 3cb3a96e2..d165db191 100644 --- a/server/controllers/api/server/server-blocklist.ts +++ b/server/controllers/api/server/server-blocklist.ts | |||
@@ -18,11 +18,9 @@ import { | |||
18 | unblockAccountByServerValidator, | 18 | unblockAccountByServerValidator, |
19 | unblockServerByServerValidator | 19 | unblockServerByServerValidator |
20 | } from '../../../middlewares/validators' | 20 | } from '../../../middlewares/validators' |
21 | import { AccountModel } from '../../../models/account/account' | ||
22 | import { AccountBlocklistModel } from '../../../models/account/account-blocklist' | 21 | import { AccountBlocklistModel } from '../../../models/account/account-blocklist' |
23 | import { addAccountInBlocklist, addServerInBlocklist, removeAccountFromBlocklist, removeServerFromBlocklist } from '../../../lib/blocklist' | 22 | import { addAccountInBlocklist, addServerInBlocklist, removeAccountFromBlocklist, removeServerFromBlocklist } from '../../../lib/blocklist' |
24 | import { ServerBlocklistModel } from '../../../models/server/server-blocklist' | 23 | import { ServerBlocklistModel } from '../../../models/server/server-blocklist' |
25 | import { ServerModel } from '../../../models/server/server' | ||
26 | import { UserRight } from '../../../../shared/models/users' | 24 | import { UserRight } from '../../../../shared/models/users' |
27 | 25 | ||
28 | const serverBlocklistRouter = express.Router() | 26 | const serverBlocklistRouter = express.Router() |
@@ -91,7 +89,7 @@ async function listBlockedAccounts (req: express.Request, res: express.Response) | |||
91 | 89 | ||
92 | async function blockAccount (req: express.Request, res: express.Response) { | 90 | async function blockAccount (req: express.Request, res: express.Response) { |
93 | const serverActor = await getServerActor() | 91 | const serverActor = await getServerActor() |
94 | const accountToBlock: AccountModel = res.locals.account | 92 | const accountToBlock = res.locals.account |
95 | 93 | ||
96 | await addAccountInBlocklist(serverActor.Account.id, accountToBlock.id) | 94 | await addAccountInBlocklist(serverActor.Account.id, accountToBlock.id) |
97 | 95 | ||
@@ -99,7 +97,7 @@ async function blockAccount (req: express.Request, res: express.Response) { | |||
99 | } | 97 | } |
100 | 98 | ||
101 | async function unblockAccount (req: express.Request, res: express.Response) { | 99 | async function unblockAccount (req: express.Request, res: express.Response) { |
102 | const accountBlock: AccountBlocklistModel = res.locals.accountBlock | 100 | const accountBlock = res.locals.accountBlock |
103 | 101 | ||
104 | await removeAccountFromBlocklist(accountBlock) | 102 | await removeAccountFromBlocklist(accountBlock) |
105 | 103 | ||
@@ -116,7 +114,7 @@ async function listBlockedServers (req: express.Request, res: express.Response) | |||
116 | 114 | ||
117 | async function blockServer (req: express.Request, res: express.Response) { | 115 | async function blockServer (req: express.Request, res: express.Response) { |
118 | const serverActor = await getServerActor() | 116 | const serverActor = await getServerActor() |
119 | const serverToBlock: ServerModel = res.locals.server | 117 | const serverToBlock = res.locals.server |
120 | 118 | ||
121 | await addServerInBlocklist(serverActor.Account.id, serverToBlock.id) | 119 | await addServerInBlocklist(serverActor.Account.id, serverToBlock.id) |
122 | 120 | ||
@@ -124,7 +122,7 @@ async function blockServer (req: express.Request, res: express.Response) { | |||
124 | } | 122 | } |
125 | 123 | ||
126 | async function unblockServer (req: express.Request, res: express.Response) { | 124 | async function unblockServer (req: express.Request, res: express.Response) { |
127 | const serverBlock: ServerBlocklistModel = res.locals.serverBlock | 125 | const serverBlock = res.locals.serverBlock |
128 | 126 | ||
129 | await removeServerFromBlocklist(serverBlock) | 127 | await removeServerFromBlocklist(serverBlock) |
130 | 128 | ||
diff --git a/server/controllers/api/users/index.ts b/server/controllers/api/users/index.ts index f7edbddf3..2117bdfeb 100644 --- a/server/controllers/api/users/index.ts +++ b/server/controllers/api/users/index.ts | |||
@@ -221,8 +221,8 @@ async function registerUser (req: express.Request, res: express.Response) { | |||
221 | return res.type('json').status(204).end() | 221 | return res.type('json').status(204).end() |
222 | } | 222 | } |
223 | 223 | ||
224 | async function unblockUser (req: express.Request, res: express.Response, next: express.NextFunction) { | 224 | async function unblockUser (req: express.Request, res: express.Response) { |
225 | const user: UserModel = res.locals.user | 225 | const user = res.locals.user |
226 | 226 | ||
227 | await changeUserBlock(res, user, false) | 227 | await changeUserBlock(res, user, false) |
228 | 228 | ||
@@ -230,7 +230,7 @@ async function unblockUser (req: express.Request, res: express.Response, next: e | |||
230 | } | 230 | } |
231 | 231 | ||
232 | async function blockUser (req: express.Request, res: express.Response) { | 232 | async function blockUser (req: express.Request, res: express.Response) { |
233 | const user: UserModel = res.locals.user | 233 | const user = res.locals.user |
234 | const reason = req.body.reason | 234 | const reason = req.body.reason |
235 | 235 | ||
236 | await changeUserBlock(res, user, true, reason) | 236 | await changeUserBlock(res, user, true, reason) |
@@ -239,7 +239,7 @@ async function blockUser (req: express.Request, res: express.Response) { | |||
239 | } | 239 | } |
240 | 240 | ||
241 | function getUser (req: express.Request, res: express.Response) { | 241 | function getUser (req: express.Request, res: express.Response) { |
242 | return res.json((res.locals.user as UserModel).toFormattedJSON()) | 242 | return res.json(res.locals.user.toFormattedJSON()) |
243 | } | 243 | } |
244 | 244 | ||
245 | async function autocompleteUsers (req: express.Request, res: express.Response) { | 245 | async function autocompleteUsers (req: express.Request, res: express.Response) { |
@@ -255,7 +255,7 @@ async function listUsers (req: express.Request, res: express.Response) { | |||
255 | } | 255 | } |
256 | 256 | ||
257 | async function removeUser (req: express.Request, res: express.Response) { | 257 | async function removeUser (req: express.Request, res: express.Response) { |
258 | const user: UserModel = res.locals.user | 258 | const user = res.locals.user |
259 | 259 | ||
260 | await user.destroy() | 260 | await user.destroy() |
261 | 261 | ||
@@ -266,7 +266,7 @@ async function removeUser (req: express.Request, res: express.Response) { | |||
266 | 266 | ||
267 | async function updateUser (req: express.Request, res: express.Response) { | 267 | async function updateUser (req: express.Request, res: express.Response) { |
268 | const body: UserUpdate = req.body | 268 | const body: UserUpdate = req.body |
269 | const userToUpdate = res.locals.user as UserModel | 269 | const userToUpdate = res.locals.user |
270 | const oldUserAuditView = new UserAuditView(userToUpdate.toFormattedJSON()) | 270 | const oldUserAuditView = new UserAuditView(userToUpdate.toFormattedJSON()) |
271 | const roleChanged = body.role !== undefined && body.role !== userToUpdate.role | 271 | const roleChanged = body.role !== undefined && body.role !== userToUpdate.role |
272 | 272 | ||
@@ -289,8 +289,8 @@ async function updateUser (req: express.Request, res: express.Response) { | |||
289 | return res.sendStatus(204) | 289 | return res.sendStatus(204) |
290 | } | 290 | } |
291 | 291 | ||
292 | async function askResetUserPassword (req: express.Request, res: express.Response, next: express.NextFunction) { | 292 | async function askResetUserPassword (req: express.Request, res: express.Response) { |
293 | const user = res.locals.user as UserModel | 293 | const user = res.locals.user |
294 | 294 | ||
295 | const verificationString = await Redis.Instance.setResetPasswordVerificationString(user.id) | 295 | const verificationString = await Redis.Instance.setResetPasswordVerificationString(user.id) |
296 | const url = CONFIG.WEBSERVER.URL + '/reset-password?userId=' + user.id + '&verificationString=' + verificationString | 296 | const url = CONFIG.WEBSERVER.URL + '/reset-password?userId=' + user.id + '&verificationString=' + verificationString |
@@ -299,8 +299,8 @@ async function askResetUserPassword (req: express.Request, res: express.Response | |||
299 | return res.status(204).end() | 299 | return res.status(204).end() |
300 | } | 300 | } |
301 | 301 | ||
302 | async function resetUserPassword (req: express.Request, res: express.Response, next: express.NextFunction) { | 302 | async function resetUserPassword (req: express.Request, res: express.Response) { |
303 | const user = res.locals.user as UserModel | 303 | const user = res.locals.user |
304 | user.password = req.body.password | 304 | user.password = req.body.password |
305 | 305 | ||
306 | await user.save() | 306 | await user.save() |
@@ -315,16 +315,16 @@ async function sendVerifyUserEmail (user: UserModel) { | |||
315 | return | 315 | return |
316 | } | 316 | } |
317 | 317 | ||
318 | async function askSendVerifyUserEmail (req: express.Request, res: express.Response, next: express.NextFunction) { | 318 | async function askSendVerifyUserEmail (req: express.Request, res: express.Response) { |
319 | const user = res.locals.user as UserModel | 319 | const user = res.locals.user |
320 | 320 | ||
321 | await sendVerifyUserEmail(user) | 321 | await sendVerifyUserEmail(user) |
322 | 322 | ||
323 | return res.status(204).end() | 323 | return res.status(204).end() |
324 | } | 324 | } |
325 | 325 | ||
326 | async function verifyUserEmail (req: express.Request, res: express.Response, next: express.NextFunction) { | 326 | async function verifyUserEmail (req: express.Request, res: express.Response) { |
327 | const user = res.locals.user as UserModel | 327 | const user = res.locals.user |
328 | user.emailVerified = true | 328 | user.emailVerified = true |
329 | 329 | ||
330 | await user.save() | 330 | await user.save() |
@@ -332,7 +332,7 @@ async function verifyUserEmail (req: express.Request, res: express.Response, nex | |||
332 | return res.status(204).end() | 332 | return res.status(204).end() |
333 | } | 333 | } |
334 | 334 | ||
335 | function success (req: express.Request, res: express.Response, next: express.NextFunction) { | 335 | function success (req: express.Request, res: express.Response) { |
336 | res.end() | 336 | res.end() |
337 | } | 337 | } |
338 | 338 | ||
diff --git a/server/controllers/api/users/me.ts b/server/controllers/api/users/me.ts index d5e154869..3533499be 100644 --- a/server/controllers/api/users/me.ts +++ b/server/controllers/api/users/me.ts | |||
@@ -93,8 +93,8 @@ export { | |||
93 | 93 | ||
94 | // --------------------------------------------------------------------------- | 94 | // --------------------------------------------------------------------------- |
95 | 95 | ||
96 | async function getUserVideos (req: express.Request, res: express.Response, next: express.NextFunction) { | 96 | async function getUserVideos (req: express.Request, res: express.Response) { |
97 | const user = res.locals.oauth.token.User as UserModel | 97 | const user = res.locals.oauth.token.User |
98 | const resultList = await VideoModel.listUserVideosForApi( | 98 | const resultList = await VideoModel.listUserVideosForApi( |
99 | user.Account.id, | 99 | user.Account.id, |
100 | req.query.start as number, | 100 | req.query.start as number, |
@@ -111,8 +111,8 @@ async function getUserVideos (req: express.Request, res: express.Response, next: | |||
111 | return res.json(getFormattedObjects(resultList.data, resultList.total, { additionalAttributes })) | 111 | return res.json(getFormattedObjects(resultList.data, resultList.total, { additionalAttributes })) |
112 | } | 112 | } |
113 | 113 | ||
114 | async function getUserVideoImports (req: express.Request, res: express.Response, next: express.NextFunction) { | 114 | async function getUserVideoImports (req: express.Request, res: express.Response) { |
115 | const user = res.locals.oauth.token.User as UserModel | 115 | const user = res.locals.oauth.token.User |
116 | const resultList = await VideoImportModel.listUserVideoImportsForApi( | 116 | const resultList = await VideoImportModel.listUserVideoImportsForApi( |
117 | user.id, | 117 | user.id, |
118 | req.query.start as number, | 118 | req.query.start as number, |
@@ -123,14 +123,14 @@ async function getUserVideoImports (req: express.Request, res: express.Response, | |||
123 | return res.json(getFormattedObjects(resultList.data, resultList.total)) | 123 | return res.json(getFormattedObjects(resultList.data, resultList.total)) |
124 | } | 124 | } |
125 | 125 | ||
126 | async function getUserInformation (req: express.Request, res: express.Response, next: express.NextFunction) { | 126 | async function getUserInformation (req: express.Request, res: express.Response) { |
127 | // We did not load channels in res.locals.user | 127 | // We did not load channels in res.locals.user |
128 | const user = await UserModel.loadByUsernameAndPopulateChannels(res.locals.oauth.token.user.username) | 128 | const user = await UserModel.loadByUsernameAndPopulateChannels(res.locals.oauth.token.user.username) |
129 | 129 | ||
130 | return res.json(user.toFormattedJSON()) | 130 | return res.json(user.toFormattedJSON()) |
131 | } | 131 | } |
132 | 132 | ||
133 | async function getUserVideoQuotaUsed (req: express.Request, res: express.Response, next: express.NextFunction) { | 133 | async function getUserVideoQuotaUsed (req: express.Request, res: express.Response) { |
134 | // We did not load channels in res.locals.user | 134 | // We did not load channels in res.locals.user |
135 | const user = await UserModel.loadByUsernameAndPopulateChannels(res.locals.oauth.token.user.username) | 135 | const user = await UserModel.loadByUsernameAndPopulateChannels(res.locals.oauth.token.user.username) |
136 | const videoQuotaUsed = await UserModel.getOriginalVideoFileTotalFromUser(user) | 136 | const videoQuotaUsed = await UserModel.getOriginalVideoFileTotalFromUser(user) |
@@ -143,7 +143,7 @@ async function getUserVideoQuotaUsed (req: express.Request, res: express.Respons | |||
143 | return res.json(data) | 143 | return res.json(data) |
144 | } | 144 | } |
145 | 145 | ||
146 | async function getUserVideoRating (req: express.Request, res: express.Response, next: express.NextFunction) { | 146 | async function getUserVideoRating (req: express.Request, res: express.Response) { |
147 | const videoId = res.locals.video.id | 147 | const videoId = res.locals.video.id |
148 | const accountId = +res.locals.oauth.token.User.Account.id | 148 | const accountId = +res.locals.oauth.token.User.Account.id |
149 | 149 | ||
@@ -158,7 +158,7 @@ async function getUserVideoRating (req: express.Request, res: express.Response, | |||
158 | } | 158 | } |
159 | 159 | ||
160 | async function deleteMe (req: express.Request, res: express.Response) { | 160 | async function deleteMe (req: express.Request, res: express.Response) { |
161 | const user: UserModel = res.locals.oauth.token.User | 161 | const user = res.locals.oauth.token.User |
162 | 162 | ||
163 | await user.destroy() | 163 | await user.destroy() |
164 | 164 | ||
@@ -170,7 +170,7 @@ async function deleteMe (req: express.Request, res: express.Response) { | |||
170 | async function updateMe (req: express.Request, res: express.Response) { | 170 | async function updateMe (req: express.Request, res: express.Response) { |
171 | const body: UserUpdateMe = req.body | 171 | const body: UserUpdateMe = req.body |
172 | 172 | ||
173 | const user: UserModel = res.locals.oauth.token.user | 173 | const user = res.locals.oauth.token.user |
174 | const oldUserAuditView = new UserAuditView(user.toFormattedJSON()) | 174 | const oldUserAuditView = new UserAuditView(user.toFormattedJSON()) |
175 | 175 | ||
176 | if (body.password !== undefined) user.password = body.password | 176 | if (body.password !== undefined) user.password = body.password |
@@ -199,7 +199,7 @@ async function updateMe (req: express.Request, res: express.Response) { | |||
199 | 199 | ||
200 | async function updateMyAvatar (req: express.Request, res: express.Response) { | 200 | async function updateMyAvatar (req: express.Request, res: express.Response) { |
201 | const avatarPhysicalFile = req.files[ 'avatarfile' ][ 0 ] | 201 | const avatarPhysicalFile = req.files[ 'avatarfile' ][ 0 ] |
202 | const user: UserModel = res.locals.oauth.token.user | 202 | const user = res.locals.oauth.token.user |
203 | const oldUserAuditView = new UserAuditView(user.toFormattedJSON()) | 203 | const oldUserAuditView = new UserAuditView(user.toFormattedJSON()) |
204 | 204 | ||
205 | const userAccount = await AccountModel.load(user.Account.id) | 205 | const userAccount = await AccountModel.load(user.Account.id) |
diff --git a/server/controllers/api/users/my-blocklist.ts b/server/controllers/api/users/my-blocklist.ts index 9575eab46..481e75139 100644 --- a/server/controllers/api/users/my-blocklist.ts +++ b/server/controllers/api/users/my-blocklist.ts | |||
@@ -17,7 +17,6 @@ import { | |||
17 | serversBlocklistSortValidator, | 17 | serversBlocklistSortValidator, |
18 | unblockServerByAccountValidator | 18 | unblockServerByAccountValidator |
19 | } from '../../../middlewares/validators' | 19 | } from '../../../middlewares/validators' |
20 | import { UserModel } from '../../../models/account/user' | ||
21 | import { AccountModel } from '../../../models/account/account' | 20 | import { AccountModel } from '../../../models/account/account' |
22 | import { AccountBlocklistModel } from '../../../models/account/account-blocklist' | 21 | import { AccountBlocklistModel } from '../../../models/account/account-blocklist' |
23 | import { addAccountInBlocklist, addServerInBlocklist, removeAccountFromBlocklist, removeServerFromBlocklist } from '../../../lib/blocklist' | 22 | import { addAccountInBlocklist, addServerInBlocklist, removeAccountFromBlocklist, removeServerFromBlocklist } from '../../../lib/blocklist' |
@@ -75,7 +74,7 @@ export { | |||
75 | // --------------------------------------------------------------------------- | 74 | // --------------------------------------------------------------------------- |
76 | 75 | ||
77 | async function listBlockedAccounts (req: express.Request, res: express.Response) { | 76 | async function listBlockedAccounts (req: express.Request, res: express.Response) { |
78 | const user: UserModel = res.locals.oauth.token.User | 77 | const user = res.locals.oauth.token.User |
79 | 78 | ||
80 | const resultList = await AccountBlocklistModel.listForApi(user.Account.id, req.query.start, req.query.count, req.query.sort) | 79 | const resultList = await AccountBlocklistModel.listForApi(user.Account.id, req.query.start, req.query.count, req.query.sort) |
81 | 80 | ||
@@ -83,8 +82,8 @@ async function listBlockedAccounts (req: express.Request, res: express.Response) | |||
83 | } | 82 | } |
84 | 83 | ||
85 | async function blockAccount (req: express.Request, res: express.Response) { | 84 | async function blockAccount (req: express.Request, res: express.Response) { |
86 | const user: UserModel = res.locals.oauth.token.User | 85 | const user = res.locals.oauth.token.User |
87 | const accountToBlock: AccountModel = res.locals.account | 86 | const accountToBlock = res.locals.account |
88 | 87 | ||
89 | await addAccountInBlocklist(user.Account.id, accountToBlock.id) | 88 | await addAccountInBlocklist(user.Account.id, accountToBlock.id) |
90 | 89 | ||
@@ -92,7 +91,7 @@ async function blockAccount (req: express.Request, res: express.Response) { | |||
92 | } | 91 | } |
93 | 92 | ||
94 | async function unblockAccount (req: express.Request, res: express.Response) { | 93 | async function unblockAccount (req: express.Request, res: express.Response) { |
95 | const accountBlock: AccountBlocklistModel = res.locals.accountBlock | 94 | const accountBlock = res.locals.accountBlock |
96 | 95 | ||
97 | await removeAccountFromBlocklist(accountBlock) | 96 | await removeAccountFromBlocklist(accountBlock) |
98 | 97 | ||
@@ -100,7 +99,7 @@ async function unblockAccount (req: express.Request, res: express.Response) { | |||
100 | } | 99 | } |
101 | 100 | ||
102 | async function listBlockedServers (req: express.Request, res: express.Response) { | 101 | async function listBlockedServers (req: express.Request, res: express.Response) { |
103 | const user: UserModel = res.locals.oauth.token.User | 102 | const user = res.locals.oauth.token.User |
104 | 103 | ||
105 | const resultList = await ServerBlocklistModel.listForApi(user.Account.id, req.query.start, req.query.count, req.query.sort) | 104 | const resultList = await ServerBlocklistModel.listForApi(user.Account.id, req.query.start, req.query.count, req.query.sort) |
106 | 105 | ||
@@ -108,8 +107,8 @@ async function listBlockedServers (req: express.Request, res: express.Response) | |||
108 | } | 107 | } |
109 | 108 | ||
110 | async function blockServer (req: express.Request, res: express.Response) { | 109 | async function blockServer (req: express.Request, res: express.Response) { |
111 | const user: UserModel = res.locals.oauth.token.User | 110 | const user = res.locals.oauth.token.User |
112 | const serverToBlock: ServerModel = res.locals.server | 111 | const serverToBlock = res.locals.server |
113 | 112 | ||
114 | await addServerInBlocklist(user.Account.id, serverToBlock.id) | 113 | await addServerInBlocklist(user.Account.id, serverToBlock.id) |
115 | 114 | ||
@@ -117,7 +116,7 @@ async function blockServer (req: express.Request, res: express.Response) { | |||
117 | } | 116 | } |
118 | 117 | ||
119 | async function unblockServer (req: express.Request, res: express.Response) { | 118 | async function unblockServer (req: express.Request, res: express.Response) { |
120 | const serverBlock: ServerBlocklistModel = res.locals.serverBlock | 119 | const serverBlock = res.locals.serverBlock |
121 | 120 | ||
122 | await removeServerFromBlocklist(serverBlock) | 121 | await removeServerFromBlocklist(serverBlock) |
123 | 122 | ||
diff --git a/server/controllers/api/users/my-history.ts b/server/controllers/api/users/my-history.ts index 6cd782c47..b30d3aec2 100644 --- a/server/controllers/api/users/my-history.ts +++ b/server/controllers/api/users/my-history.ts | |||
@@ -36,7 +36,7 @@ export { | |||
36 | // --------------------------------------------------------------------------- | 36 | // --------------------------------------------------------------------------- |
37 | 37 | ||
38 | async function listMyVideosHistory (req: express.Request, res: express.Response) { | 38 | async function listMyVideosHistory (req: express.Request, res: express.Response) { |
39 | const user: UserModel = res.locals.oauth.token.User | 39 | const user = res.locals.oauth.token.User |
40 | 40 | ||
41 | const resultList = await UserVideoHistoryModel.listForApi(user, req.query.start, req.query.count) | 41 | const resultList = await UserVideoHistoryModel.listForApi(user, req.query.start, req.query.count) |
42 | 42 | ||
@@ -44,7 +44,7 @@ async function listMyVideosHistory (req: express.Request, res: express.Response) | |||
44 | } | 44 | } |
45 | 45 | ||
46 | async function removeUserHistory (req: express.Request, res: express.Response) { | 46 | async function removeUserHistory (req: express.Request, res: express.Response) { |
47 | const user: UserModel = res.locals.oauth.token.User | 47 | const user = res.locals.oauth.token.User |
48 | const beforeDate = req.body.beforeDate || null | 48 | const beforeDate = req.body.beforeDate || null |
49 | 49 | ||
50 | await sequelizeTypescript.transaction(t => { | 50 | await sequelizeTypescript.transaction(t => { |
diff --git a/server/controllers/api/users/my-notifications.ts b/server/controllers/api/users/my-notifications.ts index 76cf97587..bbafda5a6 100644 --- a/server/controllers/api/users/my-notifications.ts +++ b/server/controllers/api/users/my-notifications.ts | |||
@@ -9,7 +9,6 @@ import { | |||
9 | setDefaultSort, | 9 | setDefaultSort, |
10 | userNotificationsSortValidator | 10 | userNotificationsSortValidator |
11 | } from '../../../middlewares' | 11 | } from '../../../middlewares' |
12 | import { UserModel } from '../../../models/account/user' | ||
13 | import { getFormattedObjects } from '../../../helpers/utils' | 12 | import { getFormattedObjects } from '../../../helpers/utils' |
14 | import { UserNotificationModel } from '../../../models/account/user-notification' | 13 | import { UserNotificationModel } from '../../../models/account/user-notification' |
15 | import { meRouter } from './me' | 14 | import { meRouter } from './me' |
@@ -57,8 +56,8 @@ export { | |||
57 | // --------------------------------------------------------------------------- | 56 | // --------------------------------------------------------------------------- |
58 | 57 | ||
59 | async function updateNotificationSettings (req: express.Request, res: express.Response) { | 58 | async function updateNotificationSettings (req: express.Request, res: express.Response) { |
60 | const user: UserModel = res.locals.oauth.token.User | 59 | const user = res.locals.oauth.token.User |
61 | const body = req.body | 60 | const body = req.body as UserNotificationSetting |
62 | 61 | ||
63 | const query = { | 62 | const query = { |
64 | where: { | 63 | where: { |
@@ -84,7 +83,7 @@ async function updateNotificationSettings (req: express.Request, res: express.Re | |||
84 | } | 83 | } |
85 | 84 | ||
86 | async function listUserNotifications (req: express.Request, res: express.Response) { | 85 | async function listUserNotifications (req: express.Request, res: express.Response) { |
87 | const user: UserModel = res.locals.oauth.token.User | 86 | const user = res.locals.oauth.token.User |
88 | 87 | ||
89 | const resultList = await UserNotificationModel.listForApi(user.id, req.query.start, req.query.count, req.query.sort, req.query.unread) | 88 | const resultList = await UserNotificationModel.listForApi(user.id, req.query.start, req.query.count, req.query.sort, req.query.unread) |
90 | 89 | ||
@@ -92,7 +91,7 @@ async function listUserNotifications (req: express.Request, res: express.Respons | |||
92 | } | 91 | } |
93 | 92 | ||
94 | async function markAsReadUserNotifications (req: express.Request, res: express.Response) { | 93 | async function markAsReadUserNotifications (req: express.Request, res: express.Response) { |
95 | const user: UserModel = res.locals.oauth.token.User | 94 | const user = res.locals.oauth.token.User |
96 | 95 | ||
97 | await UserNotificationModel.markAsRead(user.id, req.body.ids) | 96 | await UserNotificationModel.markAsRead(user.id, req.body.ids) |
98 | 97 | ||
@@ -100,7 +99,7 @@ async function markAsReadUserNotifications (req: express.Request, res: express.R | |||
100 | } | 99 | } |
101 | 100 | ||
102 | async function markAsReadAllUserNotifications (req: express.Request, res: express.Response) { | 101 | async function markAsReadAllUserNotifications (req: express.Request, res: express.Response) { |
103 | const user: UserModel = res.locals.oauth.token.User | 102 | const user = res.locals.oauth.token.User |
104 | 103 | ||
105 | await UserNotificationModel.markAllAsRead(user.id) | 104 | await UserNotificationModel.markAllAsRead(user.id) |
106 | 105 | ||
diff --git a/server/controllers/api/users/my-subscriptions.ts b/server/controllers/api/users/my-subscriptions.ts index accca6d52..a173adfd0 100644 --- a/server/controllers/api/users/my-subscriptions.ts +++ b/server/controllers/api/users/my-subscriptions.ts | |||
@@ -14,7 +14,6 @@ import { | |||
14 | userSubscriptionGetValidator | 14 | userSubscriptionGetValidator |
15 | } from '../../../middlewares' | 15 | } from '../../../middlewares' |
16 | import { areSubscriptionsExistValidator, userSubscriptionsSortValidator, videosSortValidator } from '../../../middlewares/validators' | 16 | import { areSubscriptionsExistValidator, userSubscriptionsSortValidator, videosSortValidator } from '../../../middlewares/validators' |
17 | import { UserModel } from '../../../models/account/user' | ||
18 | import { VideoModel } from '../../../models/video/video' | 17 | import { VideoModel } from '../../../models/video/video' |
19 | import { buildNSFWFilter } from '../../../helpers/express-utils' | 18 | import { buildNSFWFilter } from '../../../helpers/express-utils' |
20 | import { VideoFilter } from '../../../../shared/models/videos/video-query.type' | 19 | import { VideoFilter } from '../../../../shared/models/videos/video-query.type' |
@@ -77,7 +76,7 @@ export { | |||
77 | 76 | ||
78 | async function areSubscriptionsExist (req: express.Request, res: express.Response) { | 77 | async function areSubscriptionsExist (req: express.Request, res: express.Response) { |
79 | const uris = req.query.uris as string[] | 78 | const uris = req.query.uris as string[] |
80 | const user = res.locals.oauth.token.User as UserModel | 79 | const user = res.locals.oauth.token.User |
81 | 80 | ||
82 | const handles = uris.map(u => { | 81 | const handles = uris.map(u => { |
83 | let [ name, host ] = u.split('@') | 82 | let [ name, host ] = u.split('@') |
@@ -107,7 +106,7 @@ async function areSubscriptionsExist (req: express.Request, res: express.Respons | |||
107 | } | 106 | } |
108 | 107 | ||
109 | async function addUserSubscription (req: express.Request, res: express.Response) { | 108 | async function addUserSubscription (req: express.Request, res: express.Response) { |
110 | const user = res.locals.oauth.token.User as UserModel | 109 | const user = res.locals.oauth.token.User |
111 | const [ name, host ] = req.body.uri.split('@') | 110 | const [ name, host ] = req.body.uri.split('@') |
112 | 111 | ||
113 | const payload = { | 112 | const payload = { |
@@ -123,13 +122,13 @@ async function addUserSubscription (req: express.Request, res: express.Response) | |||
123 | } | 122 | } |
124 | 123 | ||
125 | function getUserSubscription (req: express.Request, res: express.Response) { | 124 | function getUserSubscription (req: express.Request, res: express.Response) { |
126 | const subscription: ActorFollowModel = res.locals.subscription | 125 | const subscription = res.locals.subscription |
127 | 126 | ||
128 | return res.json(subscription.ActorFollowing.VideoChannel.toFormattedJSON()) | 127 | return res.json(subscription.ActorFollowing.VideoChannel.toFormattedJSON()) |
129 | } | 128 | } |
130 | 129 | ||
131 | async function deleteUserSubscription (req: express.Request, res: express.Response) { | 130 | async function deleteUserSubscription (req: express.Request, res: express.Response) { |
132 | const subscription: ActorFollowModel = res.locals.subscription | 131 | const subscription = res.locals.subscription |
133 | 132 | ||
134 | await sequelizeTypescript.transaction(async t => { | 133 | await sequelizeTypescript.transaction(async t => { |
135 | return subscription.destroy({ transaction: t }) | 134 | return subscription.destroy({ transaction: t }) |
@@ -139,7 +138,7 @@ async function deleteUserSubscription (req: express.Request, res: express.Respon | |||
139 | } | 138 | } |
140 | 139 | ||
141 | async function getUserSubscriptions (req: express.Request, res: express.Response) { | 140 | async function getUserSubscriptions (req: express.Request, res: express.Response) { |
142 | const user = res.locals.oauth.token.User as UserModel | 141 | const user = res.locals.oauth.token.User |
143 | const actorId = user.Account.Actor.id | 142 | const actorId = user.Account.Actor.id |
144 | 143 | ||
145 | const resultList = await ActorFollowModel.listSubscriptionsForApi(actorId, req.query.start, req.query.count, req.query.sort) | 144 | const resultList = await ActorFollowModel.listSubscriptionsForApi(actorId, req.query.start, req.query.count, req.query.sort) |
@@ -147,8 +146,8 @@ async function getUserSubscriptions (req: express.Request, res: express.Response | |||
147 | return res.json(getFormattedObjects(resultList.data, resultList.total)) | 146 | return res.json(getFormattedObjects(resultList.data, resultList.total)) |
148 | } | 147 | } |
149 | 148 | ||
150 | async function getUserSubscriptionVideos (req: express.Request, res: express.Response, next: express.NextFunction) { | 149 | async function getUserSubscriptionVideos (req: express.Request, res: express.Response) { |
151 | const user = res.locals.oauth.token.User as UserModel | 150 | const user = res.locals.oauth.token.User |
152 | const resultList = await VideoModel.listForApi({ | 151 | const resultList = await VideoModel.listForApi({ |
153 | start: req.query.start, | 152 | start: req.query.start, |
154 | count: req.query.count, | 153 | count: req.query.count, |
diff --git a/server/controllers/api/users/my-video-playlists.ts b/server/controllers/api/users/my-video-playlists.ts index 42da02bff..15e92f4f3 100644 --- a/server/controllers/api/users/my-video-playlists.ts +++ b/server/controllers/api/users/my-video-playlists.ts | |||
@@ -1,6 +1,5 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { asyncMiddleware, authenticate } from '../../../middlewares' | 2 | import { asyncMiddleware, authenticate } from '../../../middlewares' |
3 | import { UserModel } from '../../../models/account/user' | ||
4 | import { doVideosInPlaylistExistValidator } from '../../../middlewares/validators/videos/video-playlists' | 3 | import { doVideosInPlaylistExistValidator } from '../../../middlewares/validators/videos/video-playlists' |
5 | import { VideoPlaylistModel } from '../../../models/video/video-playlist' | 4 | import { VideoPlaylistModel } from '../../../models/video/video-playlist' |
6 | import { VideoExistInPlaylist } from '../../../../shared/models/videos/playlist/video-exist-in-playlist.model' | 5 | import { VideoExistInPlaylist } from '../../../../shared/models/videos/playlist/video-exist-in-playlist.model' |
@@ -23,7 +22,7 @@ export { | |||
23 | 22 | ||
24 | async function doVideosInPlaylistExist (req: express.Request, res: express.Response) { | 23 | async function doVideosInPlaylistExist (req: express.Request, res: express.Response) { |
25 | const videoIds = req.query.videoIds.map(i => parseInt(i + '', 10)) | 24 | const videoIds = req.query.videoIds.map(i => parseInt(i + '', 10)) |
26 | const user = res.locals.oauth.token.User as UserModel | 25 | const user = res.locals.oauth.token.User |
27 | 26 | ||
28 | const results = await VideoPlaylistModel.listPlaylistIdsOf(user.Account.id, videoIds) | 27 | const results = await VideoPlaylistModel.listPlaylistIdsOf(user.Account.id, videoIds) |
29 | 28 | ||
diff --git a/server/controllers/api/video-channel.ts b/server/controllers/api/video-channel.ts index c13aed4dc..5881cab41 100644 --- a/server/controllers/api/video-channel.ts +++ b/server/controllers/api/video-channel.ts | |||
@@ -30,7 +30,6 @@ import { updateAvatarValidator } from '../../middlewares/validators/avatar' | |||
30 | import { updateActorAvatarFile } from '../../lib/avatar' | 30 | import { updateActorAvatarFile } from '../../lib/avatar' |
31 | import { auditLoggerFactory, getAuditIdFromRes, VideoChannelAuditView } from '../../helpers/audit-logger' | 31 | import { auditLoggerFactory, getAuditIdFromRes, VideoChannelAuditView } from '../../helpers/audit-logger' |
32 | import { resetSequelizeInstance } from '../../helpers/database-utils' | 32 | import { resetSequelizeInstance } from '../../helpers/database-utils' |
33 | import { UserModel } from '../../models/account/user' | ||
34 | import { JobQueue } from '../../lib/job-queue' | 33 | import { JobQueue } from '../../lib/job-queue' |
35 | import { VideoPlaylistModel } from '../../models/video/video-playlist' | 34 | import { VideoPlaylistModel } from '../../models/video/video-playlist' |
36 | import { commonVideoPlaylistFiltersValidator } from '../../middlewares/validators/videos/video-playlists' | 35 | import { commonVideoPlaylistFiltersValidator } from '../../middlewares/validators/videos/video-playlists' |
@@ -109,16 +108,16 @@ export { | |||
109 | 108 | ||
110 | // --------------------------------------------------------------------------- | 109 | // --------------------------------------------------------------------------- |
111 | 110 | ||
112 | async function listVideoChannels (req: express.Request, res: express.Response, next: express.NextFunction) { | 111 | async function listVideoChannels (req: express.Request, res: express.Response) { |
113 | const serverActor = await getServerActor() | 112 | const serverActor = await getServerActor() |
114 | const resultList = await VideoChannelModel.listForApi(serverActor.id, req.query.start, req.query.count, req.query.sort) | 113 | const resultList = await VideoChannelModel.listForApi(serverActor.id, req.query.start, req.query.count, req.query.sort) |
115 | 114 | ||
116 | return res.json(getFormattedObjects(resultList.data, resultList.total)) | 115 | return res.json(getFormattedObjects(resultList.data, resultList.total)) |
117 | } | 116 | } |
118 | 117 | ||
119 | async function updateVideoChannelAvatar (req: express.Request, res: express.Response, next: express.NextFunction) { | 118 | async function updateVideoChannelAvatar (req: express.Request, res: express.Response) { |
120 | const avatarPhysicalFile = req.files[ 'avatarfile' ][ 0 ] | 119 | const avatarPhysicalFile = req.files[ 'avatarfile' ][ 0 ] |
121 | const videoChannel = res.locals.videoChannel as VideoChannelModel | 120 | const videoChannel = res.locals.videoChannel |
122 | const oldVideoChannelAuditKeys = new VideoChannelAuditView(videoChannel.toFormattedJSON()) | 121 | const oldVideoChannelAuditKeys = new VideoChannelAuditView(videoChannel.toFormattedJSON()) |
123 | 122 | ||
124 | const avatar = await updateActorAvatarFile(avatarPhysicalFile, videoChannel) | 123 | const avatar = await updateActorAvatarFile(avatarPhysicalFile, videoChannel) |
@@ -136,7 +135,7 @@ async function addVideoChannel (req: express.Request, res: express.Response) { | |||
136 | const videoChannelInfo: VideoChannelCreate = req.body | 135 | const videoChannelInfo: VideoChannelCreate = req.body |
137 | 136 | ||
138 | const videoChannelCreated: VideoChannelModel = await sequelizeTypescript.transaction(async t => { | 137 | const videoChannelCreated: VideoChannelModel = await sequelizeTypescript.transaction(async t => { |
139 | const account = await AccountModel.load((res.locals.oauth.token.User as UserModel).Account.id, t) | 138 | const account = await AccountModel.load(res.locals.oauth.token.User.Account.id, t) |
140 | 139 | ||
141 | return createVideoChannel(videoChannelInfo, account, t) | 140 | return createVideoChannel(videoChannelInfo, account, t) |
142 | }) | 141 | }) |
@@ -156,7 +155,7 @@ async function addVideoChannel (req: express.Request, res: express.Response) { | |||
156 | } | 155 | } |
157 | 156 | ||
158 | async function updateVideoChannel (req: express.Request, res: express.Response) { | 157 | async function updateVideoChannel (req: express.Request, res: express.Response) { |
159 | const videoChannelInstance = res.locals.videoChannel as VideoChannelModel | 158 | const videoChannelInstance = res.locals.videoChannel |
160 | const videoChannelFieldsSave = videoChannelInstance.toJSON() | 159 | const videoChannelFieldsSave = videoChannelInstance.toJSON() |
161 | const oldVideoChannelAuditKeys = new VideoChannelAuditView(videoChannelInstance.toFormattedJSON()) | 160 | const oldVideoChannelAuditKeys = new VideoChannelAuditView(videoChannelInstance.toFormattedJSON()) |
162 | const videoChannelInfoToUpdate = req.body as VideoChannelUpdate | 161 | const videoChannelInfoToUpdate = req.body as VideoChannelUpdate |
@@ -196,7 +195,7 @@ async function updateVideoChannel (req: express.Request, res: express.Response) | |||
196 | } | 195 | } |
197 | 196 | ||
198 | async function removeVideoChannel (req: express.Request, res: express.Response) { | 197 | async function removeVideoChannel (req: express.Request, res: express.Response) { |
199 | const videoChannelInstance: VideoChannelModel = res.locals.videoChannel | 198 | const videoChannelInstance = res.locals.videoChannel |
200 | 199 | ||
201 | await sequelizeTypescript.transaction(async t => { | 200 | await sequelizeTypescript.transaction(async t => { |
202 | await VideoPlaylistModel.resetPlaylistsOfChannel(videoChannelInstance.id, t) | 201 | await VideoPlaylistModel.resetPlaylistsOfChannel(videoChannelInstance.id, t) |
@@ -210,7 +209,7 @@ async function removeVideoChannel (req: express.Request, res: express.Response) | |||
210 | return res.type('json').status(204).end() | 209 | return res.type('json').status(204).end() |
211 | } | 210 | } |
212 | 211 | ||
213 | async function getVideoChannel (req: express.Request, res: express.Response, next: express.NextFunction) { | 212 | async function getVideoChannel (req: express.Request, res: express.Response) { |
214 | const videoChannelWithVideos = await VideoChannelModel.loadAndPopulateAccountAndVideos(res.locals.videoChannel.id) | 213 | const videoChannelWithVideos = await VideoChannelModel.loadAndPopulateAccountAndVideos(res.locals.videoChannel.id) |
215 | 214 | ||
216 | if (videoChannelWithVideos.isOutdated()) { | 215 | if (videoChannelWithVideos.isOutdated()) { |
@@ -236,8 +235,8 @@ async function listVideoChannelPlaylists (req: express.Request, res: express.Res | |||
236 | return res.json(getFormattedObjects(resultList.data, resultList.total)) | 235 | return res.json(getFormattedObjects(resultList.data, resultList.total)) |
237 | } | 236 | } |
238 | 237 | ||
239 | async function listVideoChannelVideos (req: express.Request, res: express.Response, next: express.NextFunction) { | 238 | async function listVideoChannelVideos (req: express.Request, res: express.Response) { |
240 | const videoChannelInstance: VideoChannelModel = res.locals.videoChannel | 239 | const videoChannelInstance = res.locals.videoChannel |
241 | const followerActorId = isUserAbleToSearchRemoteURI(res) ? null : undefined | 240 | const followerActorId = isUserAbleToSearchRemoteURI(res) ? null : undefined |
242 | 241 | ||
243 | const resultList = await VideoModel.listForApi({ | 242 | const resultList = await VideoModel.listForApi({ |
diff --git a/server/controllers/api/video-playlist.ts b/server/controllers/api/video-playlist.ts index c7dfc583b..5b1601c4e 100644 --- a/server/controllers/api/video-playlist.ts +++ b/server/controllers/api/video-playlist.ts | |||
@@ -10,7 +10,6 @@ import { | |||
10 | setDefaultPagination, | 10 | setDefaultPagination, |
11 | setDefaultSort | 11 | setDefaultSort |
12 | } from '../../middlewares' | 12 | } from '../../middlewares' |
13 | import { VideoChannelModel } from '../../models/video/video-channel' | ||
14 | import { videoPlaylistsSortValidator } from '../../middlewares/validators' | 13 | import { videoPlaylistsSortValidator } from '../../middlewares/validators' |
15 | import { buildNSFWFilter, createReqFiles, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils' | 14 | import { buildNSFWFilter, createReqFiles, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils' |
16 | import { CONFIG, MIMETYPES, sequelizeTypescript, THUMBNAILS_SIZE, VIDEO_PLAYLIST_PRIVACIES } from '../../initializers' | 15 | import { CONFIG, MIMETYPES, sequelizeTypescript, THUMBNAILS_SIZE, VIDEO_PLAYLIST_PRIVACIES } from '../../initializers' |
@@ -31,7 +30,6 @@ import { VideoPlaylistCreate } from '../../../shared/models/videos/playlist/vide | |||
31 | import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model' | 30 | import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model' |
32 | import { processImage } from '../../helpers/image-utils' | 31 | import { processImage } from '../../helpers/image-utils' |
33 | import { join } from 'path' | 32 | import { join } from 'path' |
34 | import { UserModel } from '../../models/account/user' | ||
35 | import { sendCreateVideoPlaylist, sendDeleteVideoPlaylist, sendUpdateVideoPlaylist } from '../../lib/activitypub/send' | 33 | import { sendCreateVideoPlaylist, sendDeleteVideoPlaylist, sendUpdateVideoPlaylist } from '../../lib/activitypub/send' |
36 | import { getVideoPlaylistActivityPubUrl, getVideoPlaylistElementActivityPubUrl } from '../../lib/activitypub/url' | 34 | import { getVideoPlaylistActivityPubUrl, getVideoPlaylistElementActivityPubUrl } from '../../lib/activitypub/url' |
37 | import { VideoPlaylistUpdate } from '../../../shared/models/videos/playlist/video-playlist-update.model' | 35 | import { VideoPlaylistUpdate } from '../../../shared/models/videos/playlist/video-playlist-update.model' |
@@ -142,14 +140,14 @@ async function listVideoPlaylists (req: express.Request, res: express.Response) | |||
142 | } | 140 | } |
143 | 141 | ||
144 | function getVideoPlaylist (req: express.Request, res: express.Response) { | 142 | function getVideoPlaylist (req: express.Request, res: express.Response) { |
145 | const videoPlaylist = res.locals.videoPlaylist as VideoPlaylistModel | 143 | const videoPlaylist = res.locals.videoPlaylist |
146 | 144 | ||
147 | return res.json(videoPlaylist.toFormattedJSON()) | 145 | return res.json(videoPlaylist.toFormattedJSON()) |
148 | } | 146 | } |
149 | 147 | ||
150 | async function addVideoPlaylist (req: express.Request, res: express.Response) { | 148 | async function addVideoPlaylist (req: express.Request, res: express.Response) { |
151 | const videoPlaylistInfo: VideoPlaylistCreate = req.body | 149 | const videoPlaylistInfo: VideoPlaylistCreate = req.body |
152 | const user: UserModel = res.locals.oauth.token.User | 150 | const user = res.locals.oauth.token.User |
153 | 151 | ||
154 | const videoPlaylist = new VideoPlaylistModel({ | 152 | const videoPlaylist = new VideoPlaylistModel({ |
155 | name: videoPlaylistInfo.displayName, | 153 | name: videoPlaylistInfo.displayName, |
@@ -161,7 +159,7 @@ async function addVideoPlaylist (req: express.Request, res: express.Response) { | |||
161 | videoPlaylist.url = getVideoPlaylistActivityPubUrl(videoPlaylist) // We use the UUID, so set the URL after building the object | 159 | videoPlaylist.url = getVideoPlaylistActivityPubUrl(videoPlaylist) // We use the UUID, so set the URL after building the object |
162 | 160 | ||
163 | if (videoPlaylistInfo.videoChannelId) { | 161 | if (videoPlaylistInfo.videoChannelId) { |
164 | const videoChannel = res.locals.videoChannel as VideoChannelModel | 162 | const videoChannel = res.locals.videoChannel |
165 | 163 | ||
166 | videoPlaylist.videoChannelId = videoChannel.id | 164 | videoPlaylist.videoChannelId = videoChannel.id |
167 | videoPlaylist.VideoChannel = videoChannel | 165 | videoPlaylist.VideoChannel = videoChannel |
@@ -194,7 +192,7 @@ async function addVideoPlaylist (req: express.Request, res: express.Response) { | |||
194 | } | 192 | } |
195 | 193 | ||
196 | async function updateVideoPlaylist (req: express.Request, res: express.Response) { | 194 | async function updateVideoPlaylist (req: express.Request, res: express.Response) { |
197 | const videoPlaylistInstance = res.locals.videoPlaylist as VideoPlaylistModel | 195 | const videoPlaylistInstance = res.locals.videoPlaylist |
198 | const videoPlaylistFieldsSave = videoPlaylistInstance.toJSON() | 196 | const videoPlaylistFieldsSave = videoPlaylistInstance.toJSON() |
199 | const videoPlaylistInfoToUpdate = req.body as VideoPlaylistUpdate | 197 | const videoPlaylistInfoToUpdate = req.body as VideoPlaylistUpdate |
200 | const wasPrivatePlaylist = videoPlaylistInstance.privacy === VideoPlaylistPrivacy.PRIVATE | 198 | const wasPrivatePlaylist = videoPlaylistInstance.privacy === VideoPlaylistPrivacy.PRIVATE |
@@ -219,7 +217,7 @@ async function updateVideoPlaylist (req: express.Request, res: express.Response) | |||
219 | if (videoPlaylistInfoToUpdate.videoChannelId === null) { | 217 | if (videoPlaylistInfoToUpdate.videoChannelId === null) { |
220 | videoPlaylistInstance.videoChannelId = null | 218 | videoPlaylistInstance.videoChannelId = null |
221 | } else { | 219 | } else { |
222 | const videoChannel = res.locals.videoChannel as VideoChannelModel | 220 | const videoChannel = res.locals.videoChannel |
223 | 221 | ||
224 | videoPlaylistInstance.videoChannelId = videoChannel.id | 222 | videoPlaylistInstance.videoChannelId = videoChannel.id |
225 | videoPlaylistInstance.VideoChannel = videoChannel | 223 | videoPlaylistInstance.VideoChannel = videoChannel |
@@ -262,7 +260,7 @@ async function updateVideoPlaylist (req: express.Request, res: express.Response) | |||
262 | } | 260 | } |
263 | 261 | ||
264 | async function removeVideoPlaylist (req: express.Request, res: express.Response) { | 262 | async function removeVideoPlaylist (req: express.Request, res: express.Response) { |
265 | const videoPlaylistInstance: VideoPlaylistModel = res.locals.videoPlaylist | 263 | const videoPlaylistInstance = res.locals.videoPlaylist |
266 | 264 | ||
267 | await sequelizeTypescript.transaction(async t => { | 265 | await sequelizeTypescript.transaction(async t => { |
268 | await videoPlaylistInstance.destroy({ transaction: t }) | 266 | await videoPlaylistInstance.destroy({ transaction: t }) |
@@ -277,8 +275,8 @@ async function removeVideoPlaylist (req: express.Request, res: express.Response) | |||
277 | 275 | ||
278 | async function addVideoInPlaylist (req: express.Request, res: express.Response) { | 276 | async function addVideoInPlaylist (req: express.Request, res: express.Response) { |
279 | const body: VideoPlaylistElementCreate = req.body | 277 | const body: VideoPlaylistElementCreate = req.body |
280 | const videoPlaylist: VideoPlaylistModel = res.locals.videoPlaylist | 278 | const videoPlaylist = res.locals.videoPlaylist |
281 | const video: VideoModel = res.locals.video | 279 | const video = res.locals.video |
282 | 280 | ||
283 | const playlistElement: VideoPlaylistElementModel = await sequelizeTypescript.transaction(async t => { | 281 | const playlistElement: VideoPlaylistElementModel = await sequelizeTypescript.transaction(async t => { |
284 | const position = await VideoPlaylistElementModel.getNextPositionOf(videoPlaylist.id, t) | 282 | const position = await VideoPlaylistElementModel.getNextPositionOf(videoPlaylist.id, t) |
@@ -323,8 +321,8 @@ async function addVideoInPlaylist (req: express.Request, res: express.Response) | |||
323 | 321 | ||
324 | async function updateVideoPlaylistElement (req: express.Request, res: express.Response) { | 322 | async function updateVideoPlaylistElement (req: express.Request, res: express.Response) { |
325 | const body: VideoPlaylistElementUpdate = req.body | 323 | const body: VideoPlaylistElementUpdate = req.body |
326 | const videoPlaylist: VideoPlaylistModel = res.locals.videoPlaylist | 324 | const videoPlaylist = res.locals.videoPlaylist |
327 | const videoPlaylistElement: VideoPlaylistElementModel = res.locals.videoPlaylistElement | 325 | const videoPlaylistElement = res.locals.videoPlaylistElement |
328 | 326 | ||
329 | const playlistElement: VideoPlaylistElementModel = await sequelizeTypescript.transaction(async t => { | 327 | const playlistElement: VideoPlaylistElementModel = await sequelizeTypescript.transaction(async t => { |
330 | if (body.startTimestamp !== undefined) videoPlaylistElement.startTimestamp = body.startTimestamp | 328 | if (body.startTimestamp !== undefined) videoPlaylistElement.startTimestamp = body.startTimestamp |
@@ -346,8 +344,8 @@ async function updateVideoPlaylistElement (req: express.Request, res: express.Re | |||
346 | } | 344 | } |
347 | 345 | ||
348 | async function removeVideoFromPlaylist (req: express.Request, res: express.Response) { | 346 | async function removeVideoFromPlaylist (req: express.Request, res: express.Response) { |
349 | const videoPlaylistElement: VideoPlaylistElementModel = res.locals.videoPlaylistElement | 347 | const videoPlaylistElement = res.locals.videoPlaylistElement |
350 | const videoPlaylist: VideoPlaylistModel = res.locals.videoPlaylist | 348 | const videoPlaylist = res.locals.videoPlaylist |
351 | const positionToDelete = videoPlaylistElement.position | 349 | const positionToDelete = videoPlaylistElement.position |
352 | 350 | ||
353 | await sequelizeTypescript.transaction(async t => { | 351 | await sequelizeTypescript.transaction(async t => { |
@@ -368,7 +366,7 @@ async function removeVideoFromPlaylist (req: express.Request, res: express.Respo | |||
368 | } | 366 | } |
369 | 367 | ||
370 | async function reorderVideosPlaylist (req: express.Request, res: express.Response) { | 368 | async function reorderVideosPlaylist (req: express.Request, res: express.Response) { |
371 | const videoPlaylist: VideoPlaylistModel = res.locals.videoPlaylist | 369 | const videoPlaylist = res.locals.videoPlaylist |
372 | const body: VideoPlaylistReorder = req.body | 370 | const body: VideoPlaylistReorder = req.body |
373 | 371 | ||
374 | const start: number = body.startPosition | 372 | const start: number = body.startPosition |
@@ -416,7 +414,7 @@ async function reorderVideosPlaylist (req: express.Request, res: express.Respons | |||
416 | } | 414 | } |
417 | 415 | ||
418 | async function getVideoPlaylistVideos (req: express.Request, res: express.Response) { | 416 | async function getVideoPlaylistVideos (req: express.Request, res: express.Response) { |
419 | const videoPlaylistInstance: VideoPlaylistModel = res.locals.videoPlaylist | 417 | const videoPlaylistInstance = res.locals.videoPlaylist |
420 | const followerActorId = isUserAbleToSearchRemoteURI(res) ? null : undefined | 418 | const followerActorId = isUserAbleToSearchRemoteURI(res) ? null : undefined |
421 | 419 | ||
422 | const resultList = await VideoModel.listForApi({ | 420 | const resultList = await VideoModel.listForApi({ |
diff --git a/server/controllers/api/videos/abuse.ts b/server/controllers/api/videos/abuse.ts index 32f9c4793..ca70230a2 100644 --- a/server/controllers/api/videos/abuse.ts +++ b/server/controllers/api/videos/abuse.ts | |||
@@ -17,10 +17,8 @@ import { | |||
17 | videoAbuseUpdateValidator | 17 | videoAbuseUpdateValidator |
18 | } from '../../../middlewares' | 18 | } from '../../../middlewares' |
19 | import { AccountModel } from '../../../models/account/account' | 19 | import { AccountModel } from '../../../models/account/account' |
20 | import { VideoModel } from '../../../models/video/video' | ||
21 | import { VideoAbuseModel } from '../../../models/video/video-abuse' | 20 | import { VideoAbuseModel } from '../../../models/video/video-abuse' |
22 | import { auditLoggerFactory, VideoAbuseAuditView } from '../../../helpers/audit-logger' | 21 | import { auditLoggerFactory, VideoAbuseAuditView } from '../../../helpers/audit-logger' |
23 | import { UserModel } from '../../../models/account/user' | ||
24 | import { Notifier } from '../../../lib/notifier' | 22 | import { Notifier } from '../../../lib/notifier' |
25 | import { sendVideoAbuse } from '../../../lib/activitypub/send/send-flag' | 23 | import { sendVideoAbuse } from '../../../lib/activitypub/send/send-flag' |
26 | 24 | ||
@@ -69,7 +67,7 @@ async function listVideoAbuses (req: express.Request, res: express.Response) { | |||
69 | } | 67 | } |
70 | 68 | ||
71 | async function updateVideoAbuse (req: express.Request, res: express.Response) { | 69 | async function updateVideoAbuse (req: express.Request, res: express.Response) { |
72 | const videoAbuse: VideoAbuseModel = res.locals.videoAbuse | 70 | const videoAbuse = res.locals.videoAbuse |
73 | 71 | ||
74 | if (req.body.moderationComment !== undefined) videoAbuse.moderationComment = req.body.moderationComment | 72 | if (req.body.moderationComment !== undefined) videoAbuse.moderationComment = req.body.moderationComment |
75 | if (req.body.state !== undefined) videoAbuse.state = req.body.state | 73 | if (req.body.state !== undefined) videoAbuse.state = req.body.state |
@@ -84,7 +82,7 @@ async function updateVideoAbuse (req: express.Request, res: express.Response) { | |||
84 | } | 82 | } |
85 | 83 | ||
86 | async function deleteVideoAbuse (req: express.Request, res: express.Response) { | 84 | async function deleteVideoAbuse (req: express.Request, res: express.Response) { |
87 | const videoAbuse: VideoAbuseModel = res.locals.videoAbuse | 85 | const videoAbuse = res.locals.videoAbuse |
88 | 86 | ||
89 | await sequelizeTypescript.transaction(t => { | 87 | await sequelizeTypescript.transaction(t => { |
90 | return videoAbuse.destroy({ transaction: t }) | 88 | return videoAbuse.destroy({ transaction: t }) |
@@ -96,11 +94,11 @@ async function deleteVideoAbuse (req: express.Request, res: express.Response) { | |||
96 | } | 94 | } |
97 | 95 | ||
98 | async function reportVideoAbuse (req: express.Request, res: express.Response) { | 96 | async function reportVideoAbuse (req: express.Request, res: express.Response) { |
99 | const videoInstance = res.locals.video as VideoModel | 97 | const videoInstance = res.locals.video |
100 | const body: VideoAbuseCreate = req.body | 98 | const body: VideoAbuseCreate = req.body |
101 | 99 | ||
102 | const videoAbuse: VideoAbuseModel = await sequelizeTypescript.transaction(async t => { | 100 | const videoAbuse: VideoAbuseModel = await sequelizeTypescript.transaction(async t => { |
103 | const reporterAccount = await AccountModel.load((res.locals.oauth.token.User as UserModel).Account.id, t) | 101 | const reporterAccount = await AccountModel.load(res.locals.oauth.token.User.Account.id, t) |
104 | 102 | ||
105 | const abuseToCreate = { | 103 | const abuseToCreate = { |
106 | reporterAccountId: reporterAccount.id, | 104 | reporterAccountId: reporterAccount.id, |
diff --git a/server/controllers/api/videos/blacklist.ts b/server/controllers/api/videos/blacklist.ts index b01296200..d0728eb59 100644 --- a/server/controllers/api/videos/blacklist.ts +++ b/server/controllers/api/videos/blacklist.ts | |||
@@ -17,7 +17,6 @@ import { | |||
17 | import { VideoBlacklistModel } from '../../../models/video/video-blacklist' | 17 | import { VideoBlacklistModel } from '../../../models/video/video-blacklist' |
18 | import { sequelizeTypescript } from '../../../initializers' | 18 | import { sequelizeTypescript } from '../../../initializers' |
19 | import { Notifier } from '../../../lib/notifier' | 19 | import { Notifier } from '../../../lib/notifier' |
20 | import { VideoModel } from '../../../models/video/video' | ||
21 | import { sendDeleteVideo } from '../../../lib/activitypub/send' | 20 | import { sendDeleteVideo } from '../../../lib/activitypub/send' |
22 | import { federateVideoIfNeeded } from '../../../lib/activitypub' | 21 | import { federateVideoIfNeeded } from '../../../lib/activitypub' |
23 | 22 | ||
@@ -87,7 +86,7 @@ async function addVideoToBlacklist (req: express.Request, res: express.Response) | |||
87 | } | 86 | } |
88 | 87 | ||
89 | async function updateVideoBlacklistController (req: express.Request, res: express.Response) { | 88 | async function updateVideoBlacklistController (req: express.Request, res: express.Response) { |
90 | const videoBlacklist = res.locals.videoBlacklist as VideoBlacklistModel | 89 | const videoBlacklist = res.locals.videoBlacklist |
91 | 90 | ||
92 | if (req.body.reason !== undefined) videoBlacklist.reason = req.body.reason | 91 | if (req.body.reason !== undefined) videoBlacklist.reason = req.body.reason |
93 | 92 | ||
@@ -105,8 +104,8 @@ async function listBlacklist (req: express.Request, res: express.Response, next: | |||
105 | } | 104 | } |
106 | 105 | ||
107 | async function removeVideoFromBlacklistController (req: express.Request, res: express.Response, next: express.NextFunction) { | 106 | async function removeVideoFromBlacklistController (req: express.Request, res: express.Response, next: express.NextFunction) { |
108 | const videoBlacklist = res.locals.videoBlacklist as VideoBlacklistModel | 107 | const videoBlacklist = res.locals.videoBlacklist |
109 | const video: VideoModel = res.locals.video | 108 | const video = res.locals.video |
110 | 109 | ||
111 | await sequelizeTypescript.transaction(async t => { | 110 | await sequelizeTypescript.transaction(async t => { |
112 | const unfederated = videoBlacklist.unfederated | 111 | const unfederated = videoBlacklist.unfederated |
diff --git a/server/controllers/api/videos/captions.ts b/server/controllers/api/videos/captions.ts index 9b3661368..2694577d8 100644 --- a/server/controllers/api/videos/captions.ts +++ b/server/controllers/api/videos/captions.ts | |||
@@ -5,7 +5,6 @@ import { createReqFiles } from '../../../helpers/express-utils' | |||
5 | import { CONFIG, MIMETYPES, sequelizeTypescript } from '../../../initializers' | 5 | import { CONFIG, MIMETYPES, sequelizeTypescript } from '../../../initializers' |
6 | import { getFormattedObjects } from '../../../helpers/utils' | 6 | import { getFormattedObjects } from '../../../helpers/utils' |
7 | import { VideoCaptionModel } from '../../../models/video/video-caption' | 7 | import { VideoCaptionModel } from '../../../models/video/video-caption' |
8 | import { VideoModel } from '../../../models/video/video' | ||
9 | import { logger } from '../../../helpers/logger' | 8 | import { logger } from '../../../helpers/logger' |
10 | import { federateVideoIfNeeded } from '../../../lib/activitypub' | 9 | import { federateVideoIfNeeded } from '../../../lib/activitypub' |
11 | import { moveAndProcessCaptionFile } from '../../../helpers/captions-utils' | 10 | import { moveAndProcessCaptionFile } from '../../../helpers/captions-utils' |
@@ -52,7 +51,7 @@ async function listVideoCaptions (req: express.Request, res: express.Response) { | |||
52 | 51 | ||
53 | async function addVideoCaption (req: express.Request, res: express.Response) { | 52 | async function addVideoCaption (req: express.Request, res: express.Response) { |
54 | const videoCaptionPhysicalFile = req.files['captionfile'][0] | 53 | const videoCaptionPhysicalFile = req.files['captionfile'][0] |
55 | const video = res.locals.video as VideoModel | 54 | const video = res.locals.video |
56 | 55 | ||
57 | const videoCaption = new VideoCaptionModel({ | 56 | const videoCaption = new VideoCaptionModel({ |
58 | videoId: video.id, | 57 | videoId: video.id, |
@@ -74,8 +73,8 @@ async function addVideoCaption (req: express.Request, res: express.Response) { | |||
74 | } | 73 | } |
75 | 74 | ||
76 | async function deleteVideoCaption (req: express.Request, res: express.Response) { | 75 | async function deleteVideoCaption (req: express.Request, res: express.Response) { |
77 | const video = res.locals.video as VideoModel | 76 | const video = res.locals.video |
78 | const videoCaption = res.locals.videoCaption as VideoCaptionModel | 77 | const videoCaption = res.locals.videoCaption |
79 | 78 | ||
80 | await sequelizeTypescript.transaction(async t => { | 79 | await sequelizeTypescript.transaction(async t => { |
81 | await videoCaption.destroy({ transaction: t }) | 80 | await videoCaption.destroy({ transaction: t }) |
diff --git a/server/controllers/api/videos/comment.ts b/server/controllers/api/videos/comment.ts index 70c1148ba..176ee8bd4 100644 --- a/server/controllers/api/videos/comment.ts +++ b/server/controllers/api/videos/comment.ts | |||
@@ -8,7 +8,8 @@ import { buildFormattedCommentTree, createVideoComment } from '../../../lib/vide | |||
8 | import { | 8 | import { |
9 | asyncMiddleware, | 9 | asyncMiddleware, |
10 | asyncRetryTransactionMiddleware, | 10 | asyncRetryTransactionMiddleware, |
11 | authenticate, optionalAuthenticate, | 11 | authenticate, |
12 | optionalAuthenticate, | ||
12 | paginationValidator, | 13 | paginationValidator, |
13 | setDefaultPagination, | 14 | setDefaultPagination, |
14 | setDefaultSort | 15 | setDefaultSort |
@@ -21,11 +22,9 @@ import { | |||
21 | removeVideoCommentValidator, | 22 | removeVideoCommentValidator, |
22 | videoCommentThreadsSortValidator | 23 | videoCommentThreadsSortValidator |
23 | } from '../../../middlewares/validators' | 24 | } from '../../../middlewares/validators' |
24 | import { VideoModel } from '../../../models/video/video' | ||
25 | import { VideoCommentModel } from '../../../models/video/video-comment' | 25 | import { VideoCommentModel } from '../../../models/video/video-comment' |
26 | import { auditLoggerFactory, CommentAuditView, getAuditIdFromRes } from '../../../helpers/audit-logger' | 26 | import { auditLoggerFactory, CommentAuditView, getAuditIdFromRes } from '../../../helpers/audit-logger' |
27 | import { AccountModel } from '../../../models/account/account' | 27 | import { AccountModel } from '../../../models/account/account' |
28 | import { UserModel } from '../../../models/account/user' | ||
29 | import { Notifier } from '../../../lib/notifier' | 28 | import { Notifier } from '../../../lib/notifier' |
30 | 29 | ||
31 | const auditLogger = auditLoggerFactory('comments') | 30 | const auditLogger = auditLoggerFactory('comments') |
@@ -70,9 +69,9 @@ export { | |||
70 | 69 | ||
71 | // --------------------------------------------------------------------------- | 70 | // --------------------------------------------------------------------------- |
72 | 71 | ||
73 | async function listVideoThreads (req: express.Request, res: express.Response, next: express.NextFunction) { | 72 | async function listVideoThreads (req: express.Request, res: express.Response) { |
74 | const video = res.locals.video as VideoModel | 73 | const video = res.locals.video |
75 | const user: UserModel = res.locals.oauth ? res.locals.oauth.token.User : undefined | 74 | const user = res.locals.oauth ? res.locals.oauth.token.User : undefined |
76 | 75 | ||
77 | let resultList: ResultList<VideoCommentModel> | 76 | let resultList: ResultList<VideoCommentModel> |
78 | 77 | ||
@@ -88,9 +87,9 @@ async function listVideoThreads (req: express.Request, res: express.Response, ne | |||
88 | return res.json(getFormattedObjects(resultList.data, resultList.total)) | 87 | return res.json(getFormattedObjects(resultList.data, resultList.total)) |
89 | } | 88 | } |
90 | 89 | ||
91 | async function listVideoThreadComments (req: express.Request, res: express.Response, next: express.NextFunction) { | 90 | async function listVideoThreadComments (req: express.Request, res: express.Response) { |
92 | const video = res.locals.video as VideoModel | 91 | const video = res.locals.video |
93 | const user: UserModel = res.locals.oauth ? res.locals.oauth.token.User : undefined | 92 | const user = res.locals.oauth ? res.locals.oauth.token.User : undefined |
94 | 93 | ||
95 | let resultList: ResultList<VideoCommentModel> | 94 | let resultList: ResultList<VideoCommentModel> |
96 | 95 | ||
@@ -110,7 +109,7 @@ async function addVideoCommentThread (req: express.Request, res: express.Respons | |||
110 | const videoCommentInfo: VideoCommentCreate = req.body | 109 | const videoCommentInfo: VideoCommentCreate = req.body |
111 | 110 | ||
112 | const comment = await sequelizeTypescript.transaction(async t => { | 111 | const comment = await sequelizeTypescript.transaction(async t => { |
113 | const account = await AccountModel.load((res.locals.oauth.token.User as UserModel).Account.id, t) | 112 | const account = await AccountModel.load(res.locals.oauth.token.User.Account.id, t) |
114 | 113 | ||
115 | return createVideoComment({ | 114 | return createVideoComment({ |
116 | text: videoCommentInfo.text, | 115 | text: videoCommentInfo.text, |
@@ -132,7 +131,7 @@ async function addVideoCommentReply (req: express.Request, res: express.Response | |||
132 | const videoCommentInfo: VideoCommentCreate = req.body | 131 | const videoCommentInfo: VideoCommentCreate = req.body |
133 | 132 | ||
134 | const comment = await sequelizeTypescript.transaction(async t => { | 133 | const comment = await sequelizeTypescript.transaction(async t => { |
135 | const account = await AccountModel.load((res.locals.oauth.token.User as UserModel).Account.id, t) | 134 | const account = await AccountModel.load(res.locals.oauth.token.User.Account.id, t) |
136 | 135 | ||
137 | return createVideoComment({ | 136 | return createVideoComment({ |
138 | text: videoCommentInfo.text, | 137 | text: videoCommentInfo.text, |
@@ -149,7 +148,7 @@ async function addVideoCommentReply (req: express.Request, res: express.Response | |||
149 | } | 148 | } |
150 | 149 | ||
151 | async function removeVideoComment (req: express.Request, res: express.Response) { | 150 | async function removeVideoComment (req: express.Request, res: express.Response) { |
152 | const videoCommentInstance: VideoCommentModel = res.locals.videoComment | 151 | const videoCommentInstance = res.locals.videoComment |
153 | 152 | ||
154 | await sequelizeTypescript.transaction(async t => { | 153 | await sequelizeTypescript.transaction(async t => { |
155 | await videoCommentInstance.destroy({ transaction: t }) | 154 | await videoCommentInstance.destroy({ transaction: t }) |
diff --git a/server/controllers/api/videos/import.ts b/server/controllers/api/videos/import.ts index 626c81eca..cbd2e8514 100644 --- a/server/controllers/api/videos/import.ts +++ b/server/controllers/api/videos/import.ts | |||
@@ -97,7 +97,7 @@ async function addTorrentImport (req: express.Request, res: express.Response, to | |||
97 | state: VideoImportState.PENDING, | 97 | state: VideoImportState.PENDING, |
98 | userId: user.id | 98 | userId: user.id |
99 | } | 99 | } |
100 | const videoImport: VideoImportModel = await insertIntoDB(video, res.locals.videoChannel, tags, videoImportAttributes) | 100 | const videoImport = await insertIntoDB(video, res.locals.videoChannel, tags, videoImportAttributes) |
101 | 101 | ||
102 | // Create job to import the video | 102 | // Create job to import the video |
103 | const payload = { | 103 | const payload = { |
@@ -139,7 +139,7 @@ async function addYoutubeDLImport (req: express.Request, res: express.Response) | |||
139 | state: VideoImportState.PENDING, | 139 | state: VideoImportState.PENDING, |
140 | userId: user.id | 140 | userId: user.id |
141 | } | 141 | } |
142 | const videoImport: VideoImportModel = await insertIntoDB(video, res.locals.videoChannel, tags, videoImportAttributes) | 142 | const videoImport = await insertIntoDB(video, res.locals.videoChannel, tags, videoImportAttributes) |
143 | 143 | ||
144 | // Create job to import the video | 144 | // Create job to import the video |
145 | const payload = { | 145 | const payload = { |
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index 27f67895e..db4f4c96f 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts | |||
@@ -295,7 +295,7 @@ async function addVideo (req: express.Request, res: express.Response) { | |||
295 | } | 295 | } |
296 | 296 | ||
297 | async function updateVideo (req: express.Request, res: express.Response) { | 297 | async function updateVideo (req: express.Request, res: express.Response) { |
298 | const videoInstance: VideoModel = res.locals.video | 298 | const videoInstance = res.locals.video |
299 | const videoFieldsSave = videoInstance.toJSON() | 299 | const videoFieldsSave = videoInstance.toJSON() |
300 | const oldVideoAuditView = new VideoAuditView(videoInstance.toFormattedDetailsJSON()) | 300 | const oldVideoAuditView = new VideoAuditView(videoInstance.toFormattedDetailsJSON()) |
301 | const videoInfoToUpdate: VideoUpdate = req.body | 301 | const videoInfoToUpdate: VideoUpdate = req.body |
@@ -407,7 +407,7 @@ async function updateVideo (req: express.Request, res: express.Response) { | |||
407 | async function getVideo (req: express.Request, res: express.Response) { | 407 | async function getVideo (req: express.Request, res: express.Response) { |
408 | // We need more attributes | 408 | // We need more attributes |
409 | const userId: number = res.locals.oauth ? res.locals.oauth.token.User.id : null | 409 | const userId: number = res.locals.oauth ? res.locals.oauth.token.User.id : null |
410 | const video: VideoModel = await VideoModel.loadForGetAPI(res.locals.video.id, undefined, userId) | 410 | const video = await VideoModel.loadForGetAPI(res.locals.video.id, undefined, userId) |
411 | 411 | ||
412 | if (video.isOutdated()) { | 412 | if (video.isOutdated()) { |
413 | JobQueue.Instance.createJob({ type: 'activitypub-refresher', payload: { type: 'video', url: video.url } }) | 413 | JobQueue.Instance.createJob({ type: 'activitypub-refresher', payload: { type: 'video', url: video.url } }) |
@@ -472,7 +472,7 @@ async function listVideos (req: express.Request, res: express.Response) { | |||
472 | } | 472 | } |
473 | 473 | ||
474 | async function removeVideo (req: express.Request, res: express.Response) { | 474 | async function removeVideo (req: express.Request, res: express.Response) { |
475 | const videoInstance: VideoModel = res.locals.video | 475 | const videoInstance = res.locals.video |
476 | 476 | ||
477 | await sequelizeTypescript.transaction(async t => { | 477 | await sequelizeTypescript.transaction(async t => { |
478 | await videoInstance.destroy({ transaction: t }) | 478 | await videoInstance.destroy({ transaction: t }) |
diff --git a/server/controllers/api/videos/ownership.ts b/server/controllers/api/videos/ownership.ts index 5ea7d7c6a..fc73856c9 100644 --- a/server/controllers/api/videos/ownership.ts +++ b/server/controllers/api/videos/ownership.ts | |||
@@ -11,8 +11,6 @@ import { | |||
11 | videosChangeOwnershipValidator, | 11 | videosChangeOwnershipValidator, |
12 | videosTerminateChangeOwnershipValidator | 12 | videosTerminateChangeOwnershipValidator |
13 | } from '../../../middlewares' | 13 | } from '../../../middlewares' |
14 | import { AccountModel } from '../../../models/account/account' | ||
15 | import { VideoModel } from '../../../models/video/video' | ||
16 | import { VideoChangeOwnershipModel } from '../../../models/video/video-change-ownership' | 14 | import { VideoChangeOwnershipModel } from '../../../models/video/video-change-ownership' |
17 | import { VideoChangeOwnershipStatus, VideoPrivacy, VideoState } from '../../../../shared/models/videos' | 15 | import { VideoChangeOwnershipStatus, VideoPrivacy, VideoState } from '../../../../shared/models/videos' |
18 | import { VideoChannelModel } from '../../../models/video/video-channel' | 16 | import { VideoChannelModel } from '../../../models/video/video-channel' |
@@ -58,9 +56,9 @@ export { | |||
58 | // --------------------------------------------------------------------------- | 56 | // --------------------------------------------------------------------------- |
59 | 57 | ||
60 | async function giveVideoOwnership (req: express.Request, res: express.Response) { | 58 | async function giveVideoOwnership (req: express.Request, res: express.Response) { |
61 | const videoInstance = res.locals.video as VideoModel | 59 | const videoInstance = res.locals.video |
62 | const initiatorAccountId = (res.locals.oauth.token.User as UserModel).Account.id | 60 | const initiatorAccountId = res.locals.oauth.token.User.Account.id |
63 | const nextOwner = res.locals.nextOwner as AccountModel | 61 | const nextOwner = res.locals.nextOwner |
64 | 62 | ||
65 | await sequelizeTypescript.transaction(t => { | 63 | await sequelizeTypescript.transaction(t => { |
66 | return VideoChangeOwnershipModel.findOrCreate({ | 64 | return VideoChangeOwnershipModel.findOrCreate({ |
@@ -85,7 +83,7 @@ async function giveVideoOwnership (req: express.Request, res: express.Response) | |||
85 | } | 83 | } |
86 | 84 | ||
87 | async function listVideoOwnership (req: express.Request, res: express.Response) { | 85 | async function listVideoOwnership (req: express.Request, res: express.Response) { |
88 | const currentAccountId = (res.locals.oauth.token.User as UserModel).Account.id | 86 | const currentAccountId = res.locals.oauth.token.User.Account.id |
89 | 87 | ||
90 | const resultList = await VideoChangeOwnershipModel.listForApi( | 88 | const resultList = await VideoChangeOwnershipModel.listForApi( |
91 | currentAccountId, | 89 | currentAccountId, |
@@ -99,9 +97,9 @@ async function listVideoOwnership (req: express.Request, res: express.Response) | |||
99 | 97 | ||
100 | async function acceptOwnership (req: express.Request, res: express.Response) { | 98 | async function acceptOwnership (req: express.Request, res: express.Response) { |
101 | return sequelizeTypescript.transaction(async t => { | 99 | return sequelizeTypescript.transaction(async t => { |
102 | const videoChangeOwnership = res.locals.videoChangeOwnership as VideoChangeOwnershipModel | 100 | const videoChangeOwnership = res.locals.videoChangeOwnership |
103 | const targetVideo = videoChangeOwnership.Video | 101 | const targetVideo = videoChangeOwnership.Video |
104 | const channel = res.locals.videoChannel as VideoChannelModel | 102 | const channel = res.locals.videoChannel |
105 | 103 | ||
106 | const oldVideoChannel = await VideoChannelModel.loadByIdAndPopulateAccount(targetVideo.channelId) | 104 | const oldVideoChannel = await VideoChannelModel.loadByIdAndPopulateAccount(targetVideo.channelId) |
107 | 105 | ||
@@ -123,7 +121,7 @@ async function acceptOwnership (req: express.Request, res: express.Response) { | |||
123 | 121 | ||
124 | async function refuseOwnership (req: express.Request, res: express.Response) { | 122 | async function refuseOwnership (req: express.Request, res: express.Response) { |
125 | return sequelizeTypescript.transaction(async t => { | 123 | return sequelizeTypescript.transaction(async t => { |
126 | const videoChangeOwnership = res.locals.videoChangeOwnership as VideoChangeOwnershipModel | 124 | const videoChangeOwnership = res.locals.videoChangeOwnership |
127 | 125 | ||
128 | videoChangeOwnership.set('status', VideoChangeOwnershipStatus.REFUSED) | 126 | videoChangeOwnership.set('status', VideoChangeOwnershipStatus.REFUSED) |
129 | await videoChangeOwnership.save({ transaction: t }) | 127 | await videoChangeOwnership.save({ transaction: t }) |
diff --git a/server/controllers/api/videos/rate.ts b/server/controllers/api/videos/rate.ts index 53952a0a2..914c596c3 100644 --- a/server/controllers/api/videos/rate.ts +++ b/server/controllers/api/videos/rate.ts | |||
@@ -6,7 +6,6 @@ import { getRateUrl, sendVideoRateChange } from '../../../lib/activitypub' | |||
6 | import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoUpdateRateValidator } from '../../../middlewares' | 6 | import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoUpdateRateValidator } from '../../../middlewares' |
7 | import { AccountModel } from '../../../models/account/account' | 7 | import { AccountModel } from '../../../models/account/account' |
8 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' | 8 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' |
9 | import { VideoModel } from '../../../models/video/video' | ||
10 | 9 | ||
11 | const rateVideoRouter = express.Router() | 10 | const rateVideoRouter = express.Router() |
12 | 11 | ||
@@ -27,8 +26,8 @@ export { | |||
27 | async function rateVideo (req: express.Request, res: express.Response) { | 26 | async function rateVideo (req: express.Request, res: express.Response) { |
28 | const body: UserVideoRateUpdate = req.body | 27 | const body: UserVideoRateUpdate = req.body |
29 | const rateType = body.rating | 28 | const rateType = body.rating |
30 | const videoInstance: VideoModel = res.locals.video | 29 | const videoInstance = res.locals.video |
31 | const userAccount: AccountModel = res.locals.oauth.token.User.Account | 30 | const userAccount = res.locals.oauth.token.User.Account |
32 | 31 | ||
33 | await sequelizeTypescript.transaction(async t => { | 32 | await sequelizeTypescript.transaction(async t => { |
34 | const sequelizeOptions = { transaction: t } | 33 | const sequelizeOptions = { transaction: t } |
diff --git a/server/controllers/api/videos/watching.ts b/server/controllers/api/videos/watching.ts index e8876b47a..6bc60e045 100644 --- a/server/controllers/api/videos/watching.ts +++ b/server/controllers/api/videos/watching.ts | |||
@@ -21,7 +21,7 @@ export { | |||
21 | // --------------------------------------------------------------------------- | 21 | // --------------------------------------------------------------------------- |
22 | 22 | ||
23 | async function userWatchVideo (req: express.Request, res: express.Response) { | 23 | async function userWatchVideo (req: express.Request, res: express.Response) { |
24 | const user = res.locals.oauth.token.User as UserModel | 24 | const user = res.locals.oauth.token.User |
25 | 25 | ||
26 | const body: UserWatchingVideo = req.body | 26 | const body: UserWatchingVideo = req.body |
27 | const { id: videoId } = res.locals.video as { id: number } | 27 | const { id: videoId } = res.locals.video as { id: number } |