diff options
Diffstat (limited to 'server/controllers')
-rw-r--r-- | server/controllers/activitypub/outbox.ts | 14 | ||||
-rw-r--r-- | server/controllers/api/server/follows.ts | 9 | ||||
-rw-r--r-- | server/controllers/api/videos/index.ts | 26 |
3 files changed, 32 insertions, 17 deletions
diff --git a/server/controllers/activitypub/outbox.ts b/server/controllers/activitypub/outbox.ts index 74d399763..8c63eeb2e 100644 --- a/server/controllers/activitypub/outbox.ts +++ b/server/controllers/activitypub/outbox.ts | |||
@@ -1,14 +1,14 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { Activity, ActivityAdd } from '../../../shared/models/activitypub/activity' | 2 | import { Activity, ActivityAdd } from '../../../shared/models/activitypub/activity' |
3 | import { activityPubCollectionPagination, activityPubContextify } from '../../helpers/activitypub' | 3 | import { activityPubCollectionPagination } from '../../helpers/activitypub' |
4 | import { pageToStartAndCount } from '../../helpers/core-utils' | ||
4 | import { database as db } from '../../initializers' | 5 | import { database as db } from '../../initializers' |
6 | import { ACTIVITY_PUB } from '../../initializers/constants' | ||
5 | import { addActivityData } from '../../lib/activitypub/send/send-add' | 7 | import { addActivityData } from '../../lib/activitypub/send/send-add' |
6 | import { getAnnounceActivityPubUrl } from '../../lib/activitypub/url' | 8 | import { getAnnounceActivityPubUrl } from '../../lib/activitypub/url' |
7 | import { announceActivityData } from '../../lib/index' | 9 | import { announceActivityData } from '../../lib/index' |
8 | import { asyncMiddleware, localAccountValidator } from '../../middlewares' | 10 | import { asyncMiddleware, localAccountValidator } from '../../middlewares' |
9 | import { AccountInstance } from '../../models/account/account-interface' | 11 | import { AccountInstance } from '../../models/account/account-interface' |
10 | import { pageToStartAndCount } from '../../helpers/core-utils' | ||
11 | import { ACTIVITY_PUB } from '../../initializers/constants' | ||
12 | 12 | ||
13 | const outboxRouter = express.Router() | 13 | const outboxRouter = express.Router() |
14 | 14 | ||
@@ -36,14 +36,18 @@ async function outboxController (req: express.Request, res: express.Response, ne | |||
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 | let addActivity: ActivityAdd = await addActivityData(video.url, account, video, video.VideoChannel.url, videoObject) | ||
40 | 39 | ||
41 | // This is a shared video | 40 | // This is a shared video |
42 | if (video.VideoShare !== undefined) { | 41 | if (video.VideoShares !== undefined && video.VideoShares.length !== 0) { |
42 | const addActivity = await addActivityData(video.url, video.VideoChannel.Account, video, video.VideoChannel.url, videoObject) | ||
43 | |||
43 | const url = getAnnounceActivityPubUrl(video.url, account) | 44 | const url = getAnnounceActivityPubUrl(video.url, account) |
44 | const announceActivity = await announceActivityData(url, account, addActivity) | 45 | const announceActivity = await announceActivityData(url, account, addActivity) |
46 | |||
45 | activities.push(announceActivity) | 47 | activities.push(announceActivity) |
46 | } else { | 48 | } else { |
49 | const addActivity = await addActivityData(video.url, account, video, video.VideoChannel.url, videoObject) | ||
50 | |||
47 | activities.push(addActivity) | 51 | activities.push(addActivity) |
48 | } | 52 | } |
49 | } | 53 | } |
diff --git a/server/controllers/api/server/follows.ts b/server/controllers/api/server/follows.ts index 391f8bdca..535d530f7 100644 --- a/server/controllers/api/server/follows.ts +++ b/server/controllers/api/server/follows.ts | |||
@@ -148,10 +148,17 @@ async function removeFollow (req: express.Request, res: express.Response, next: | |||
148 | const follow: AccountFollowInstance = res.locals.follow | 148 | const follow: AccountFollowInstance = res.locals.follow |
149 | 149 | ||
150 | await db.sequelize.transaction(async t => { | 150 | await db.sequelize.transaction(async t => { |
151 | await sendUndoFollow(follow, t) | 151 | if (follow.state === 'accepted') await sendUndoFollow(follow, t) |
152 | |||
152 | await follow.destroy({ transaction: t }) | 153 | await follow.destroy({ transaction: t }) |
153 | }) | 154 | }) |
154 | 155 | ||
156 | // Destroy the account that will destroy video channels, videos and video files too | ||
157 | // This could be long so don't wait this task | ||
158 | const following = follow.AccountFollowing | ||
159 | following.destroy() | ||
160 | .catch(err => logger.error('Cannot destroy account that we do not follow anymore %s.', following.url, err)) | ||
161 | |||
155 | return res.status(204).end() | 162 | return res.status(204).end() |
156 | } | 163 | } |
157 | 164 | ||
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index 0d114dcd2..2b5afd632 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts | |||
@@ -11,10 +11,15 @@ import { | |||
11 | resetSequelizeInstance, | 11 | resetSequelizeInstance, |
12 | retryTransactionWrapper | 12 | retryTransactionWrapper |
13 | } from '../../../helpers' | 13 | } from '../../../helpers' |
14 | import { getServerAccount } from '../../../helpers/utils' | ||
14 | import { CONFIG, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_MIMETYPE_EXT, VIDEO_PRIVACIES } from '../../../initializers' | 15 | import { CONFIG, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_MIMETYPE_EXT, VIDEO_PRIVACIES } from '../../../initializers' |
15 | import { database as db } from '../../../initializers/database' | 16 | import { database as db } from '../../../initializers/database' |
16 | import { sendAddVideo } from '../../../lib/activitypub/send/send-add' | 17 | import { sendAddVideo } from '../../../lib/activitypub/send/send-add' |
17 | import { sendUpdateVideo } from '../../../lib/activitypub/send/send-update' | 18 | import { sendUpdateVideo } from '../../../lib/activitypub/send/send-update' |
19 | import { shareVideoByServer } from '../../../lib/activitypub/share' | ||
20 | import { getVideoActivityPubUrl } from '../../../lib/activitypub/url' | ||
21 | import { fetchRemoteVideoDescription } from '../../../lib/activitypub/videos' | ||
22 | import { sendCreateViewToVideoFollowers } from '../../../lib/index' | ||
18 | import { transcodingJobScheduler } from '../../../lib/jobs/transcoding-job-scheduler/transcoding-job-scheduler' | 23 | import { transcodingJobScheduler } from '../../../lib/jobs/transcoding-job-scheduler/transcoding-job-scheduler' |
19 | import { | 24 | import { |
20 | asyncMiddleware, | 25 | asyncMiddleware, |
@@ -35,9 +40,7 @@ import { abuseVideoRouter } from './abuse' | |||
35 | import { blacklistRouter } from './blacklist' | 40 | import { blacklistRouter } from './blacklist' |
36 | import { videoChannelRouter } from './channel' | 41 | import { videoChannelRouter } from './channel' |
37 | import { rateVideoRouter } from './rate' | 42 | import { rateVideoRouter } from './rate' |
38 | import { getVideoActivityPubUrl } from '../../../lib/activitypub/url' | 43 | import { sendCreateViewToOrigin } from '../../../lib/activitypub/send/send-create' |
39 | import { shareVideoByServer } from '../../../lib/activitypub/share' | ||
40 | import { fetchRemoteVideoDescription } from '../../../lib/activitypub/videos' | ||
41 | 44 | ||
42 | const videosRouter = express.Router() | 45 | const videosRouter = express.Router() |
43 | 46 | ||
@@ -311,17 +314,18 @@ async function updateVideo (req: express.Request, res: express.Response) { | |||
311 | async function getVideo (req: express.Request, res: express.Response) { | 314 | async function getVideo (req: express.Request, res: express.Response) { |
312 | const videoInstance = res.locals.video | 315 | const videoInstance = res.locals.video |
313 | 316 | ||
317 | const baseIncrementPromise = videoInstance.increment('views') | ||
318 | .then(() => getServerAccount()) | ||
319 | |||
314 | if (videoInstance.isOwned()) { | 320 | if (videoInstance.isOwned()) { |
315 | // The increment is done directly in the database, not using the instance value | 321 | // The increment is done directly in the database, not using the instance value |
316 | // FIXME: make a real view system | 322 | baseIncrementPromise |
317 | // For example, only add a view when a user watch a video during 30s etc | 323 | .then(serverAccount => sendCreateViewToVideoFollowers(serverAccount, videoInstance, undefined)) |
318 | videoInstance.increment('views') | 324 | .catch(err => logger.error('Cannot add view to video/send view to followers for %s.', videoInstance.uuid, err)) |
319 | .then(() => { | ||
320 | // TODO: send to followers a notification | ||
321 | }) | ||
322 | .catch(err => logger.error('Cannot add view to video %s.', videoInstance.uuid, err)) | ||
323 | } else { | 325 | } else { |
324 | // TODO: send view event to followers | 326 | baseIncrementPromise |
327 | .then(serverAccount => sendCreateViewToOrigin(serverAccount, videoInstance, undefined)) | ||
328 | .catch(err => logger.error('Cannot send view to origin server for %s.', videoInstance.uuid, err)) | ||
325 | } | 329 | } |
326 | 330 | ||
327 | // Do not wait the view system | 331 | // Do not wait the view system |