diff options
author | Chocobozzz <me@florianbigard.com> | 2017-12-12 17:53:50 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2017-12-13 16:50:33 +0100 |
commit | 3fd3ab2d34d512b160a5e6084d7609be7b4f4452 (patch) | |
tree | e5ca358287fca6ecacce83defcf23af1e8e9f419 /server/controllers | |
parent | c893d4514e6ecbf282c7985fe5f82b8acd8a1137 (diff) | |
download | PeerTube-3fd3ab2d34d512b160a5e6084d7609be7b4f4452.tar.gz PeerTube-3fd3ab2d34d512b160a5e6084d7609be7b4f4452.tar.zst PeerTube-3fd3ab2d34d512b160a5e6084d7609be7b4f4452.zip |
Move models to typescript-sequelize
Diffstat (limited to 'server/controllers')
-rw-r--r-- | server/controllers/activitypub/client.ts | 48 | ||||
-rw-r--r-- | server/controllers/activitypub/outbox.ts | 8 | ||||
-rw-r--r-- | server/controllers/api/jobs.ts | 14 | ||||
-rw-r--r-- | server/controllers/api/oauth-clients.ts | 4 | ||||
-rw-r--r-- | server/controllers/api/server/follows.ts | 54 | ||||
-rw-r--r-- | server/controllers/api/users.ts | 28 | ||||
-rw-r--r-- | server/controllers/api/videos/abuse.ts | 17 | ||||
-rw-r--r-- | server/controllers/api/videos/blacklist.ts | 12 | ||||
-rw-r--r-- | server/controllers/api/videos/channel.ts | 27 | ||||
-rw-r--r-- | server/controllers/api/videos/index.ts | 53 | ||||
-rw-r--r-- | server/controllers/api/videos/rate.ts | 20 | ||||
-rw-r--r-- | server/controllers/client.ts | 12 | ||||
-rw-r--r-- | server/controllers/services.ts | 8 | ||||
-rw-r--r-- | server/controllers/static.ts | 1 | ||||
-rw-r--r-- | server/controllers/webfinger.ts | 8 |
15 files changed, 158 insertions, 156 deletions
diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.ts index a478acd14..72b216254 100644 --- a/server/controllers/activitypub/client.ts +++ b/server/controllers/activitypub/client.ts | |||
@@ -1,20 +1,22 @@ | |||
1 | // Intercept ActivityPub client requests | 1 | // Intercept ActivityPub client requests |
2 | import * as express from 'express' | 2 | import * as express from 'express' |
3 | import { pageToStartAndCount } from '../../helpers' | 3 | import { activityPubCollectionPagination, pageToStartAndCount } from '../../helpers' |
4 | import { activityPubCollectionPagination } from '../../helpers/activitypub' | 4 | import { ACTIVITY_PUB, CONFIG } from '../../initializers' |
5 | 5 | import { buildVideoChannelAnnounceToFollowers } from '../../lib/activitypub/send' | |
6 | import { database as db } from '../../initializers' | ||
7 | import { ACTIVITY_PUB, CONFIG } from '../../initializers/constants' | ||
8 | import { buildVideoChannelAnnounceToFollowers } from '../../lib/activitypub/send/send-announce' | ||
9 | import { buildVideoAnnounceToFollowers } from '../../lib/index' | 6 | import { buildVideoAnnounceToFollowers } from '../../lib/index' |
10 | import { executeIfActivityPub, localAccountValidator } from '../../middlewares' | 7 | import { asyncMiddleware, executeIfActivityPub, localAccountValidator } from '../../middlewares' |
11 | import { asyncMiddleware } from '../../middlewares/async' | 8 | import { |
12 | import { videoChannelsGetValidator, videoChannelsShareValidator } from '../../middlewares/validators/video-channels' | 9 | videoChannelsGetValidator, |
13 | import { videosGetValidator, videosShareValidator } from '../../middlewares/validators/videos' | 10 | videoChannelsShareValidator, |
14 | import { AccountInstance, VideoChannelInstance } from '../../models' | 11 | videosGetValidator, |
15 | import { VideoChannelShareInstance } from '../../models/video/video-channel-share-interface' | 12 | videosShareValidator |
16 | import { VideoInstance } from '../../models/video/video-interface' | 13 | } from '../../middlewares/validators' |
17 | import { VideoShareInstance } from '../../models/video/video-share-interface' | 14 | import { AccountModel } from '../../models/account/account' |
15 | import { AccountFollowModel } from '../../models/account/account-follow' | ||
16 | import { VideoModel } from '../../models/video/video' | ||
17 | import { VideoChannelModel } from '../../models/video/video-channel' | ||
18 | import { VideoChannelShareModel } from '../../models/video/video-channel-share' | ||
19 | import { VideoShareModel } from '../../models/video/video-share' | ||
18 | 20 | ||
19 | const activityPubClientRouter = express.Router() | 21 | const activityPubClientRouter = express.Router() |
20 | 22 | ||
@@ -62,57 +64,57 @@ export { | |||
62 | // --------------------------------------------------------------------------- | 64 | // --------------------------------------------------------------------------- |
63 | 65 | ||
64 | function accountController (req: express.Request, res: express.Response, next: express.NextFunction) { | 66 | function accountController (req: express.Request, res: express.Response, next: express.NextFunction) { |
65 | const account: AccountInstance = res.locals.account | 67 | const account: AccountModel = res.locals.account |
66 | 68 | ||
67 | return res.json(account.toActivityPubObject()).end() | 69 | return res.json(account.toActivityPubObject()).end() |
68 | } | 70 | } |
69 | 71 | ||
70 | async function accountFollowersController (req: express.Request, res: express.Response, next: express.NextFunction) { | 72 | async function accountFollowersController (req: express.Request, res: express.Response, next: express.NextFunction) { |
71 | const account: AccountInstance = res.locals.account | 73 | const account: AccountModel = res.locals.account |
72 | 74 | ||
73 | const page = req.query.page || 1 | 75 | const page = req.query.page || 1 |
74 | const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE) | 76 | const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE) |
75 | 77 | ||
76 | const result = await db.AccountFollow.listAcceptedFollowerUrlsForApi([ account.id ], undefined, start, count) | 78 | const result = await AccountFollowModel.listAcceptedFollowerUrlsForApi([ account.id ], undefined, start, count) |
77 | const activityPubResult = activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.url, page, result) | 79 | const activityPubResult = activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.url, page, result) |
78 | 80 | ||
79 | return res.json(activityPubResult) | 81 | return res.json(activityPubResult) |
80 | } | 82 | } |
81 | 83 | ||
82 | async function accountFollowingController (req: express.Request, res: express.Response, next: express.NextFunction) { | 84 | async function accountFollowingController (req: express.Request, res: express.Response, next: express.NextFunction) { |
83 | const account: AccountInstance = res.locals.account | 85 | const account: AccountModel = res.locals.account |
84 | 86 | ||
85 | const page = req.query.page || 1 | 87 | const page = req.query.page || 1 |
86 | const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE) | 88 | const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE) |
87 | 89 | ||
88 | const result = await db.AccountFollow.listAcceptedFollowingUrlsForApi([ account.id ], undefined, start, count) | 90 | const result = await AccountFollowModel.listAcceptedFollowingUrlsForApi([ account.id ], undefined, start, count) |
89 | const activityPubResult = activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.url, page, result) | 91 | const activityPubResult = activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.url, page, result) |
90 | 92 | ||
91 | return res.json(activityPubResult) | 93 | return res.json(activityPubResult) |
92 | } | 94 | } |
93 | 95 | ||
94 | function videoController (req: express.Request, res: express.Response, next: express.NextFunction) { | 96 | function videoController (req: express.Request, res: express.Response, next: express.NextFunction) { |
95 | const video: VideoInstance = res.locals.video | 97 | const video: VideoModel = res.locals.video |
96 | 98 | ||
97 | return res.json(video.toActivityPubObject()) | 99 | return res.json(video.toActivityPubObject()) |
98 | } | 100 | } |
99 | 101 | ||
100 | async function videoAnnounceController (req: express.Request, res: express.Response, next: express.NextFunction) { | 102 | async function videoAnnounceController (req: express.Request, res: express.Response, next: express.NextFunction) { |
101 | const share = res.locals.videoShare as VideoShareInstance | 103 | const share = res.locals.videoShare as VideoShareModel |
102 | const object = await buildVideoAnnounceToFollowers(share.Account, res.locals.video, undefined) | 104 | const object = await buildVideoAnnounceToFollowers(share.Account, res.locals.video, undefined) |
103 | 105 | ||
104 | return res.json(object) | 106 | return res.json(object) |
105 | } | 107 | } |
106 | 108 | ||
107 | async function videoChannelAnnounceController (req: express.Request, res: express.Response, next: express.NextFunction) { | 109 | async function videoChannelAnnounceController (req: express.Request, res: express.Response, next: express.NextFunction) { |
108 | const share = res.locals.videoChannelShare as VideoChannelShareInstance | 110 | const share = res.locals.videoChannelShare as VideoChannelShareModel |
109 | const object = await buildVideoChannelAnnounceToFollowers(share.Account, share.VideoChannel, undefined) | 111 | const object = await buildVideoChannelAnnounceToFollowers(share.Account, share.VideoChannel, undefined) |
110 | 112 | ||
111 | return res.json(object) | 113 | return res.json(object) |
112 | } | 114 | } |
113 | 115 | ||
114 | async function videoChannelController (req: express.Request, res: express.Response, next: express.NextFunction) { | 116 | async function videoChannelController (req: express.Request, res: express.Response, next: express.NextFunction) { |
115 | const videoChannel: VideoChannelInstance = res.locals.videoChannel | 117 | const videoChannel: VideoChannelModel = res.locals.videoChannel |
116 | 118 | ||
117 | return res.json(videoChannel.toActivityPubObject()) | 119 | return res.json(videoChannel.toActivityPubObject()) |
118 | } | 120 | } |
diff --git a/server/controllers/activitypub/outbox.ts b/server/controllers/activitypub/outbox.ts index 5a2d43f3d..dc6b72a6e 100644 --- a/server/controllers/activitypub/outbox.ts +++ b/server/controllers/activitypub/outbox.ts | |||
@@ -2,13 +2,13 @@ import * as express from 'express' | |||
2 | import { Activity } from '../../../shared/models/activitypub/activity' | 2 | import { Activity } from '../../../shared/models/activitypub/activity' |
3 | import { activityPubCollectionPagination } from '../../helpers/activitypub' | 3 | import { activityPubCollectionPagination } from '../../helpers/activitypub' |
4 | import { pageToStartAndCount } from '../../helpers/core-utils' | 4 | import { pageToStartAndCount } from '../../helpers/core-utils' |
5 | import { database as db } from '../../initializers' | ||
6 | import { ACTIVITY_PUB } from '../../initializers/constants' | 5 | import { ACTIVITY_PUB } from '../../initializers/constants' |
7 | import { addActivityData } from '../../lib/activitypub/send/send-add' | 6 | import { addActivityData } from '../../lib/activitypub/send/send-add' |
8 | import { getAnnounceActivityPubUrl } from '../../lib/activitypub/url' | 7 | import { getAnnounceActivityPubUrl } from '../../lib/activitypub/url' |
9 | import { announceActivityData } from '../../lib/index' | 8 | import { announceActivityData } from '../../lib/index' |
10 | import { asyncMiddleware, localAccountValidator } from '../../middlewares' | 9 | import { asyncMiddleware, localAccountValidator } from '../../middlewares' |
11 | import { AccountInstance } from '../../models/account/account-interface' | 10 | import { AccountModel } from '../../models/account/account' |
11 | import { VideoModel } from '../../models/video/video' | ||
12 | 12 | ||
13 | const outboxRouter = express.Router() | 13 | const outboxRouter = express.Router() |
14 | 14 | ||
@@ -26,12 +26,12 @@ export { | |||
26 | // --------------------------------------------------------------------------- | 26 | // --------------------------------------------------------------------------- |
27 | 27 | ||
28 | async function outboxController (req: express.Request, res: express.Response, next: express.NextFunction) { | 28 | async function outboxController (req: express.Request, res: express.Response, next: express.NextFunction) { |
29 | const account: AccountInstance = res.locals.account | 29 | const account: AccountModel = res.locals.account |
30 | 30 | ||
31 | const page = req.query.page || 1 | 31 | const page = req.query.page || 1 |
32 | const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE) | 32 | const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE) |
33 | 33 | ||
34 | const data = await db.Video.listAllAndSharedByAccountForOutbox(account.id, start, count) | 34 | const data = await VideoModel.listAllAndSharedByAccountForOutbox(account.id, start, count) |
35 | const activities: Activity[] = [] | 35 | const activities: Activity[] = [] |
36 | 36 | ||
37 | for (const video of data.data) { | 37 | for (const video of data.data) { |
diff --git a/server/controllers/api/jobs.ts b/server/controllers/api/jobs.ts index f6fbff369..4e7cd1ee3 100644 --- a/server/controllers/api/jobs.ts +++ b/server/controllers/api/jobs.ts | |||
@@ -1,11 +1,9 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { asyncMiddleware, jobsSortValidator, setJobsSort, setPagination } from '../../middlewares' | 2 | import { UserRight } from '../../../shared/models/users' |
3 | import { paginationValidator } from '../../middlewares/validators/pagination' | 3 | import { getFormattedObjects } from '../../helpers' |
4 | import { database as db } from '../../initializers' | 4 | import { asyncMiddleware, authenticate, ensureUserHasRight, jobsSortValidator, setJobsSort, setPagination } from '../../middlewares' |
5 | import { getFormattedObjects } from '../../helpers/utils' | 5 | import { paginationValidator } from '../../middlewares/validators' |
6 | import { authenticate } from '../../middlewares/oauth' | 6 | import { JobModel } from '../../models/job/job' |
7 | import { ensureUserHasRight } from '../../middlewares/user-right' | ||
8 | import { UserRight } from '../../../shared/models/users/user-right.enum' | ||
9 | 7 | ||
10 | const jobsRouter = express.Router() | 8 | const jobsRouter = express.Router() |
11 | 9 | ||
@@ -28,7 +26,7 @@ export { | |||
28 | // --------------------------------------------------------------------------- | 26 | // --------------------------------------------------------------------------- |
29 | 27 | ||
30 | async function listJobs (req: express.Request, res: express.Response, next: express.NextFunction) { | 28 | async function listJobs (req: express.Request, res: express.Response, next: express.NextFunction) { |
31 | const resultList = await db.Job.listForApi(req.query.start, req.query.count, req.query.sort) | 29 | const resultList = await JobModel.listForApi(req.query.start, req.query.count, req.query.sort) |
32 | 30 | ||
33 | return res.json(getFormattedObjects(resultList.data, resultList.total)) | 31 | return res.json(getFormattedObjects(resultList.data, resultList.total)) |
34 | } | 32 | } |
diff --git a/server/controllers/api/oauth-clients.ts b/server/controllers/api/oauth-clients.ts index ac1ee9e36..bc02fce90 100644 --- a/server/controllers/api/oauth-clients.ts +++ b/server/controllers/api/oauth-clients.ts | |||
@@ -3,8 +3,8 @@ import * as express from 'express' | |||
3 | import { CONFIG } from '../../initializers' | 3 | import { CONFIG } from '../../initializers' |
4 | import { logger } from '../../helpers' | 4 | import { logger } from '../../helpers' |
5 | import { asyncMiddleware } from '../../middlewares' | 5 | import { asyncMiddleware } from '../../middlewares' |
6 | import { database as db } from '../../initializers/database' | ||
7 | import { OAuthClientLocal } from '../../../shared' | 6 | import { OAuthClientLocal } from '../../../shared' |
7 | import { OAuthClientModel } from '../../models/oauth/oauth-client' | ||
8 | 8 | ||
9 | const oauthClientsRouter = express.Router() | 9 | const oauthClientsRouter = express.Router() |
10 | 10 | ||
@@ -27,7 +27,7 @@ async function getLocalClient (req: express.Request, res: express.Response, next | |||
27 | return res.type('json').status(403).end() | 27 | return res.type('json').status(403).end() |
28 | } | 28 | } |
29 | 29 | ||
30 | const client = await db.OAuthClient.loadFirstClient() | 30 | const client = await OAuthClientModel.loadFirstClient() |
31 | if (!client) throw new Error('No client available.') | 31 | if (!client) throw new Error('No client available.') |
32 | 32 | ||
33 | const json: OAuthClientLocal = { | 33 | const json: OAuthClientLocal = { |
diff --git a/server/controllers/api/server/follows.ts b/server/controllers/api/server/follows.ts index c2fb37c39..913998e3a 100644 --- a/server/controllers/api/server/follows.ts +++ b/server/controllers/api/server/follows.ts | |||
@@ -1,24 +1,24 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { UserRight } from '../../../../shared/models/users/user-right.enum' | 2 | import { UserRight } from '../../../../shared/models/users' |
3 | import { getFormattedObjects } from '../../../helpers' | 3 | import { getAccountFromWebfinger, getFormattedObjects, getServerAccount, logger, retryTransactionWrapper } from '../../../helpers' |
4 | import { retryTransactionWrapper } from '../../../helpers/database-utils' | 4 | import { sequelizeTypescript, SERVER_ACCOUNT_NAME } from '../../../initializers' |
5 | import { logger } from '../../../helpers/logger' | 5 | import { saveAccountAndServerIfNotExist } from '../../../lib/activitypub' |
6 | import { getServerAccount } from '../../../helpers/utils' | 6 | import { sendUndoFollow } from '../../../lib/activitypub/send' |
7 | import { getAccountFromWebfinger } from '../../../helpers/webfinger' | ||
8 | import { SERVER_ACCOUNT_NAME } from '../../../initializers/constants' | ||
9 | import { database as db } from '../../../initializers/database' | ||
10 | import { saveAccountAndServerIfNotExist } from '../../../lib/activitypub/account' | ||
11 | import { sendUndoFollow } from '../../../lib/activitypub/send/send-undo' | ||
12 | import { sendFollow } from '../../../lib/index' | 7 | import { sendFollow } from '../../../lib/index' |
13 | import { asyncMiddleware, paginationValidator, removeFollowingValidator, setFollowersSort, setPagination } from '../../../middlewares' | 8 | import { |
14 | import { authenticate } from '../../../middlewares/oauth' | 9 | asyncMiddleware, |
15 | import { setBodyHostsPort } from '../../../middlewares/servers' | 10 | authenticate, |
16 | import { setFollowingSort } from '../../../middlewares/sort' | 11 | ensureUserHasRight, |
17 | import { ensureUserHasRight } from '../../../middlewares/user-right' | 12 | paginationValidator, |
18 | import { followValidator } from '../../../middlewares/validators/follows' | 13 | removeFollowingValidator, |
19 | import { followersSortValidator, followingSortValidator } from '../../../middlewares/validators/sort' | 14 | setBodyHostsPort, |
20 | import { AccountInstance } from '../../../models/account/account-interface' | 15 | setFollowersSort, |
21 | import { AccountFollowInstance } from '../../../models/index' | 16 | setFollowingSort, |
17 | setPagination | ||
18 | } from '../../../middlewares' | ||
19 | import { followersSortValidator, followingSortValidator, followValidator } from '../../../middlewares/validators' | ||
20 | import { AccountModel } from '../../../models/account/account' | ||
21 | import { AccountFollowModel } from '../../../models/account/account-follow' | ||
22 | 22 | ||
23 | const serverFollowsRouter = express.Router() | 23 | const serverFollowsRouter = express.Router() |
24 | 24 | ||
@@ -63,14 +63,14 @@ export { | |||
63 | 63 | ||
64 | async function listFollowing (req: express.Request, res: express.Response, next: express.NextFunction) { | 64 | async function listFollowing (req: express.Request, res: express.Response, next: express.NextFunction) { |
65 | const serverAccount = await getServerAccount() | 65 | const serverAccount = await getServerAccount() |
66 | const resultList = await db.AccountFollow.listFollowingForApi(serverAccount.id, req.query.start, req.query.count, req.query.sort) | 66 | const resultList = await AccountFollowModel.listFollowingForApi(serverAccount.id, req.query.start, req.query.count, req.query.sort) |
67 | 67 | ||
68 | return res.json(getFormattedObjects(resultList.data, resultList.total)) | 68 | return res.json(getFormattedObjects(resultList.data, resultList.total)) |
69 | } | 69 | } |
70 | 70 | ||
71 | async function listFollowers (req: express.Request, res: express.Response, next: express.NextFunction) { | 71 | async function listFollowers (req: express.Request, res: express.Response, next: express.NextFunction) { |
72 | const serverAccount = await getServerAccount() | 72 | const serverAccount = await getServerAccount() |
73 | const resultList = await db.AccountFollow.listFollowersForApi(serverAccount.id, req.query.start, req.query.count, req.query.sort) | 73 | const resultList = await AccountFollowModel.listFollowersForApi(serverAccount.id, req.query.start, req.query.count, req.query.sort) |
74 | 74 | ||
75 | return res.json(getFormattedObjects(resultList.data, resultList.total)) | 75 | return res.json(getFormattedObjects(resultList.data, resultList.total)) |
76 | } | 76 | } |
@@ -110,14 +110,14 @@ async function followRetry (req: express.Request, res: express.Response, next: e | |||
110 | return res.status(204).end() | 110 | return res.status(204).end() |
111 | } | 111 | } |
112 | 112 | ||
113 | async function follow (fromAccount: AccountInstance, targetAccount: AccountInstance, targetAlreadyInDB: boolean) { | 113 | async function follow (fromAccount: AccountModel, targetAccount: AccountModel, targetAlreadyInDB: boolean) { |
114 | try { | 114 | try { |
115 | await db.sequelize.transaction(async t => { | 115 | await sequelizeTypescript.transaction(async t => { |
116 | if (targetAlreadyInDB === false) { | 116 | if (targetAlreadyInDB === false) { |
117 | await saveAccountAndServerIfNotExist(targetAccount, t) | 117 | await saveAccountAndServerIfNotExist(targetAccount, t) |
118 | } | 118 | } |
119 | 119 | ||
120 | const [ accountFollow ] = await db.AccountFollow.findOrCreate({ | 120 | const [ accountFollow ] = await AccountFollowModel.findOrCreate({ |
121 | where: { | 121 | where: { |
122 | accountId: fromAccount.id, | 122 | accountId: fromAccount.id, |
123 | targetAccountId: targetAccount.id | 123 | targetAccountId: targetAccount.id |
@@ -145,9 +145,9 @@ async function follow (fromAccount: AccountInstance, targetAccount: AccountInsta | |||
145 | } | 145 | } |
146 | 146 | ||
147 | async function removeFollow (req: express.Request, res: express.Response, next: express.NextFunction) { | 147 | async function removeFollow (req: express.Request, res: express.Response, next: express.NextFunction) { |
148 | const follow: AccountFollowInstance = res.locals.follow | 148 | const follow: AccountFollowModel = res.locals.follow |
149 | 149 | ||
150 | await db.sequelize.transaction(async t => { | 150 | await sequelizeTypescript.transaction(async t => { |
151 | if (follow.state === 'accepted') await sendUndoFollow(follow, t) | 151 | if (follow.state === 'accepted') await sendUndoFollow(follow, t) |
152 | 152 | ||
153 | await follow.destroy({ transaction: t }) | 153 | await follow.destroy({ transaction: t }) |
@@ -164,7 +164,7 @@ async function removeFollow (req: express.Request, res: express.Response, next: | |||
164 | 164 | ||
165 | async function loadLocalOrGetAccountFromWebfinger (name: string, host: string) { | 165 | async function loadLocalOrGetAccountFromWebfinger (name: string, host: string) { |
166 | let loadedFromDB = true | 166 | let loadedFromDB = true |
167 | let account = await db.Account.loadByNameAndHost(name, host) | 167 | let account = await AccountModel.loadByNameAndHost(name, host) |
168 | 168 | ||
169 | if (!account) { | 169 | if (!account) { |
170 | const nameWithDomain = name + '@' + host | 170 | const nameWithDomain = name + '@' + host |
diff --git a/server/controllers/api/users.ts b/server/controllers/api/users.ts index f9b871724..d6c0e67f9 100644 --- a/server/controllers/api/users.ts +++ b/server/controllers/api/users.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { UserCreate, UserRight, UserRole, UserUpdate, UserUpdateMe, UserVideoRate as FormattedUserVideoRate } from '../../../shared' | 2 | import { UserCreate, UserRight, UserRole, UserUpdate, UserUpdateMe, UserVideoRate as FormattedUserVideoRate } from '../../../shared' |
3 | import { getFormattedObjects, logger, retryTransactionWrapper } from '../../helpers' | 3 | import { getFormattedObjects, logger, retryTransactionWrapper } from '../../helpers' |
4 | import { CONFIG, database as db } from '../../initializers' | 4 | import { CONFIG } from '../../initializers' |
5 | import { createUserAccountAndChannel } from '../../lib' | 5 | import { createUserAccountAndChannel } from '../../lib' |
6 | import { | 6 | import { |
7 | asyncMiddleware, | 7 | asyncMiddleware, |
@@ -11,6 +11,7 @@ import { | |||
11 | paginationValidator, | 11 | paginationValidator, |
12 | setPagination, | 12 | setPagination, |
13 | setUsersSort, | 13 | setUsersSort, |
14 | setVideosSort, | ||
14 | token, | 15 | token, |
15 | usersAddValidator, | 16 | usersAddValidator, |
16 | usersGetValidator, | 17 | usersGetValidator, |
@@ -21,9 +22,10 @@ import { | |||
21 | usersUpdateValidator, | 22 | usersUpdateValidator, |
22 | usersVideoRatingValidator | 23 | usersVideoRatingValidator |
23 | } from '../../middlewares' | 24 | } from '../../middlewares' |
24 | import { setVideosSort } from '../../middlewares/sort' | 25 | import { videosSortValidator } from '../../middlewares/validators' |
25 | import { videosSortValidator } from '../../middlewares/validators/sort' | 26 | import { AccountVideoRateModel } from '../../models/account/account-video-rate' |
26 | import { UserInstance } from '../../models' | 27 | import { UserModel } from '../../models/account/user' |
28 | import { VideoModel } from '../../models/video/video' | ||
27 | 29 | ||
28 | const usersRouter = express.Router() | 30 | const usersRouter = express.Router() |
29 | 31 | ||
@@ -107,8 +109,8 @@ export { | |||
107 | // --------------------------------------------------------------------------- | 109 | // --------------------------------------------------------------------------- |
108 | 110 | ||
109 | async function getUserVideos (req: express.Request, res: express.Response, next: express.NextFunction) { | 111 | async function getUserVideos (req: express.Request, res: express.Response, next: express.NextFunction) { |
110 | const user = res.locals.oauth.token.User | 112 | const user = res.locals.oauth.token.User as UserModel |
111 | const resultList = await db.Video.listUserVideosForApi(user.id ,req.query.start, req.query.count, req.query.sort) | 113 | const resultList = await VideoModel.listUserVideosForApi(user.id ,req.query.start, req.query.count, req.query.sort) |
112 | 114 | ||
113 | return res.json(getFormattedObjects(resultList.data, resultList.total)) | 115 | return res.json(getFormattedObjects(resultList.data, resultList.total)) |
114 | } | 116 | } |
@@ -127,7 +129,7 @@ async function createUserRetryWrapper (req: express.Request, res: express.Respon | |||
127 | 129 | ||
128 | async function createUser (req: express.Request) { | 130 | async function createUser (req: express.Request) { |
129 | const body: UserCreate = req.body | 131 | const body: UserCreate = req.body |
130 | const user = db.User.build({ | 132 | const user = new UserModel({ |
131 | username: body.username, | 133 | username: body.username, |
132 | password: body.password, | 134 | password: body.password, |
133 | email: body.email, | 135 | email: body.email, |
@@ -155,7 +157,7 @@ async function registerUserRetryWrapper (req: express.Request, res: express.Resp | |||
155 | async function registerUser (req: express.Request) { | 157 | async function registerUser (req: express.Request) { |
156 | const body: UserCreate = req.body | 158 | const body: UserCreate = req.body |
157 | 159 | ||
158 | const user = db.User.build({ | 160 | const user = new UserModel({ |
159 | username: body.username, | 161 | username: body.username, |
160 | password: body.password, | 162 | password: body.password, |
161 | email: body.email, | 163 | email: body.email, |
@@ -171,7 +173,7 @@ async function registerUser (req: express.Request) { | |||
171 | 173 | ||
172 | async function getUserInformation (req: express.Request, res: express.Response, next: express.NextFunction) { | 174 | async function getUserInformation (req: express.Request, res: express.Response, next: express.NextFunction) { |
173 | // We did not load channels in res.locals.user | 175 | // We did not load channels in res.locals.user |
174 | const user = await db.User.loadByUsernameAndPopulateChannels(res.locals.oauth.token.user.username) | 176 | const user = await UserModel.loadByUsernameAndPopulateChannels(res.locals.oauth.token.user.username) |
175 | 177 | ||
176 | return res.json(user.toFormattedJSON()) | 178 | return res.json(user.toFormattedJSON()) |
177 | } | 179 | } |
@@ -184,7 +186,7 @@ async function getUserVideoRating (req: express.Request, res: express.Response, | |||
184 | const videoId = +req.params.videoId | 186 | const videoId = +req.params.videoId |
185 | const accountId = +res.locals.oauth.token.User.Account.id | 187 | const accountId = +res.locals.oauth.token.User.Account.id |
186 | 188 | ||
187 | const ratingObj = await db.AccountVideoRate.load(accountId, videoId, null) | 189 | const ratingObj = await AccountVideoRateModel.load(accountId, videoId, null) |
188 | const rating = ratingObj ? ratingObj.type : 'none' | 190 | const rating = ratingObj ? ratingObj.type : 'none' |
189 | 191 | ||
190 | const json: FormattedUserVideoRate = { | 192 | const json: FormattedUserVideoRate = { |
@@ -195,13 +197,13 @@ async function getUserVideoRating (req: express.Request, res: express.Response, | |||
195 | } | 197 | } |
196 | 198 | ||
197 | async function listUsers (req: express.Request, res: express.Response, next: express.NextFunction) { | 199 | async function listUsers (req: express.Request, res: express.Response, next: express.NextFunction) { |
198 | const resultList = await db.User.listForApi(req.query.start, req.query.count, req.query.sort) | 200 | const resultList = await UserModel.listForApi(req.query.start, req.query.count, req.query.sort) |
199 | 201 | ||
200 | return res.json(getFormattedObjects(resultList.data, resultList.total)) | 202 | return res.json(getFormattedObjects(resultList.data, resultList.total)) |
201 | } | 203 | } |
202 | 204 | ||
203 | async function removeUser (req: express.Request, res: express.Response, next: express.NextFunction) { | 205 | async function removeUser (req: express.Request, res: express.Response, next: express.NextFunction) { |
204 | const user = await db.User.loadById(req.params.id) | 206 | const user = await UserModel.loadById(req.params.id) |
205 | 207 | ||
206 | await user.destroy() | 208 | await user.destroy() |
207 | 209 | ||
@@ -225,7 +227,7 @@ async function updateMe (req: express.Request, res: express.Response, next: expr | |||
225 | 227 | ||
226 | async function updateUser (req: express.Request, res: express.Response, next: express.NextFunction) { | 228 | async function updateUser (req: express.Request, res: express.Response, next: express.NextFunction) { |
227 | const body: UserUpdate = req.body | 229 | const body: UserUpdate = req.body |
228 | const user: UserInstance = res.locals.user | 230 | const user = res.locals.user as UserModel |
229 | 231 | ||
230 | if (body.email !== undefined) user.email = body.email | 232 | if (body.email !== undefined) user.email = body.email |
231 | if (body.videoQuota !== undefined) user.videoQuota = body.videoQuota | 233 | if (body.videoQuota !== undefined) user.videoQuota = body.videoQuota |
diff --git a/server/controllers/api/videos/abuse.ts b/server/controllers/api/videos/abuse.ts index 29e1175c5..08cc4d0b4 100644 --- a/server/controllers/api/videos/abuse.ts +++ b/server/controllers/api/videos/abuse.ts | |||
@@ -1,11 +1,10 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | |||
3 | import { database as db } from '../../../initializers/database' | ||
4 | import { | 2 | import { |
5 | logger, | 3 | logger, |
6 | getFormattedObjects, | 4 | getFormattedObjects, |
7 | retryTransactionWrapper | 5 | retryTransactionWrapper |
8 | } from '../../../helpers' | 6 | } from '../../../helpers' |
7 | import { sequelizeTypescript } from '../../../initializers' | ||
9 | import { | 8 | import { |
10 | authenticate, | 9 | authenticate, |
11 | ensureUserHasRight, | 10 | ensureUserHasRight, |
@@ -16,9 +15,11 @@ import { | |||
16 | setPagination, | 15 | setPagination, |
17 | asyncMiddleware | 16 | asyncMiddleware |
18 | } from '../../../middlewares' | 17 | } from '../../../middlewares' |
19 | import { VideoInstance } from '../../../models' | ||
20 | import { VideoAbuseCreate, UserRight } from '../../../../shared' | 18 | import { VideoAbuseCreate, UserRight } from '../../../../shared' |
21 | import { sendVideoAbuse } from '../../../lib/index' | 19 | import { sendVideoAbuse } from '../../../lib/index' |
20 | import { AccountModel } from '../../../models/account/account' | ||
21 | import { VideoModel } from '../../../models/video/video' | ||
22 | import { VideoAbuseModel } from '../../../models/video/video-abuse' | ||
22 | 23 | ||
23 | const abuseVideoRouter = express.Router() | 24 | const abuseVideoRouter = express.Router() |
24 | 25 | ||
@@ -46,7 +47,7 @@ export { | |||
46 | // --------------------------------------------------------------------------- | 47 | // --------------------------------------------------------------------------- |
47 | 48 | ||
48 | async function listVideoAbuses (req: express.Request, res: express.Response, next: express.NextFunction) { | 49 | async function listVideoAbuses (req: express.Request, res: express.Response, next: express.NextFunction) { |
49 | const resultList = await db.VideoAbuse.listForApi(req.query.start, req.query.count, req.query.sort) | 50 | const resultList = await VideoAbuseModel.listForApi(req.query.start, req.query.count, req.query.sort) |
50 | 51 | ||
51 | return res.json(getFormattedObjects(resultList.data, resultList.total)) | 52 | return res.json(getFormattedObjects(resultList.data, resultList.total)) |
52 | } | 53 | } |
@@ -63,8 +64,8 @@ async function reportVideoAbuseRetryWrapper (req: express.Request, res: express. | |||
63 | } | 64 | } |
64 | 65 | ||
65 | async function reportVideoAbuse (req: express.Request, res: express.Response) { | 66 | async function reportVideoAbuse (req: express.Request, res: express.Response) { |
66 | const videoInstance = res.locals.video as VideoInstance | 67 | const videoInstance = res.locals.video as VideoModel |
67 | const reporterAccount = res.locals.oauth.token.User.Account | 68 | const reporterAccount = res.locals.oauth.token.User.Account as AccountModel |
68 | const body: VideoAbuseCreate = req.body | 69 | const body: VideoAbuseCreate = req.body |
69 | 70 | ||
70 | const abuseToCreate = { | 71 | const abuseToCreate = { |
@@ -73,8 +74,8 @@ async function reportVideoAbuse (req: express.Request, res: express.Response) { | |||
73 | videoId: videoInstance.id | 74 | videoId: videoInstance.id |
74 | } | 75 | } |
75 | 76 | ||
76 | await db.sequelize.transaction(async t => { | 77 | await sequelizeTypescript.transaction(async t => { |
77 | const videoAbuseInstance = await db.VideoAbuse.create(abuseToCreate, { transaction: t }) | 78 | const videoAbuseInstance = await VideoAbuseModel.create(abuseToCreate, { transaction: t }) |
78 | videoAbuseInstance.Video = videoInstance | 79 | videoAbuseInstance.Video = videoInstance |
79 | 80 | ||
80 | // We send the video abuse to the origin server | 81 | // We send the video abuse to the origin server |
diff --git a/server/controllers/api/videos/blacklist.ts b/server/controllers/api/videos/blacklist.ts index 06333c271..d08c6e13f 100644 --- a/server/controllers/api/videos/blacklist.ts +++ b/server/controllers/api/videos/blacklist.ts | |||
@@ -1,6 +1,4 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | |||
3 | import { database as db } from '../../../initializers' | ||
4 | import { logger, getFormattedObjects } from '../../../helpers' | 2 | import { logger, getFormattedObjects } from '../../../helpers' |
5 | import { | 3 | import { |
6 | authenticate, | 4 | authenticate, |
@@ -13,8 +11,8 @@ import { | |||
13 | setPagination, | 11 | setPagination, |
14 | asyncMiddleware | 12 | asyncMiddleware |
15 | } from '../../../middlewares' | 13 | } from '../../../middlewares' |
16 | import { BlacklistedVideoInstance } from '../../../models' | ||
17 | import { BlacklistedVideo, UserRight } from '../../../../shared' | 14 | import { BlacklistedVideo, UserRight } from '../../../../shared' |
15 | import { VideoBlacklistModel } from '../../../models/video/video-blacklist' | ||
18 | 16 | ||
19 | const blacklistRouter = express.Router() | 17 | const blacklistRouter = express.Router() |
20 | 18 | ||
@@ -57,18 +55,18 @@ async function addVideoToBlacklist (req: express.Request, res: express.Response, | |||
57 | videoId: videoInstance.id | 55 | videoId: videoInstance.id |
58 | } | 56 | } |
59 | 57 | ||
60 | await db.BlacklistedVideo.create(toCreate) | 58 | await VideoBlacklistModel.create(toCreate) |
61 | return res.type('json').status(204).end() | 59 | return res.type('json').status(204).end() |
62 | } | 60 | } |
63 | 61 | ||
64 | async function listBlacklist (req: express.Request, res: express.Response, next: express.NextFunction) { | 62 | async function listBlacklist (req: express.Request, res: express.Response, next: express.NextFunction) { |
65 | const resultList = await db.BlacklistedVideo.listForApi(req.query.start, req.query.count, req.query.sort) | 63 | const resultList = await VideoBlacklistModel.listForApi(req.query.start, req.query.count, req.query.sort) |
66 | 64 | ||
67 | return res.json(getFormattedObjects<BlacklistedVideo, BlacklistedVideoInstance>(resultList.data, resultList.total)) | 65 | return res.json(getFormattedObjects<BlacklistedVideo, VideoBlacklistModel>(resultList.data, resultList.total)) |
68 | } | 66 | } |
69 | 67 | ||
70 | async function removeVideoFromBlacklistController (req: express.Request, res: express.Response, next: express.NextFunction) { | 68 | async function removeVideoFromBlacklistController (req: express.Request, res: express.Response, next: express.NextFunction) { |
71 | const blacklistedVideo = res.locals.blacklistedVideo as BlacklistedVideoInstance | 69 | const blacklistedVideo = res.locals.blacklistedVideo as VideoBlacklistModel |
72 | 70 | ||
73 | try { | 71 | try { |
74 | await blacklistedVideo.destroy() | 72 | await blacklistedVideo.destroy() |
diff --git a/server/controllers/api/videos/channel.ts b/server/controllers/api/videos/channel.ts index d99f47c32..683b0448d 100644 --- a/server/controllers/api/videos/channel.ts +++ b/server/controllers/api/videos/channel.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { VideoChannelCreate, VideoChannelUpdate } from '../../../../shared' | 2 | import { VideoChannelCreate, VideoChannelUpdate } from '../../../../shared' |
3 | import { getFormattedObjects, logger, resetSequelizeInstance, retryTransactionWrapper } from '../../../helpers' | 3 | import { getFormattedObjects, logger, resetSequelizeInstance, retryTransactionWrapper } from '../../../helpers' |
4 | import { database as db } from '../../../initializers' | 4 | import { sequelizeTypescript } from '../../../initializers' |
5 | import { createVideoChannel } from '../../../lib' | 5 | import { createVideoChannel } from '../../../lib' |
6 | import { sendUpdateVideoChannel } from '../../../lib/activitypub/send/send-update' | 6 | import { sendUpdateVideoChannel } from '../../../lib/activitypub/send/send-update' |
7 | import { | 7 | import { |
@@ -17,7 +17,8 @@ import { | |||
17 | videoChannelsSortValidator, | 17 | videoChannelsSortValidator, |
18 | videoChannelsUpdateValidator | 18 | videoChannelsUpdateValidator |
19 | } from '../../../middlewares' | 19 | } from '../../../middlewares' |
20 | import { AccountInstance, VideoChannelInstance } from '../../../models' | 20 | import { AccountModel } from '../../../models/account/account' |
21 | import { VideoChannelModel } from '../../../models/video/video-channel' | ||
21 | 22 | ||
22 | const videoChannelRouter = express.Router() | 23 | const videoChannelRouter = express.Router() |
23 | 24 | ||
@@ -66,13 +67,13 @@ export { | |||
66 | // --------------------------------------------------------------------------- | 67 | // --------------------------------------------------------------------------- |
67 | 68 | ||
68 | async function listVideoChannels (req: express.Request, res: express.Response, next: express.NextFunction) { | 69 | async function listVideoChannels (req: express.Request, res: express.Response, next: express.NextFunction) { |
69 | const resultList = await db.VideoChannel.listForApi(req.query.start, req.query.count, req.query.sort) | 70 | const resultList = await VideoChannelModel.listForApi(req.query.start, req.query.count, req.query.sort) |
70 | 71 | ||
71 | return res.json(getFormattedObjects(resultList.data, resultList.total)) | 72 | return res.json(getFormattedObjects(resultList.data, resultList.total)) |
72 | } | 73 | } |
73 | 74 | ||
74 | async function listVideoAccountChannels (req: express.Request, res: express.Response, next: express.NextFunction) { | 75 | async function listVideoAccountChannels (req: express.Request, res: express.Response, next: express.NextFunction) { |
75 | const resultList = await db.VideoChannel.listByAccount(res.locals.account.id) | 76 | const resultList = await VideoChannelModel.listByAccount(res.locals.account.id) |
76 | 77 | ||
77 | return res.json(getFormattedObjects(resultList.data, resultList.total)) | 78 | return res.json(getFormattedObjects(resultList.data, resultList.total)) |
78 | } | 79 | } |
@@ -93,10 +94,10 @@ async function addVideoChannelRetryWrapper (req: express.Request, res: express.R | |||
93 | 94 | ||
94 | async function addVideoChannel (req: express.Request, res: express.Response) { | 95 | async function addVideoChannel (req: express.Request, res: express.Response) { |
95 | const videoChannelInfo: VideoChannelCreate = req.body | 96 | const videoChannelInfo: VideoChannelCreate = req.body |
96 | const account: AccountInstance = res.locals.oauth.token.User.Account | 97 | const account: AccountModel = res.locals.oauth.token.User.Account |
97 | let videoChannelCreated: VideoChannelInstance | 98 | let videoChannelCreated: VideoChannelModel |
98 | 99 | ||
99 | await db.sequelize.transaction(async t => { | 100 | await sequelizeTypescript.transaction(async t => { |
100 | videoChannelCreated = await createVideoChannel(videoChannelInfo, account, t) | 101 | videoChannelCreated = await createVideoChannel(videoChannelInfo, account, t) |
101 | }) | 102 | }) |
102 | 103 | ||
@@ -115,12 +116,12 @@ async function updateVideoChannelRetryWrapper (req: express.Request, res: expres | |||
115 | } | 116 | } |
116 | 117 | ||
117 | async function updateVideoChannel (req: express.Request, res: express.Response) { | 118 | async function updateVideoChannel (req: express.Request, res: express.Response) { |
118 | const videoChannelInstance: VideoChannelInstance = res.locals.videoChannel | 119 | const videoChannelInstance = res.locals.videoChannel as VideoChannelModel |
119 | const videoChannelFieldsSave = videoChannelInstance.toJSON() | 120 | const videoChannelFieldsSave = videoChannelInstance.toJSON() |
120 | const videoChannelInfoToUpdate: VideoChannelUpdate = req.body | 121 | const videoChannelInfoToUpdate = req.body as VideoChannelUpdate |
121 | 122 | ||
122 | try { | 123 | try { |
123 | await db.sequelize.transaction(async t => { | 124 | await sequelizeTypescript.transaction(async t => { |
124 | const sequelizeOptions = { | 125 | const sequelizeOptions = { |
125 | transaction: t | 126 | transaction: t |
126 | } | 127 | } |
@@ -158,9 +159,9 @@ async function removeVideoChannelRetryWrapper (req: express.Request, res: expres | |||
158 | } | 159 | } |
159 | 160 | ||
160 | async function removeVideoChannel (req: express.Request, res: express.Response) { | 161 | async function removeVideoChannel (req: express.Request, res: express.Response) { |
161 | const videoChannelInstance: VideoChannelInstance = res.locals.videoChannel | 162 | const videoChannelInstance: VideoChannelModel = res.locals.videoChannel |
162 | 163 | ||
163 | await db.sequelize.transaction(async t => { | 164 | await sequelizeTypescript.transaction(async t => { |
164 | await videoChannelInstance.destroy({ transaction: t }) | 165 | await videoChannelInstance.destroy({ transaction: t }) |
165 | }) | 166 | }) |
166 | 167 | ||
@@ -168,7 +169,7 @@ async function removeVideoChannel (req: express.Request, res: express.Response) | |||
168 | } | 169 | } |
169 | 170 | ||
170 | async function getVideoChannel (req: express.Request, res: express.Response, next: express.NextFunction) { | 171 | async function getVideoChannel (req: express.Request, res: express.Response, next: express.NextFunction) { |
171 | const videoChannelWithVideos = await db.VideoChannel.loadAndPopulateAccountAndVideos(res.locals.videoChannel.id) | 172 | const videoChannelWithVideos = await VideoChannelModel.loadAndPopulateAccountAndVideos(res.locals.videoChannel.id) |
172 | 173 | ||
173 | return res.json(videoChannelWithVideos.toFormattedJSON()) | 174 | return res.json(videoChannelWithVideos.toFormattedJSON()) |
174 | } | 175 | } |
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index 63de662a7..91ab8c66a 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts | |||
@@ -12,16 +12,19 @@ import { | |||
12 | retryTransactionWrapper | 12 | retryTransactionWrapper |
13 | } from '../../../helpers' | 13 | } from '../../../helpers' |
14 | import { getServerAccount } from '../../../helpers/utils' | 14 | import { getServerAccount } from '../../../helpers/utils' |
15 | import { CONFIG, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_MIMETYPE_EXT, VIDEO_PRIVACIES } from '../../../initializers' | 15 | import { |
16 | import { database as db } from '../../../initializers/database' | 16 | CONFIG, |
17 | import { sendAddVideo } from '../../../lib/activitypub/send/send-add' | 17 | sequelizeTypescript, |
18 | import { sendCreateViewToOrigin } from '../../../lib/activitypub/send/send-create' | 18 | VIDEO_CATEGORIES, |
19 | import { sendUpdateVideo } from '../../../lib/activitypub/send/send-update' | 19 | VIDEO_LANGUAGES, |
20 | import { shareVideoByServer } from '../../../lib/activitypub/share' | 20 | VIDEO_LICENCES, |
21 | import { getVideoActivityPubUrl } from '../../../lib/activitypub/url' | 21 | VIDEO_MIMETYPE_EXT, |
22 | import { fetchRemoteVideoDescription } from '../../../lib/activitypub/videos' | 22 | VIDEO_PRIVACIES |
23 | } from '../../../initializers' | ||
24 | import { fetchRemoteVideoDescription, getVideoActivityPubUrl, shareVideoByServer } from '../../../lib/activitypub' | ||
25 | import { sendAddVideo, sendCreateViewToOrigin, sendUpdateVideo } from '../../../lib/activitypub/send' | ||
23 | import { sendCreateViewToVideoFollowers } from '../../../lib/index' | 26 | import { sendCreateViewToVideoFollowers } from '../../../lib/index' |
24 | import { transcodingJobScheduler } from '../../../lib/jobs/transcoding-job-scheduler/transcoding-job-scheduler' | 27 | import { transcodingJobScheduler } from '../../../lib/jobs/transcoding-job-scheduler' |
25 | import { | 28 | import { |
26 | asyncMiddleware, | 29 | asyncMiddleware, |
27 | authenticate, | 30 | authenticate, |
@@ -35,7 +38,9 @@ import { | |||
35 | videosSortValidator, | 38 | videosSortValidator, |
36 | videosUpdateValidator | 39 | videosUpdateValidator |
37 | } from '../../../middlewares' | 40 | } from '../../../middlewares' |
38 | import { VideoInstance } from '../../../models' | 41 | import { TagModel } from '../../../models/video/tag' |
42 | import { VideoModel } from '../../../models/video/video' | ||
43 | import { VideoFileModel } from '../../../models/video/video-file' | ||
39 | import { abuseVideoRouter } from './abuse' | 44 | import { abuseVideoRouter } from './abuse' |
40 | import { blacklistRouter } from './blacklist' | 45 | import { blacklistRouter } from './blacklist' |
41 | import { videoChannelRouter } from './channel' | 46 | import { videoChannelRouter } from './channel' |
@@ -99,7 +104,7 @@ videosRouter.put('/:id', | |||
99 | videosRouter.post('/upload', | 104 | videosRouter.post('/upload', |
100 | authenticate, | 105 | authenticate, |
101 | reqFiles, | 106 | reqFiles, |
102 | videosAddValidator, | 107 | asyncMiddleware(videosAddValidator), |
103 | asyncMiddleware(addVideoRetryWrapper) | 108 | asyncMiddleware(addVideoRetryWrapper) |
104 | ) | 109 | ) |
105 | 110 | ||
@@ -181,7 +186,7 @@ async function addVideo (req: express.Request, res: express.Response, videoPhysi | |||
181 | duration: videoPhysicalFile['duration'], // duration was added by a previous middleware | 186 | duration: videoPhysicalFile['duration'], // duration was added by a previous middleware |
182 | channelId: res.locals.videoChannel.id | 187 | channelId: res.locals.videoChannel.id |
183 | } | 188 | } |
184 | const video = db.Video.build(videoData) | 189 | const video = new VideoModel(videoData) |
185 | video.url = getVideoActivityPubUrl(video) | 190 | video.url = getVideoActivityPubUrl(video) |
186 | 191 | ||
187 | const videoFilePath = join(CONFIG.STORAGE.VIDEOS_DIR, videoPhysicalFile.filename) | 192 | const videoFilePath = join(CONFIG.STORAGE.VIDEOS_DIR, videoPhysicalFile.filename) |
@@ -192,7 +197,7 @@ async function addVideo (req: express.Request, res: express.Response, videoPhysi | |||
192 | resolution: videoFileHeight, | 197 | resolution: videoFileHeight, |
193 | size: videoPhysicalFile.size | 198 | size: videoPhysicalFile.size |
194 | } | 199 | } |
195 | const videoFile = db.VideoFile.build(videoFileData) | 200 | const videoFile = new VideoFileModel(videoFileData) |
196 | const videoDir = CONFIG.STORAGE.VIDEOS_DIR | 201 | const videoDir = CONFIG.STORAGE.VIDEOS_DIR |
197 | const source = join(videoDir, videoPhysicalFile.filename) | 202 | const source = join(videoDir, videoPhysicalFile.filename) |
198 | const destination = join(videoDir, video.getVideoFilename(videoFile)) | 203 | const destination = join(videoDir, video.getVideoFilename(videoFile)) |
@@ -210,7 +215,7 @@ async function addVideo (req: express.Request, res: express.Response, videoPhysi | |||
210 | ) | 215 | ) |
211 | await Promise.all(tasks) | 216 | await Promise.all(tasks) |
212 | 217 | ||
213 | return db.sequelize.transaction(async t => { | 218 | return sequelizeTypescript.transaction(async t => { |
214 | const sequelizeOptions = { transaction: t } | 219 | const sequelizeOptions = { transaction: t } |
215 | 220 | ||
216 | if (CONFIG.TRANSCODING.ENABLED === true) { | 221 | if (CONFIG.TRANSCODING.ENABLED === true) { |
@@ -232,9 +237,9 @@ async function addVideo (req: express.Request, res: express.Response, videoPhysi | |||
232 | video.VideoFiles = [ videoFile ] | 237 | video.VideoFiles = [ videoFile ] |
233 | 238 | ||
234 | if (videoInfo.tags) { | 239 | if (videoInfo.tags) { |
235 | const tagInstances = await db.Tag.findOrCreateTags(videoInfo.tags, t) | 240 | const tagInstances = await TagModel.findOrCreateTags(videoInfo.tags, t) |
236 | 241 | ||
237 | await video.setTags(tagInstances, sequelizeOptions) | 242 | await video.$set('Tags', tagInstances, sequelizeOptions) |
238 | video.Tags = tagInstances | 243 | video.Tags = tagInstances |
239 | } | 244 | } |
240 | 245 | ||
@@ -264,13 +269,13 @@ async function updateVideoRetryWrapper (req: express.Request, res: express.Respo | |||
264 | } | 269 | } |
265 | 270 | ||
266 | async function updateVideo (req: express.Request, res: express.Response) { | 271 | async function updateVideo (req: express.Request, res: express.Response) { |
267 | const videoInstance: VideoInstance = res.locals.video | 272 | const videoInstance: VideoModel = res.locals.video |
268 | const videoFieldsSave = videoInstance.toJSON() | 273 | const videoFieldsSave = videoInstance.toJSON() |
269 | const videoInfoToUpdate: VideoUpdate = req.body | 274 | const videoInfoToUpdate: VideoUpdate = req.body |
270 | const wasPrivateVideo = videoInstance.privacy === VideoPrivacy.PRIVATE | 275 | const wasPrivateVideo = videoInstance.privacy === VideoPrivacy.PRIVATE |
271 | 276 | ||
272 | try { | 277 | try { |
273 | await db.sequelize.transaction(async t => { | 278 | await sequelizeTypescript.transaction(async t => { |
274 | const sequelizeOptions = { | 279 | const sequelizeOptions = { |
275 | transaction: t | 280 | transaction: t |
276 | } | 281 | } |
@@ -286,9 +291,9 @@ async function updateVideo (req: express.Request, res: express.Response) { | |||
286 | const videoInstanceUpdated = await videoInstance.save(sequelizeOptions) | 291 | const videoInstanceUpdated = await videoInstance.save(sequelizeOptions) |
287 | 292 | ||
288 | if (videoInfoToUpdate.tags) { | 293 | if (videoInfoToUpdate.tags) { |
289 | const tagInstances = await db.Tag.findOrCreateTags(videoInfoToUpdate.tags, t) | 294 | const tagInstances = await TagModel.findOrCreateTags(videoInfoToUpdate.tags, t) |
290 | 295 | ||
291 | await videoInstance.setTags(tagInstances, sequelizeOptions) | 296 | await videoInstance.$set('Tags', tagInstances, sequelizeOptions) |
292 | videoInstance.Tags = tagInstances | 297 | videoInstance.Tags = tagInstances |
293 | } | 298 | } |
294 | 299 | ||
@@ -350,7 +355,7 @@ async function getVideoDescription (req: express.Request, res: express.Response) | |||
350 | } | 355 | } |
351 | 356 | ||
352 | async function listVideos (req: express.Request, res: express.Response, next: express.NextFunction) { | 357 | async function listVideos (req: express.Request, res: express.Response, next: express.NextFunction) { |
353 | const resultList = await db.Video.listForApi(req.query.start, req.query.count, req.query.sort) | 358 | const resultList = await VideoModel.listForApi(req.query.start, req.query.count, req.query.sort) |
354 | 359 | ||
355 | return res.json(getFormattedObjects(resultList.data, resultList.total)) | 360 | return res.json(getFormattedObjects(resultList.data, resultList.total)) |
356 | } | 361 | } |
@@ -367,9 +372,9 @@ async function removeVideoRetryWrapper (req: express.Request, res: express.Respo | |||
367 | } | 372 | } |
368 | 373 | ||
369 | async function removeVideo (req: express.Request, res: express.Response) { | 374 | async function removeVideo (req: express.Request, res: express.Response) { |
370 | const videoInstance: VideoInstance = res.locals.video | 375 | const videoInstance: VideoModel = res.locals.video |
371 | 376 | ||
372 | await db.sequelize.transaction(async t => { | 377 | await sequelizeTypescript.transaction(async t => { |
373 | await videoInstance.destroy({ transaction: t }) | 378 | await videoInstance.destroy({ transaction: t }) |
374 | }) | 379 | }) |
375 | 380 | ||
@@ -377,7 +382,7 @@ async function removeVideo (req: express.Request, res: express.Response) { | |||
377 | } | 382 | } |
378 | 383 | ||
379 | async function searchVideos (req: express.Request, res: express.Response, next: express.NextFunction) { | 384 | async function searchVideos (req: express.Request, res: express.Response, next: express.NextFunction) { |
380 | const resultList = await db.Video.searchAndPopulateAccountAndServerAndTags( | 385 | const resultList = await VideoModel.searchAndPopulateAccountAndServerAndTags( |
381 | req.query.search, | 386 | req.query.search, |
382 | req.query.start, | 387 | req.query.start, |
383 | req.query.count, | 388 | req.query.count, |
diff --git a/server/controllers/api/videos/rate.ts b/server/controllers/api/videos/rate.ts index c27c61116..48b744b0c 100644 --- a/server/controllers/api/videos/rate.ts +++ b/server/controllers/api/videos/rate.ts | |||
@@ -1,12 +1,12 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { UserVideoRateUpdate } from '../../../../shared' | 2 | import { UserVideoRateUpdate } from '../../../../shared' |
3 | import { logger, retryTransactionWrapper } from '../../../helpers' | 3 | import { logger, retryTransactionWrapper } from '../../../helpers' |
4 | import { VIDEO_RATE_TYPES } from '../../../initializers' | 4 | import { sequelizeTypescript, VIDEO_RATE_TYPES } from '../../../initializers' |
5 | import { database as db } from '../../../initializers/database' | 5 | import { sendVideoRateChangeToFollowers, sendVideoRateChangeToOrigin } from '../../../lib/activitypub' |
6 | import { sendVideoRateChangeToFollowers, sendVideoRateChangeToOrigin } from '../../../lib/activitypub/videos' | ||
7 | import { asyncMiddleware, authenticate, videoRateValidator } from '../../../middlewares' | 6 | import { asyncMiddleware, authenticate, videoRateValidator } from '../../../middlewares' |
8 | import { AccountInstance } from '../../../models/account/account-interface' | 7 | import { AccountModel } from '../../../models/account/account' |
9 | import { VideoInstance } from '../../../models/video/video-interface' | 8 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' |
9 | import { VideoModel } from '../../../models/video/video' | ||
10 | 10 | ||
11 | const rateVideoRouter = express.Router() | 11 | const rateVideoRouter = express.Router() |
12 | 12 | ||
@@ -38,12 +38,12 @@ async function rateVideoRetryWrapper (req: express.Request, res: express.Respons | |||
38 | async function rateVideo (req: express.Request, res: express.Response) { | 38 | async function rateVideo (req: express.Request, res: express.Response) { |
39 | const body: UserVideoRateUpdate = req.body | 39 | const body: UserVideoRateUpdate = req.body |
40 | const rateType = body.rating | 40 | const rateType = body.rating |
41 | const videoInstance: VideoInstance = res.locals.video | 41 | const videoInstance: VideoModel = res.locals.video |
42 | const accountInstance: AccountInstance = res.locals.oauth.token.User.Account | 42 | const accountInstance: AccountModel = res.locals.oauth.token.User.Account |
43 | 43 | ||
44 | await db.sequelize.transaction(async t => { | 44 | await sequelizeTypescript.transaction(async t => { |
45 | const sequelizeOptions = { transaction: t } | 45 | const sequelizeOptions = { transaction: t } |
46 | const previousRate = await db.AccountVideoRate.load(accountInstance.id, videoInstance.id, t) | 46 | const previousRate = await AccountVideoRateModel.load(accountInstance.id, videoInstance.id, t) |
47 | 47 | ||
48 | let likesToIncrement = 0 | 48 | let likesToIncrement = 0 |
49 | let dislikesToIncrement = 0 | 49 | let dislikesToIncrement = 0 |
@@ -71,7 +71,7 @@ async function rateVideo (req: express.Request, res: express.Response) { | |||
71 | type: rateType | 71 | type: rateType |
72 | } | 72 | } |
73 | 73 | ||
74 | await db.AccountVideoRate.create(query, sequelizeOptions) | 74 | await AccountVideoRateModel.create(query, sequelizeOptions) |
75 | } | 75 | } |
76 | 76 | ||
77 | const incrementQuery = { | 77 | const incrementQuery = { |
diff --git a/server/controllers/client.ts b/server/controllers/client.ts index 1b140b14a..9a72fe8e0 100644 --- a/server/controllers/client.ts +++ b/server/controllers/client.ts | |||
@@ -2,8 +2,6 @@ import * as express from 'express' | |||
2 | import { join } from 'path' | 2 | import { join } from 'path' |
3 | import * as validator from 'validator' | 3 | import * as validator from 'validator' |
4 | import * as Bluebird from 'bluebird' | 4 | import * as Bluebird from 'bluebird' |
5 | |||
6 | import { database as db } from '../initializers/database' | ||
7 | import { | 5 | import { |
8 | CONFIG, | 6 | CONFIG, |
9 | STATIC_PATHS, | 7 | STATIC_PATHS, |
@@ -13,7 +11,7 @@ import { | |||
13 | } from '../initializers' | 11 | } from '../initializers' |
14 | import { root, readFileBufferPromise, escapeHTML } from '../helpers' | 12 | import { root, readFileBufferPromise, escapeHTML } from '../helpers' |
15 | import { asyncMiddleware } from '../middlewares' | 13 | import { asyncMiddleware } from '../middlewares' |
16 | import { VideoInstance } from '../models' | 14 | import { VideoModel } from '../models/video/video' |
17 | 15 | ||
18 | const clientsRouter = express.Router() | 16 | const clientsRouter = express.Router() |
19 | 17 | ||
@@ -49,7 +47,7 @@ export { | |||
49 | 47 | ||
50 | // --------------------------------------------------------------------------- | 48 | // --------------------------------------------------------------------------- |
51 | 49 | ||
52 | function addOpenGraphAndOEmbedTags (htmlStringPage: string, video: VideoInstance) { | 50 | function addOpenGraphAndOEmbedTags (htmlStringPage: string, video: VideoModel) { |
53 | const previewUrl = CONFIG.WEBSERVER.URL + STATIC_PATHS.PREVIEWS + video.getPreviewName() | 51 | const previewUrl = CONFIG.WEBSERVER.URL + STATIC_PATHS.PREVIEWS + video.getPreviewName() |
54 | const videoUrl = CONFIG.WEBSERVER.URL + '/videos/watch/' + video.uuid | 52 | const videoUrl = CONFIG.WEBSERVER.URL + '/videos/watch/' + video.uuid |
55 | 53 | ||
@@ -108,13 +106,13 @@ function addOpenGraphAndOEmbedTags (htmlStringPage: string, video: VideoInstance | |||
108 | 106 | ||
109 | async function generateWatchHtmlPage (req: express.Request, res: express.Response, next: express.NextFunction) { | 107 | async function generateWatchHtmlPage (req: express.Request, res: express.Response, next: express.NextFunction) { |
110 | const videoId = '' + req.params.id | 108 | const videoId = '' + req.params.id |
111 | let videoPromise: Bluebird<VideoInstance> | 109 | let videoPromise: Bluebird<VideoModel> |
112 | 110 | ||
113 | // Let Angular application handle errors | 111 | // Let Angular application handle errors |
114 | if (validator.isUUID(videoId, 4)) { | 112 | if (validator.isUUID(videoId, 4)) { |
115 | videoPromise = db.Video.loadByUUIDAndPopulateAccountAndServerAndTags(videoId) | 113 | videoPromise = VideoModel.loadByUUIDAndPopulateAccountAndServerAndTags(videoId) |
116 | } else if (validator.isInt(videoId)) { | 114 | } else if (validator.isInt(videoId)) { |
117 | videoPromise = db.Video.loadAndPopulateAccountAndServerAndTags(+videoId) | 115 | videoPromise = VideoModel.loadAndPopulateAccountAndServerAndTags(+videoId) |
118 | } else { | 116 | } else { |
119 | return res.sendFile(indexPath) | 117 | return res.sendFile(indexPath) |
120 | } | 118 | } |
diff --git a/server/controllers/services.ts b/server/controllers/services.ts index 0c325678c..3ac78a5df 100644 --- a/server/controllers/services.ts +++ b/server/controllers/services.ts | |||
@@ -1,9 +1,7 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | |||
3 | import { CONFIG, EMBED_SIZE, PREVIEWS_SIZE } from '../initializers' | 2 | import { CONFIG, EMBED_SIZE, PREVIEWS_SIZE } from '../initializers' |
4 | import { oembedValidator } from '../middlewares' | 3 | import { asyncMiddleware, oembedValidator } from '../middlewares' |
5 | import { asyncMiddleware } from '../middlewares/async' | 4 | import { VideoModel } from '../models/video/video' |
6 | import { VideoInstance } from '../models' | ||
7 | 5 | ||
8 | const servicesRouter = express.Router() | 6 | const servicesRouter = express.Router() |
9 | 7 | ||
@@ -21,7 +19,7 @@ export { | |||
21 | // --------------------------------------------------------------------------- | 19 | // --------------------------------------------------------------------------- |
22 | 20 | ||
23 | function generateOEmbed (req: express.Request, res: express.Response, next: express.NextFunction) { | 21 | function generateOEmbed (req: express.Request, res: express.Response, next: express.NextFunction) { |
24 | const video = res.locals.video as VideoInstance | 22 | const video = res.locals.video as VideoModel |
25 | const webserverUrl = CONFIG.WEBSERVER.URL | 23 | const webserverUrl = CONFIG.WEBSERVER.URL |
26 | const maxHeight = parseInt(req.query.maxheight, 10) | 24 | const maxHeight = parseInt(req.query.maxheight, 10) |
27 | const maxWidth = parseInt(req.query.maxwidth, 10) | 25 | const maxWidth = parseInt(req.query.maxwidth, 10) |
diff --git a/server/controllers/static.ts b/server/controllers/static.ts index 7425fd097..33aed8927 100644 --- a/server/controllers/static.ts +++ b/server/controllers/static.ts | |||
@@ -1,6 +1,5 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import * as cors from 'cors' | 2 | import * as cors from 'cors' |
3 | |||
4 | import { | 3 | import { |
5 | CONFIG, | 4 | CONFIG, |
6 | STATIC_MAX_AGE, | 5 | STATIC_MAX_AGE, |
diff --git a/server/controllers/webfinger.ts b/server/controllers/webfinger.ts index 78e5dee79..bb2ea40fa 100644 --- a/server/controllers/webfinger.ts +++ b/server/controllers/webfinger.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { asyncMiddleware } from '../middlewares/async' | 2 | import { asyncMiddleware } from '../middlewares' |
3 | import { webfingerValidator } from '../middlewares/validators/webfinger' | 3 | import { webfingerValidator } from '../middlewares/validators' |
4 | import { AccountInstance } from '../models/account/account-interface' | 4 | import { AccountModel } from '../models/account/account' |
5 | 5 | ||
6 | const webfingerRouter = express.Router() | 6 | const webfingerRouter = express.Router() |
7 | 7 | ||
@@ -19,7 +19,7 @@ export { | |||
19 | // --------------------------------------------------------------------------- | 19 | // --------------------------------------------------------------------------- |
20 | 20 | ||
21 | function webfingerController (req: express.Request, res: express.Response, next: express.NextFunction) { | 21 | function webfingerController (req: express.Request, res: express.Response, next: express.NextFunction) { |
22 | const account: AccountInstance = res.locals.account | 22 | const account = res.locals.account as AccountModel |
23 | 23 | ||
24 | const json = { | 24 | const json = { |
25 | subject: req.query.resource, | 25 | subject: req.query.resource, |