diff options
author | Chocobozzz <me@florianbigard.com> | 2017-12-14 17:38:41 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2017-12-19 10:53:16 +0100 |
commit | 50d6de9c286abcb34ff4234d56d9cbb803db7665 (patch) | |
tree | f1732b27edcd05c7877a8358b8312f1e38c287ed /server/controllers | |
parent | fadf619ad61a016c1c7fc53de5a8f398a4f77519 (diff) | |
download | PeerTube-50d6de9c286abcb34ff4234d56d9cbb803db7665.tar.gz PeerTube-50d6de9c286abcb34ff4234d56d9cbb803db7665.tar.zst PeerTube-50d6de9c286abcb34ff4234d56d9cbb803db7665.zip |
Begin moving video channel to actor
Diffstat (limited to 'server/controllers')
-rw-r--r-- | server/controllers/activitypub/client.ts | 31 | ||||
-rw-r--r-- | server/controllers/activitypub/inbox.ts | 10 | ||||
-rw-r--r-- | server/controllers/activitypub/outbox.ts | 20 | ||||
-rw-r--r-- | server/controllers/api/server/follows.ts | 114 | ||||
-rw-r--r-- | server/controllers/api/users.ts | 2 | ||||
-rw-r--r-- | server/controllers/api/videos/abuse.ts | 20 | ||||
-rw-r--r-- | server/controllers/api/videos/channel.ts | 28 | ||||
-rw-r--r-- | server/controllers/api/videos/index.ts | 13 | ||||
-rw-r--r-- | server/controllers/static.ts | 10 | ||||
-rw-r--r-- | server/controllers/webfinger.ts | 8 |
10 files changed, 108 insertions, 148 deletions
diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.ts index 72b216254..8c6294ff7 100644 --- a/server/controllers/activitypub/client.ts +++ b/server/controllers/activitypub/client.ts | |||
@@ -2,20 +2,13 @@ | |||
2 | import * as express from 'express' | 2 | import * as express from 'express' |
3 | import { activityPubCollectionPagination, pageToStartAndCount } from '../../helpers' | 3 | import { activityPubCollectionPagination, pageToStartAndCount } from '../../helpers' |
4 | import { ACTIVITY_PUB, CONFIG } from '../../initializers' | 4 | import { ACTIVITY_PUB, CONFIG } from '../../initializers' |
5 | import { buildVideoChannelAnnounceToFollowers } from '../../lib/activitypub/send' | 5 | import { buildVideoAnnounceToFollowers } from '../../lib/activitypub/send' |
6 | import { buildVideoAnnounceToFollowers } from '../../lib/index' | ||
7 | import { asyncMiddleware, executeIfActivityPub, localAccountValidator } from '../../middlewares' | 6 | import { asyncMiddleware, executeIfActivityPub, localAccountValidator } from '../../middlewares' |
8 | import { | 7 | import { videoChannelsGetValidator, videosGetValidator, videosShareValidator } from '../../middlewares/validators' |
9 | videoChannelsGetValidator, | ||
10 | videoChannelsShareValidator, | ||
11 | videosGetValidator, | ||
12 | videosShareValidator | ||
13 | } from '../../middlewares/validators' | ||
14 | import { AccountModel } from '../../models/account/account' | 8 | import { AccountModel } from '../../models/account/account' |
15 | import { AccountFollowModel } from '../../models/account/account-follow' | 9 | import { ActorFollowModel } from '../../models/activitypub/actor-follow' |
16 | import { VideoModel } from '../../models/video/video' | 10 | import { VideoModel } from '../../models/video/video' |
17 | import { VideoChannelModel } from '../../models/video/video-channel' | 11 | import { VideoChannelModel } from '../../models/video/video-channel' |
18 | import { VideoChannelShareModel } from '../../models/video/video-channel-share' | ||
19 | import { VideoShareModel } from '../../models/video/video-share' | 12 | import { VideoShareModel } from '../../models/video/video-share' |
20 | 13 | ||
21 | const activityPubClientRouter = express.Router() | 14 | const activityPubClientRouter = express.Router() |
@@ -50,11 +43,6 @@ activityPubClientRouter.get('/video-channels/:id', | |||
50 | executeIfActivityPub(asyncMiddleware(videoChannelController)) | 43 | executeIfActivityPub(asyncMiddleware(videoChannelController)) |
51 | ) | 44 | ) |
52 | 45 | ||
53 | activityPubClientRouter.get('/video-channels/:id/announces/:accountId', | ||
54 | executeIfActivityPub(asyncMiddleware(videoChannelsShareValidator)), | ||
55 | executeIfActivityPub(asyncMiddleware(videoChannelAnnounceController)) | ||
56 | ) | ||
57 | |||
58 | // --------------------------------------------------------------------------- | 46 | // --------------------------------------------------------------------------- |
59 | 47 | ||
60 | export { | 48 | export { |
@@ -75,7 +63,7 @@ async function accountFollowersController (req: express.Request, res: express.Re | |||
75 | const page = req.query.page || 1 | 63 | const page = req.query.page || 1 |
76 | const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE) | 64 | const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE) |
77 | 65 | ||
78 | const result = await AccountFollowModel.listAcceptedFollowerUrlsForApi([ account.id ], undefined, start, count) | 66 | const result = await ActorFollowModel.listAcceptedFollowerUrlsForApi([ account.Actor.id ], undefined, start, count) |
79 | const activityPubResult = activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.url, page, result) | 67 | const activityPubResult = activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.url, page, result) |
80 | 68 | ||
81 | return res.json(activityPubResult) | 69 | return res.json(activityPubResult) |
@@ -87,7 +75,7 @@ async function accountFollowingController (req: express.Request, res: express.Re | |||
87 | const page = req.query.page || 1 | 75 | const page = req.query.page || 1 |
88 | const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE) | 76 | const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE) |
89 | 77 | ||
90 | const result = await AccountFollowModel.listAcceptedFollowingUrlsForApi([ account.id ], undefined, start, count) | 78 | const result = await ActorFollowModel.listAcceptedFollowingUrlsForApi([ account.Actor.id ], undefined, start, count) |
91 | const activityPubResult = activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.url, page, result) | 79 | const activityPubResult = activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.url, page, result) |
92 | 80 | ||
93 | return res.json(activityPubResult) | 81 | return res.json(activityPubResult) |
@@ -101,14 +89,7 @@ function videoController (req: express.Request, res: express.Response, next: exp | |||
101 | 89 | ||
102 | async function videoAnnounceController (req: express.Request, res: express.Response, next: express.NextFunction) { | 90 | async function videoAnnounceController (req: express.Request, res: express.Response, next: express.NextFunction) { |
103 | const share = res.locals.videoShare as VideoShareModel | 91 | const share = res.locals.videoShare as VideoShareModel |
104 | const object = await buildVideoAnnounceToFollowers(share.Account, res.locals.video, undefined) | 92 | const object = await buildVideoAnnounceToFollowers(share.Actor, res.locals.video, undefined) |
105 | |||
106 | return res.json(object) | ||
107 | } | ||
108 | |||
109 | async function videoChannelAnnounceController (req: express.Request, res: express.Response, next: express.NextFunction) { | ||
110 | const share = res.locals.videoChannelShare as VideoChannelShareModel | ||
111 | const object = await buildVideoChannelAnnounceToFollowers(share.Account, share.VideoChannel, undefined) | ||
112 | 93 | ||
113 | return res.json(object) | 94 | return res.json(object) |
114 | } | 95 | } |
diff --git a/server/controllers/activitypub/inbox.ts b/server/controllers/activitypub/inbox.ts index 88a0834f6..8332eabb1 100644 --- a/server/controllers/activitypub/inbox.ts +++ b/server/controllers/activitypub/inbox.ts | |||
@@ -5,6 +5,7 @@ import { isActivityValid } from '../../helpers/custom-validators/activitypub/act | |||
5 | import { processActivities } from '../../lib/activitypub/process/process' | 5 | import { processActivities } from '../../lib/activitypub/process/process' |
6 | import { asyncMiddleware, checkSignature, localAccountValidator, signatureValidator } from '../../middlewares' | 6 | import { asyncMiddleware, checkSignature, localAccountValidator, signatureValidator } from '../../middlewares' |
7 | import { activityPubValidator } from '../../middlewares/validators/activitypub/activity' | 7 | import { activityPubValidator } from '../../middlewares/validators/activitypub/activity' |
8 | import { ActorModel } from '../../models/activitypub/actor' | ||
8 | 9 | ||
9 | const inboxRouter = express.Router() | 10 | const inboxRouter = express.Router() |
10 | 11 | ||
@@ -48,7 +49,14 @@ async function inboxController (req: express.Request, res: express.Response, nex | |||
48 | activities = activities.filter(a => isActivityValid(a)) | 49 | activities = activities.filter(a => isActivityValid(a)) |
49 | logger.debug('We keep %d activities.', activities.length, { activities }) | 50 | logger.debug('We keep %d activities.', activities.length, { activities }) |
50 | 51 | ||
51 | await processActivities(activities, res.locals.signature.account, res.locals.account) | 52 | let specificActor: ActorModel = undefined |
53 | if (res.locals.account) { | ||
54 | specificActor = res.locals.account | ||
55 | } else if (res.locals.videoChannel) { | ||
56 | specificActor = res.locals.videoChannel | ||
57 | } | ||
58 | |||
59 | await processActivities(activities, res.locals.signature.actor, specificActor) | ||
52 | 60 | ||
53 | res.status(204).end() | 61 | res.status(204).end() |
54 | } | 62 | } |
diff --git a/server/controllers/activitypub/outbox.ts b/server/controllers/activitypub/outbox.ts index 6ed8a3454..01ba253c6 100644 --- a/server/controllers/activitypub/outbox.ts +++ b/server/controllers/activitypub/outbox.ts | |||
@@ -3,9 +3,8 @@ 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 { ACTIVITY_PUB } from '../../initializers/constants' | 5 | import { ACTIVITY_PUB } from '../../initializers/constants' |
6 | import { addActivityData } from '../../lib/activitypub/send/send-add' | 6 | import { announceActivityData, createActivityData } from '../../lib/activitypub/send' |
7 | import { getAnnounceActivityPubUrl } from '../../lib/activitypub/url' | 7 | import { getAnnounceActivityPubUrl } from '../../lib/activitypub/url' |
8 | import { announceActivityData } from '../../lib/index' | ||
9 | import { asyncMiddleware, localAccountValidator } from '../../middlewares' | 8 | import { asyncMiddleware, localAccountValidator } from '../../middlewares' |
10 | import { AccountModel } from '../../models/account/account' | 9 | import { AccountModel } from '../../models/account/account' |
11 | import { VideoModel } from '../../models/video/video' | 10 | import { VideoModel } from '../../models/video/video' |
@@ -27,29 +26,30 @@ export { | |||
27 | 26 | ||
28 | async function outboxController (req: express.Request, res: express.Response, next: express.NextFunction) { | 27 | async function outboxController (req: express.Request, res: express.Response, next: express.NextFunction) { |
29 | const account: AccountModel = res.locals.account | 28 | const account: AccountModel = res.locals.account |
29 | const actor = account.Actor | ||
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 VideoModel.listAllAndSharedByAccountForOutbox(account.id, start, count) | 34 | const data = await VideoModel.listAllAndSharedByActorForOutbox(actor.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) { |
38 | const videoObject = video.toActivityPubObject() | 38 | const videoObject = video.toActivityPubObject() |
39 | 39 | ||
40 | // This is a shared video | ||
41 | const videoChannel = video.VideoChannel | 40 | const videoChannel = video.VideoChannel |
41 | // This is a shared video | ||
42 | if (video.VideoShares !== undefined && video.VideoShares.length !== 0) { | 42 | if (video.VideoShares !== undefined && video.VideoShares.length !== 0) { |
43 | const addActivity = await addActivityData(video.url, videoChannel.Account, video, videoChannel.Actor.url, videoObject, undefined) | 43 | const createActivity = await createActivityData(video.url, videoChannel.Account.Actor, videoObject, undefined) |
44 | 44 | ||
45 | const url = getAnnounceActivityPubUrl(video.url, account) | 45 | const url = getAnnounceActivityPubUrl(video.url, actor) |
46 | const announceActivity = await announceActivityData(url, account, addActivity, undefined) | 46 | const announceActivity = await announceActivityData(url, actor, createActivity, undefined) |
47 | 47 | ||
48 | activities.push(announceActivity) | 48 | activities.push(announceActivity) |
49 | } else { | 49 | } else { |
50 | const addActivity = await addActivityData(video.url, account, video, videoChannel.Actor.url, videoObject, undefined) | 50 | const createActivity = await createActivityData(video.url, videoChannel.Account.Actor, videoObject, undefined) |
51 | 51 | ||
52 | activities.push(addActivity) | 52 | activities.push(createActivity) |
53 | } | 53 | } |
54 | } | 54 | } |
55 | 55 | ||
@@ -57,7 +57,7 @@ async function outboxController (req: express.Request, res: express.Response, ne | |||
57 | data: activities, | 57 | data: activities, |
58 | total: data.total | 58 | total: data.total |
59 | } | 59 | } |
60 | const json = activityPubCollectionPagination(account.url + '/outbox', page, newResult) | 60 | const json = activityPubCollectionPagination(account.Actor.url + '/outbox', page, newResult) |
61 | 61 | ||
62 | return res.json(json).end() | 62 | return res.json(json).end() |
63 | } | 63 | } |
diff --git a/server/controllers/api/server/follows.ts b/server/controllers/api/server/follows.ts index 497edb8eb..e7d81f7c3 100644 --- a/server/controllers/api/server/follows.ts +++ b/server/controllers/api/server/follows.ts | |||
@@ -1,10 +1,9 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { UserRight } from '../../../../shared/models/users' | 2 | import { UserRight } from '../../../../shared/models/users' |
3 | import { getAccountFromWebfinger, getFormattedObjects, getServerAccount, logger, retryTransactionWrapper } from '../../../helpers' | 3 | import { getFormattedObjects, getServerActor, loadActorUrlOrGetFromWebfinger, logger, retryTransactionWrapper } from '../../../helpers' |
4 | import { sequelizeTypescript, SERVER_ACCOUNT_NAME } from '../../../initializers' | 4 | import { sequelizeTypescript, SERVER_ACTOR_NAME } from '../../../initializers' |
5 | import { saveAccountAndServerIfNotExist } from '../../../lib/activitypub' | 5 | import { getOrCreateActorAndServerAndModel } from '../../../lib/activitypub' |
6 | import { sendUndoFollow } from '../../../lib/activitypub/send' | 6 | import { sendFollow, sendUndoFollow } from '../../../lib/activitypub/send' |
7 | import { sendFollow } from '../../../lib/index' | ||
8 | import { | 7 | import { |
9 | asyncMiddleware, | 8 | asyncMiddleware, |
10 | authenticate, | 9 | authenticate, |
@@ -17,8 +16,8 @@ import { | |||
17 | setPagination | 16 | setPagination |
18 | } from '../../../middlewares' | 17 | } from '../../../middlewares' |
19 | import { followersSortValidator, followingSortValidator, followValidator } from '../../../middlewares/validators' | 18 | import { followersSortValidator, followingSortValidator, followValidator } from '../../../middlewares/validators' |
20 | import { AccountModel } from '../../../models/account/account' | 19 | import { ActorModel } from '../../../models/activitypub/actor' |
21 | import { AccountFollowModel } from '../../../models/account/account-follow' | 20 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' |
22 | 21 | ||
23 | const serverFollowsRouter = express.Router() | 22 | const serverFollowsRouter = express.Router() |
24 | 23 | ||
@@ -38,7 +37,7 @@ serverFollowsRouter.post('/following', | |||
38 | asyncMiddleware(followRetry) | 37 | asyncMiddleware(followRetry) |
39 | ) | 38 | ) |
40 | 39 | ||
41 | serverFollowsRouter.delete('/following/:accountId', | 40 | serverFollowsRouter.delete('/following/:host', |
42 | authenticate, | 41 | authenticate, |
43 | ensureUserHasRight(UserRight.MANAGE_SERVER_FOLLOW), | 42 | ensureUserHasRight(UserRight.MANAGE_SERVER_FOLLOW), |
44 | asyncMiddleware(removeFollowingValidator), | 43 | asyncMiddleware(removeFollowingValidator), |
@@ -62,43 +61,41 @@ export { | |||
62 | // --------------------------------------------------------------------------- | 61 | // --------------------------------------------------------------------------- |
63 | 62 | ||
64 | async function listFollowing (req: express.Request, res: express.Response, next: express.NextFunction) { | 63 | async function listFollowing (req: express.Request, res: express.Response, next: express.NextFunction) { |
65 | const serverAccount = await getServerAccount() | 64 | const serverActor = await getServerActor() |
66 | const resultList = await AccountFollowModel.listFollowingForApi(serverAccount.id, req.query.start, req.query.count, req.query.sort) | 65 | const resultList = await ActorFollowModel.listFollowingForApi(serverActor.id, req.query.start, req.query.count, req.query.sort) |
67 | 66 | ||
68 | return res.json(getFormattedObjects(resultList.data, resultList.total)) | 67 | return res.json(getFormattedObjects(resultList.data, resultList.total)) |
69 | } | 68 | } |
70 | 69 | ||
71 | async function listFollowers (req: express.Request, res: express.Response, next: express.NextFunction) { | 70 | async function listFollowers (req: express.Request, res: express.Response, next: express.NextFunction) { |
72 | const serverAccount = await getServerAccount() | 71 | const serverActor = await getServerActor() |
73 | const resultList = await AccountFollowModel.listFollowersForApi(serverAccount.id, req.query.start, req.query.count, req.query.sort) | 72 | const resultList = await ActorFollowModel.listFollowersForApi(serverActor.id, req.query.start, req.query.count, req.query.sort) |
74 | 73 | ||
75 | return res.json(getFormattedObjects(resultList.data, resultList.total)) | 74 | return res.json(getFormattedObjects(resultList.data, resultList.total)) |
76 | } | 75 | } |
77 | 76 | ||
78 | async function followRetry (req: express.Request, res: express.Response, next: express.NextFunction) { | 77 | async function followRetry (req: express.Request, res: express.Response, next: express.NextFunction) { |
79 | const hosts = req.body.hosts as string[] | 78 | const hosts = req.body.hosts as string[] |
80 | const fromAccount = await getServerAccount() | 79 | const fromActor = await getServerActor() |
81 | 80 | ||
82 | const tasks: Promise<any>[] = [] | 81 | const tasks: Promise<any>[] = [] |
83 | const accountName = SERVER_ACCOUNT_NAME | 82 | const actorName = SERVER_ACTOR_NAME |
84 | 83 | ||
85 | for (const host of hosts) { | 84 | for (const host of hosts) { |
86 | |||
87 | // We process each host in a specific transaction | 85 | // We process each host in a specific transaction |
88 | // First, we add the follow request in the database | 86 | // First, we add the follow request in the database |
89 | // Then we send the follow request to other account | 87 | // Then we send the follow request to other actor |
90 | const p = loadLocalOrGetAccountFromWebfinger(accountName, host) | 88 | const p = loadActorUrlOrGetFromWebfinger(actorName, host) |
91 | .then(accountResult => { | 89 | .then(actorUrl => getOrCreateActorAndServerAndModel(actorUrl)) |
92 | let targetAccount = accountResult.account | 90 | .then(targetActor => { |
93 | |||
94 | const options = { | 91 | const options = { |
95 | arguments: [ fromAccount, targetAccount, accountResult.loadedFromDB ], | 92 | arguments: [ fromActor, targetActor ], |
96 | errorMessage: 'Cannot follow with many retries.' | 93 | errorMessage: 'Cannot follow with many retries.' |
97 | } | 94 | } |
98 | 95 | ||
99 | return retryTransactionWrapper(follow, options) | 96 | return retryTransactionWrapper(follow, options) |
100 | }) | 97 | }) |
101 | .catch(err => logger.warn('Cannot follow server %s.', `${accountName}@${host}`, err)) | 98 | .catch(err => logger.warn('Cannot follow server %s.', host, err)) |
102 | 99 | ||
103 | tasks.push(p) | 100 | tasks.push(p) |
104 | } | 101 | } |
@@ -110,42 +107,32 @@ async function followRetry (req: express.Request, res: express.Response, next: e | |||
110 | return res.status(204).end() | 107 | return res.status(204).end() |
111 | } | 108 | } |
112 | 109 | ||
113 | async function follow (fromAccount: AccountModel, targetAccount: AccountModel, targetAlreadyInDB: boolean) { | 110 | function follow (fromActor: ActorModel, targetActor: ActorModel) { |
114 | try { | 111 | return sequelizeTypescript.transaction(async t => { |
115 | await sequelizeTypescript.transaction(async t => { | 112 | const [ actorFollow ] = await ActorFollowModel.findOrCreate({ |
116 | if (targetAlreadyInDB === false) { | 113 | where: { |
117 | await saveAccountAndServerIfNotExist(targetAccount, t) | 114 | actorId: fromActor.id, |
118 | } | 115 | targetActorId: targetActor.id |
119 | 116 | }, | |
120 | const [ accountFollow ] = await AccountFollowModel.findOrCreate({ | 117 | defaults: { |
121 | where: { | 118 | state: 'pending', |
122 | accountId: fromAccount.id, | 119 | actorId: fromActor.id, |
123 | targetAccountId: targetAccount.id | 120 | targetActorId: targetActor.id |
124 | }, | 121 | }, |
125 | defaults: { | 122 | transaction: t |
126 | state: 'pending', | ||
127 | accountId: fromAccount.id, | ||
128 | targetAccountId: targetAccount.id | ||
129 | }, | ||
130 | transaction: t | ||
131 | }) | ||
132 | accountFollow.AccountFollowing = targetAccount | ||
133 | accountFollow.AccountFollower = fromAccount | ||
134 | |||
135 | // Send a notification to remote server | ||
136 | if (accountFollow.state === 'pending') { | ||
137 | await sendFollow(accountFollow, t) | ||
138 | } | ||
139 | }) | 123 | }) |
140 | } catch (err) { | 124 | actorFollow.ActorFollowing = targetActor |
141 | // Reset target account | 125 | actorFollow.ActorFollower = fromActor |
142 | targetAccount.isNewRecord = !targetAlreadyInDB | 126 | |
143 | throw err | 127 | // Send a notification to remote server |
144 | } | 128 | if (actorFollow.state === 'pending') { |
129 | await sendFollow(actorFollow, t) | ||
130 | } | ||
131 | }) | ||
145 | } | 132 | } |
146 | 133 | ||
147 | async function removeFollow (req: express.Request, res: express.Response, next: express.NextFunction) { | 134 | async function removeFollow (req: express.Request, res: express.Response, next: express.NextFunction) { |
148 | const follow: AccountFollowModel = res.locals.follow | 135 | const follow: ActorFollowModel = res.locals.follow |
149 | 136 | ||
150 | await sequelizeTypescript.transaction(async t => { | 137 | await sequelizeTypescript.transaction(async t => { |
151 | if (follow.state === 'accepted') await sendUndoFollow(follow, t) | 138 | if (follow.state === 'accepted') await sendUndoFollow(follow, t) |
@@ -153,24 +140,11 @@ async function removeFollow (req: express.Request, res: express.Response, next: | |||
153 | await follow.destroy({ transaction: t }) | 140 | await follow.destroy({ transaction: t }) |
154 | }) | 141 | }) |
155 | 142 | ||
156 | // Destroy the account that will destroy video channels, videos and video files too | 143 | // Destroy the actor that will destroy video channels, videos and video files too |
157 | // This could be long so don't wait this task | 144 | // This could be long so don't wait this task |
158 | const following = follow.AccountFollowing | 145 | const following = follow.ActorFollowing |
159 | following.destroy() | 146 | following.destroy() |
160 | .catch(err => logger.error('Cannot destroy account that we do not follow anymore %s.', following.Actor.url, err)) | 147 | .catch(err => logger.error('Cannot destroy actor that we do not follow anymore %s.', following.url, err)) |
161 | 148 | ||
162 | return res.status(204).end() | 149 | return res.status(204).end() |
163 | } | 150 | } |
164 | |||
165 | async function loadLocalOrGetAccountFromWebfinger (name: string, host: string) { | ||
166 | let loadedFromDB = true | ||
167 | let account = await AccountModel.loadByNameAndHost(name, host) | ||
168 | |||
169 | if (!account) { | ||
170 | const nameWithDomain = name + '@' + host | ||
171 | account = await getAccountFromWebfinger(nameWithDomain) | ||
172 | loadedFromDB = false | ||
173 | } | ||
174 | |||
175 | return { account, loadedFromDB } | ||
176 | } | ||
diff --git a/server/controllers/api/users.ts b/server/controllers/api/users.ts index 995542604..3106df9b9 100644 --- a/server/controllers/api/users.ts +++ b/server/controllers/api/users.ts | |||
@@ -2,7 +2,7 @@ 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 } from '../../initializers' | 4 | import { CONFIG } from '../../initializers' |
5 | import { createUserAccountAndChannel } from '../../lib' | 5 | import { createUserAccountAndChannel } from '../../lib/user' |
6 | import { | 6 | import { |
7 | asyncMiddleware, | 7 | asyncMiddleware, |
8 | authenticate, | 8 | authenticate, |
diff --git a/server/controllers/api/videos/abuse.ts b/server/controllers/api/videos/abuse.ts index 08cc4d0b4..fecdaf5a3 100644 --- a/server/controllers/api/videos/abuse.ts +++ b/server/controllers/api/videos/abuse.ts | |||
@@ -1,22 +1,18 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { | 2 | import { UserRight, VideoAbuseCreate } from '../../../../shared' |
3 | logger, | 3 | import { getFormattedObjects, logger, retryTransactionWrapper } from '../../../helpers' |
4 | getFormattedObjects, | ||
5 | retryTransactionWrapper | ||
6 | } from '../../../helpers' | ||
7 | import { sequelizeTypescript } from '../../../initializers' | 4 | import { sequelizeTypescript } from '../../../initializers' |
5 | import { sendVideoAbuse } from '../../../lib/activitypub/send' | ||
8 | import { | 6 | import { |
7 | asyncMiddleware, | ||
9 | authenticate, | 8 | authenticate, |
10 | ensureUserHasRight, | 9 | ensureUserHasRight, |
11 | paginationValidator, | 10 | paginationValidator, |
12 | videoAbuseReportValidator, | ||
13 | videoAbusesSortValidator, | ||
14 | setVideoAbusesSort, | ||
15 | setPagination, | 11 | setPagination, |
16 | asyncMiddleware | 12 | setVideoAbusesSort, |
13 | videoAbuseReportValidator, | ||
14 | videoAbusesSortValidator | ||
17 | } from '../../../middlewares' | 15 | } from '../../../middlewares' |
18 | import { VideoAbuseCreate, UserRight } from '../../../../shared' | ||
19 | import { sendVideoAbuse } from '../../../lib/index' | ||
20 | import { AccountModel } from '../../../models/account/account' | 16 | import { AccountModel } from '../../../models/account/account' |
21 | import { VideoModel } from '../../../models/video/video' | 17 | import { VideoModel } from '../../../models/video/video' |
22 | import { VideoAbuseModel } from '../../../models/video/video-abuse' | 18 | import { VideoAbuseModel } from '../../../models/video/video-abuse' |
@@ -80,7 +76,7 @@ async function reportVideoAbuse (req: express.Request, res: express.Response) { | |||
80 | 76 | ||
81 | // We send the video abuse to the origin server | 77 | // We send the video abuse to the origin server |
82 | if (videoInstance.isOwned() === false) { | 78 | if (videoInstance.isOwned() === false) { |
83 | await sendVideoAbuse(reporterAccount, videoAbuseInstance, videoInstance, t) | 79 | await sendVideoAbuse(reporterAccount.Actor, videoAbuseInstance, videoInstance, t) |
84 | } | 80 | } |
85 | }) | 81 | }) |
86 | 82 | ||
diff --git a/server/controllers/api/videos/channel.ts b/server/controllers/api/videos/channel.ts index 315469115..cc00d9f8d 100644 --- a/server/controllers/api/videos/channel.ts +++ b/server/controllers/api/videos/channel.ts | |||
@@ -2,8 +2,8 @@ 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 { sequelizeTypescript } from '../../../initializers' | 4 | import { sequelizeTypescript } from '../../../initializers' |
5 | import { createVideoChannel } from '../../../lib' | 5 | import { setAsyncActorKeys } from '../../../lib/activitypub' |
6 | import { sendUpdateVideoChannel } from '../../../lib/activitypub/send/send-update' | 6 | import { createVideoChannel } from '../../../lib/video-channel' |
7 | import { | 7 | import { |
8 | asyncMiddleware, | 8 | asyncMiddleware, |
9 | authenticate, | 9 | authenticate, |
@@ -92,15 +92,17 @@ async function addVideoChannelRetryWrapper (req: express.Request, res: express.R | |||
92 | return res.type('json').status(204).end() | 92 | return res.type('json').status(204).end() |
93 | } | 93 | } |
94 | 94 | ||
95 | function addVideoChannel (req: express.Request, res: express.Response) { | 95 | async function addVideoChannel (req: express.Request, res: express.Response) { |
96 | const videoChannelInfo: VideoChannelCreate = req.body | 96 | const videoChannelInfo: VideoChannelCreate = req.body |
97 | const account: AccountModel = res.locals.oauth.token.User.Account | 97 | const account: AccountModel = res.locals.oauth.token.User.Account |
98 | 98 | ||
99 | return sequelizeTypescript.transaction(async t => { | 99 | const videoChannelCreated = await sequelizeTypescript.transaction(async t => { |
100 | const videoChannelCreated = await createVideoChannel(videoChannelInfo, account, t) | 100 | return createVideoChannel(videoChannelInfo, account, t) |
101 | |||
102 | logger.info('Video channel with uuid %s created.', videoChannelCreated.uuid) | ||
103 | }) | 101 | }) |
102 | |||
103 | setAsyncActorKeys(videoChannelCreated.Actor) | ||
104 | |||
105 | logger.info('Video channel with uuid %s created.', videoChannelCreated.Actor.uuid) | ||
104 | } | 106 | } |
105 | 107 | ||
106 | async function updateVideoChannelRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) { | 108 | async function updateVideoChannelRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) { |
@@ -128,12 +130,13 @@ async function updateVideoChannel (req: express.Request, res: express.Response) | |||
128 | if (videoChannelInfoToUpdate.name !== undefined) videoChannelInstance.set('name', videoChannelInfoToUpdate.name) | 130 | if (videoChannelInfoToUpdate.name !== undefined) videoChannelInstance.set('name', videoChannelInfoToUpdate.name) |
129 | if (videoChannelInfoToUpdate.description !== undefined) videoChannelInstance.set('description', videoChannelInfoToUpdate.description) | 131 | if (videoChannelInfoToUpdate.description !== undefined) videoChannelInstance.set('description', videoChannelInfoToUpdate.description) |
130 | 132 | ||
131 | const videoChannelInstanceUpdated = await videoChannelInstance.save(sequelizeOptions) | 133 | await videoChannelInstance.save(sequelizeOptions) |
132 | 134 | ||
133 | await sendUpdateVideoChannel(videoChannelInstanceUpdated, t) | 135 | // TODO |
136 | // await sendUpdateVideoChannel(videoChannelInstanceUpdated, t) | ||
134 | }) | 137 | }) |
135 | 138 | ||
136 | logger.info('Video channel with name %s and uuid %s updated.', videoChannelInstance.name, videoChannelInstance.uuid) | 139 | logger.info('Video channel with name %s and uuid %s updated.', videoChannelInstance.name, videoChannelInstance.Actor.uuid) |
137 | } catch (err) { | 140 | } catch (err) { |
138 | logger.debug('Cannot update the video channel.', err) | 141 | logger.debug('Cannot update the video channel.', err) |
139 | 142 | ||
@@ -160,11 +163,12 @@ async function removeVideoChannelRetryWrapper (req: express.Request, res: expres | |||
160 | async function removeVideoChannel (req: express.Request, res: express.Response) { | 163 | async function removeVideoChannel (req: express.Request, res: express.Response) { |
161 | const videoChannelInstance: VideoChannelModel = res.locals.videoChannel | 164 | const videoChannelInstance: VideoChannelModel = res.locals.videoChannel |
162 | 165 | ||
163 | await sequelizeTypescript.transaction(async t => { | 166 | return sequelizeTypescript.transaction(async t => { |
164 | await videoChannelInstance.destroy({ transaction: t }) | 167 | await videoChannelInstance.destroy({ transaction: t }) |
168 | |||
169 | logger.info('Video channel with name %s and uuid %s deleted.', videoChannelInstance.name, videoChannelInstance.Actor.uuid) | ||
165 | }) | 170 | }) |
166 | 171 | ||
167 | logger.info('Video channel with name %s and uuid %s deleted.', videoChannelInstance.name, videoChannelInstance.uuid) | ||
168 | } | 172 | } |
169 | 173 | ||
170 | async function getVideoChannel (req: express.Request, res: express.Response, next: express.NextFunction) { | 174 | async function getVideoChannel (req: express.Request, res: express.Response, next: express.NextFunction) { |
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index 91ab8c66a..d6934748f 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts | |||
@@ -11,7 +11,7 @@ import { | |||
11 | resetSequelizeInstance, | 11 | resetSequelizeInstance, |
12 | retryTransactionWrapper | 12 | retryTransactionWrapper |
13 | } from '../../../helpers' | 13 | } from '../../../helpers' |
14 | import { getServerAccount } from '../../../helpers/utils' | 14 | import { getServerActor } from '../../../helpers/utils' |
15 | import { | 15 | import { |
16 | CONFIG, | 16 | CONFIG, |
17 | sequelizeTypescript, | 17 | sequelizeTypescript, |
@@ -22,8 +22,7 @@ import { | |||
22 | VIDEO_PRIVACIES | 22 | VIDEO_PRIVACIES |
23 | } from '../../../initializers' | 23 | } from '../../../initializers' |
24 | import { fetchRemoteVideoDescription, getVideoActivityPubUrl, shareVideoByServer } from '../../../lib/activitypub' | 24 | import { fetchRemoteVideoDescription, getVideoActivityPubUrl, shareVideoByServer } from '../../../lib/activitypub' |
25 | import { sendAddVideo, sendCreateViewToOrigin, sendUpdateVideo } from '../../../lib/activitypub/send' | 25 | import { sendCreateVideo, sendCreateViewToOrigin, sendCreateViewToVideoFollowers, sendUpdateVideo } from '../../../lib/activitypub/send' |
26 | import { sendCreateViewToVideoFollowers } from '../../../lib/index' | ||
27 | import { transcodingJobScheduler } from '../../../lib/jobs/transcoding-job-scheduler' | 26 | import { transcodingJobScheduler } from '../../../lib/jobs/transcoding-job-scheduler' |
28 | import { | 27 | import { |
29 | asyncMiddleware, | 28 | asyncMiddleware, |
@@ -248,7 +247,8 @@ async function addVideo (req: express.Request, res: express.Response, videoPhysi | |||
248 | // Don't send video to remote servers, it is private | 247 | // Don't send video to remote servers, it is private |
249 | if (video.privacy === VideoPrivacy.PRIVATE) return videoCreated | 248 | if (video.privacy === VideoPrivacy.PRIVATE) return videoCreated |
250 | 249 | ||
251 | await sendAddVideo(video, t) | 250 | await sendCreateVideo(video, t) |
251 | // TODO: share by video channel | ||
252 | await shareVideoByServer(video, t) | 252 | await shareVideoByServer(video, t) |
253 | 253 | ||
254 | logger.info('Video with name %s and uuid %s created.', videoInfo.name, videoCreated.uuid) | 254 | logger.info('Video with name %s and uuid %s created.', videoInfo.name, videoCreated.uuid) |
@@ -304,7 +304,8 @@ async function updateVideo (req: express.Request, res: express.Response) { | |||
304 | 304 | ||
305 | // Video is not private anymore, send a create action to remote servers | 305 | // Video is not private anymore, send a create action to remote servers |
306 | if (wasPrivateVideo === true && videoInstanceUpdated.privacy !== VideoPrivacy.PRIVATE) { | 306 | if (wasPrivateVideo === true && videoInstanceUpdated.privacy !== VideoPrivacy.PRIVATE) { |
307 | await sendAddVideo(videoInstanceUpdated, t) | 307 | await sendCreateVideo(videoInstanceUpdated, t) |
308 | // TODO: Send by video channel | ||
308 | await shareVideoByServer(videoInstanceUpdated, t) | 309 | await shareVideoByServer(videoInstanceUpdated, t) |
309 | } | 310 | } |
310 | }) | 311 | }) |
@@ -330,7 +331,7 @@ async function viewVideo (req: express.Request, res: express.Response) { | |||
330 | const videoInstance = res.locals.video | 331 | const videoInstance = res.locals.video |
331 | 332 | ||
332 | await videoInstance.increment('views') | 333 | await videoInstance.increment('views') |
333 | const serverAccount = await getServerAccount() | 334 | const serverAccount = await getServerActor() |
334 | 335 | ||
335 | if (videoInstance.isOwned()) { | 336 | if (videoInstance.isOwned()) { |
336 | await sendCreateViewToVideoFollowers(serverAccount, videoInstance, undefined) | 337 | await sendCreateViewToVideoFollowers(serverAccount, videoInstance, undefined) |
diff --git a/server/controllers/static.ts b/server/controllers/static.ts index 33aed8927..ccae60517 100644 --- a/server/controllers/static.ts +++ b/server/controllers/static.ts | |||
@@ -1,11 +1,7 @@ | |||
1 | import * as express from 'express' | ||
2 | import * as cors from 'cors' | 1 | import * as cors from 'cors' |
3 | import { | 2 | import * as express from 'express' |
4 | CONFIG, | 3 | import { CONFIG, STATIC_MAX_AGE, STATIC_PATHS } from '../initializers' |
5 | STATIC_MAX_AGE, | 4 | import { VideosPreviewCache } from '../lib/cache' |
6 | STATIC_PATHS | ||
7 | } from '../initializers' | ||
8 | import { VideosPreviewCache } from '../lib' | ||
9 | import { asyncMiddleware } from '../middlewares' | 5 | import { asyncMiddleware } from '../middlewares' |
10 | 6 | ||
11 | const staticRouter = express.Router() | 7 | const staticRouter = express.Router() |
diff --git a/server/controllers/webfinger.ts b/server/controllers/webfinger.ts index 8829500bc..ed781c21b 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' | 2 | import { asyncMiddleware } from '../middlewares' |
3 | import { webfingerValidator } from '../middlewares/validators' | 3 | import { webfingerValidator } from '../middlewares/validators' |
4 | import { AccountModel } from '../models/account/account' | 4 | import { ActorModel } from '../models/activitypub/actor' |
5 | 5 | ||
6 | const webfingerRouter = express.Router() | 6 | const webfingerRouter = express.Router() |
7 | 7 | ||
@@ -19,16 +19,16 @@ 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 = res.locals.account as AccountModel | 22 | const actor = res.locals.actor as ActorModel |
23 | 23 | ||
24 | const json = { | 24 | const json = { |
25 | subject: req.query.resource, | 25 | subject: req.query.resource, |
26 | aliases: [ account.Actor.url ], | 26 | aliases: [ actor.url ], |
27 | links: [ | 27 | links: [ |
28 | { | 28 | { |
29 | rel: 'self', | 29 | rel: 'self', |
30 | type: 'application/activity+json', | 30 | type: 'application/activity+json', |
31 | href: account.Actor.url | 31 | href: actor.url |
32 | } | 32 | } |
33 | ] | 33 | ] |
34 | } | 34 | } |