diff options
author | Chocobozzz <me@florianbigard.com> | 2021-06-02 15:47:05 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-06-02 16:57:53 +0200 |
commit | 304a84d59c3a800b7f7aef48cf55f307534c0926 (patch) | |
tree | e099aefd76aa8ee5aacef7ddfc59d79111fe474b /server/lib/activitypub/process | |
parent | c56faf0d9453490737f283b29a203bb1ca632b95 (diff) | |
download | PeerTube-304a84d59c3a800b7f7aef48cf55f307534c0926.tar.gz PeerTube-304a84d59c3a800b7f7aef48cf55f307534c0926.tar.zst PeerTube-304a84d59c3a800b7f7aef48cf55f307534c0926.zip |
Refactor getOrCreateAPVideo
Diffstat (limited to 'server/lib/activitypub/process')
7 files changed, 18 insertions, 18 deletions
diff --git a/server/lib/activitypub/process/process-announce.ts b/server/lib/activitypub/process/process-announce.ts index 63082466e..ec23c705e 100644 --- a/server/lib/activitypub/process/process-announce.ts +++ b/server/lib/activitypub/process/process-announce.ts | |||
@@ -3,7 +3,7 @@ import { retryTransactionWrapper } from '../../../helpers/database-utils' | |||
3 | import { sequelizeTypescript } from '../../../initializers/database' | 3 | import { sequelizeTypescript } from '../../../initializers/database' |
4 | import { VideoShareModel } from '../../../models/video/video-share' | 4 | import { VideoShareModel } from '../../../models/video/video-share' |
5 | import { forwardVideoRelatedActivity } from '../send/utils' | 5 | import { forwardVideoRelatedActivity } from '../send/utils' |
6 | import { getOrCreateVideoAndAccountAndChannel } from '../videos' | 6 | import { getOrCreateAPVideo } from '../videos' |
7 | import { Notifier } from '../../notifier' | 7 | import { Notifier } from '../../notifier' |
8 | import { logger } from '../../../helpers/logger' | 8 | import { logger } from '../../../helpers/logger' |
9 | import { APProcessorOptions } from '../../../types/activitypub-processor.model' | 9 | import { APProcessorOptions } from '../../../types/activitypub-processor.model' |
@@ -32,7 +32,7 @@ async function processVideoShare (actorAnnouncer: MActorSignature, activity: Act | |||
32 | let videoCreated: boolean | 32 | let videoCreated: boolean |
33 | 33 | ||
34 | try { | 34 | try { |
35 | const result = await getOrCreateVideoAndAccountAndChannel({ videoObject: objectUri }) | 35 | const result = await getOrCreateAPVideo({ videoObject: objectUri }) |
36 | video = result.video | 36 | video = result.video |
37 | videoCreated = result.created | 37 | videoCreated = result.created |
38 | } catch (err) { | 38 | } catch (err) { |
diff --git a/server/lib/activitypub/process/process-create.ts b/server/lib/activitypub/process/process-create.ts index 9cded4dec..ef5a3100e 100644 --- a/server/lib/activitypub/process/process-create.ts +++ b/server/lib/activitypub/process/process-create.ts | |||
@@ -12,7 +12,7 @@ import { createOrUpdateCacheFile } from '../cache-file' | |||
12 | import { createOrUpdateVideoPlaylist } from '../playlist' | 12 | import { createOrUpdateVideoPlaylist } from '../playlist' |
13 | import { forwardVideoRelatedActivity } from '../send/utils' | 13 | import { forwardVideoRelatedActivity } from '../send/utils' |
14 | import { resolveThread } from '../video-comments' | 14 | import { resolveThread } from '../video-comments' |
15 | import { getOrCreateVideoAndAccountAndChannel } from '../videos' | 15 | import { getOrCreateAPVideo } from '../videos' |
16 | import { isBlockedByServerOrAccount } from '@server/lib/blocklist' | 16 | import { isBlockedByServerOrAccount } from '@server/lib/blocklist' |
17 | 17 | ||
18 | async function processCreateActivity (options: APProcessorOptions<ActivityCreate>) { | 18 | async function processCreateActivity (options: APProcessorOptions<ActivityCreate>) { |
@@ -55,7 +55,7 @@ async function processCreateVideo (activity: ActivityCreate, notify: boolean) { | |||
55 | const videoToCreateData = activity.object as VideoObject | 55 | const videoToCreateData = activity.object as VideoObject |
56 | 56 | ||
57 | const syncParam = { likes: false, dislikes: false, shares: false, comments: false, thumbnail: true, refreshVideo: false } | 57 | const syncParam = { likes: false, dislikes: false, shares: false, comments: false, thumbnail: true, refreshVideo: false } |
58 | const { video, created } = await getOrCreateVideoAndAccountAndChannel({ videoObject: videoToCreateData, syncParam }) | 58 | const { video, created } = await getOrCreateAPVideo({ videoObject: videoToCreateData, syncParam }) |
59 | 59 | ||
60 | if (created && notify) Notifier.Instance.notifyOnNewVideoIfNeeded(video) | 60 | if (created && notify) Notifier.Instance.notifyOnNewVideoIfNeeded(video) |
61 | 61 | ||
@@ -67,7 +67,7 @@ async function processCreateCacheFile (activity: ActivityCreate, byActor: MActor | |||
67 | 67 | ||
68 | const cacheFile = activity.object as CacheFileObject | 68 | const cacheFile = activity.object as CacheFileObject |
69 | 69 | ||
70 | const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: cacheFile.object }) | 70 | const { video } = await getOrCreateAPVideo({ videoObject: cacheFile.object }) |
71 | 71 | ||
72 | await sequelizeTypescript.transaction(async t => { | 72 | await sequelizeTypescript.transaction(async t => { |
73 | return createOrUpdateCacheFile(cacheFile, video, byActor, t) | 73 | return createOrUpdateCacheFile(cacheFile, video, byActor, t) |
diff --git a/server/lib/activitypub/process/process-dislike.ts b/server/lib/activitypub/process/process-dislike.ts index 089c7b881..ecc57cd10 100644 --- a/server/lib/activitypub/process/process-dislike.ts +++ b/server/lib/activitypub/process/process-dislike.ts | |||
@@ -6,7 +6,7 @@ import { AccountVideoRateModel } from '../../../models/account/account-video-rat | |||
6 | import { APProcessorOptions } from '../../../types/activitypub-processor.model' | 6 | import { APProcessorOptions } from '../../../types/activitypub-processor.model' |
7 | import { MActorSignature } from '../../../types/models' | 7 | import { MActorSignature } from '../../../types/models' |
8 | import { forwardVideoRelatedActivity } from '../send/utils' | 8 | import { forwardVideoRelatedActivity } from '../send/utils' |
9 | import { getOrCreateVideoAndAccountAndChannel } from '../videos' | 9 | import { getOrCreateAPVideo } from '../videos' |
10 | 10 | ||
11 | async function processDislikeActivity (options: APProcessorOptions<ActivityCreate | ActivityDislike>) { | 11 | async function processDislikeActivity (options: APProcessorOptions<ActivityCreate | ActivityDislike>) { |
12 | const { activity, byActor } = options | 12 | const { activity, byActor } = options |
@@ -30,7 +30,7 @@ async function processDislike (activity: ActivityCreate | ActivityDislike, byAct | |||
30 | 30 | ||
31 | if (!byAccount) throw new Error('Cannot create dislike with the non account actor ' + byActor.url) | 31 | if (!byAccount) throw new Error('Cannot create dislike with the non account actor ' + byActor.url) |
32 | 32 | ||
33 | const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: dislikeObject }) | 33 | const { video } = await getOrCreateAPVideo({ videoObject: dislikeObject }) |
34 | 34 | ||
35 | return sequelizeTypescript.transaction(async t => { | 35 | return sequelizeTypescript.transaction(async t => { |
36 | const existingRate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byAccount.id, video.id, activity.id, t) | 36 | const existingRate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byAccount.id, video.id, activity.id, t) |
diff --git a/server/lib/activitypub/process/process-like.ts b/server/lib/activitypub/process/process-like.ts index 8688b3b47..cd4e86cbb 100644 --- a/server/lib/activitypub/process/process-like.ts +++ b/server/lib/activitypub/process/process-like.ts | |||
@@ -6,7 +6,7 @@ import { AccountVideoRateModel } from '../../../models/account/account-video-rat | |||
6 | import { APProcessorOptions } from '../../../types/activitypub-processor.model' | 6 | import { APProcessorOptions } from '../../../types/activitypub-processor.model' |
7 | import { MActorSignature } from '../../../types/models' | 7 | import { MActorSignature } from '../../../types/models' |
8 | import { forwardVideoRelatedActivity } from '../send/utils' | 8 | import { forwardVideoRelatedActivity } from '../send/utils' |
9 | import { getOrCreateVideoAndAccountAndChannel } from '../videos' | 9 | import { getOrCreateAPVideo } from '../videos' |
10 | 10 | ||
11 | async function processLikeActivity (options: APProcessorOptions<ActivityLike>) { | 11 | async function processLikeActivity (options: APProcessorOptions<ActivityLike>) { |
12 | const { activity, byActor } = options | 12 | const { activity, byActor } = options |
@@ -27,7 +27,7 @@ async function processLikeVideo (byActor: MActorSignature, activity: ActivityLik | |||
27 | const byAccount = byActor.Account | 27 | const byAccount = byActor.Account |
28 | if (!byAccount) throw new Error('Cannot create like with the non account actor ' + byActor.url) | 28 | if (!byAccount) throw new Error('Cannot create like with the non account actor ' + byActor.url) |
29 | 29 | ||
30 | const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: videoUrl }) | 30 | const { video } = await getOrCreateAPVideo({ videoObject: videoUrl }) |
31 | 31 | ||
32 | return sequelizeTypescript.transaction(async t => { | 32 | return sequelizeTypescript.transaction(async t => { |
33 | const existingRate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byAccount.id, video.id, activity.id, t) | 33 | const existingRate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byAccount.id, video.id, activity.id, t) |
diff --git a/server/lib/activitypub/process/process-undo.ts b/server/lib/activitypub/process/process-undo.ts index 9f031b528..fdb8dac24 100644 --- a/server/lib/activitypub/process/process-undo.ts +++ b/server/lib/activitypub/process/process-undo.ts | |||
@@ -11,7 +11,7 @@ import { VideoShareModel } from '../../../models/video/video-share' | |||
11 | import { APProcessorOptions } from '../../../types/activitypub-processor.model' | 11 | import { APProcessorOptions } from '../../../types/activitypub-processor.model' |
12 | import { MActorSignature } from '../../../types/models' | 12 | import { MActorSignature } from '../../../types/models' |
13 | import { forwardVideoRelatedActivity } from '../send/utils' | 13 | import { forwardVideoRelatedActivity } from '../send/utils' |
14 | import { getOrCreateVideoAndAccountAndChannel } from '../videos' | 14 | import { getOrCreateAPVideo } from '../videos' |
15 | 15 | ||
16 | async function processUndoActivity (options: APProcessorOptions<ActivityUndo>) { | 16 | async function processUndoActivity (options: APProcessorOptions<ActivityUndo>) { |
17 | const { activity, byActor } = options | 17 | const { activity, byActor } = options |
@@ -55,7 +55,7 @@ export { | |||
55 | async function processUndoLike (byActor: MActorSignature, activity: ActivityUndo) { | 55 | async function processUndoLike (byActor: MActorSignature, activity: ActivityUndo) { |
56 | const likeActivity = activity.object as ActivityLike | 56 | const likeActivity = activity.object as ActivityLike |
57 | 57 | ||
58 | const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: likeActivity.object }) | 58 | const { video } = await getOrCreateAPVideo({ videoObject: likeActivity.object }) |
59 | 59 | ||
60 | return sequelizeTypescript.transaction(async t => { | 60 | return sequelizeTypescript.transaction(async t => { |
61 | if (!byActor.Account) throw new Error('Unknown account ' + byActor.url) | 61 | if (!byActor.Account) throw new Error('Unknown account ' + byActor.url) |
@@ -80,7 +80,7 @@ async function processUndoDislike (byActor: MActorSignature, activity: ActivityU | |||
80 | ? activity.object | 80 | ? activity.object |
81 | : activity.object.object as DislikeObject | 81 | : activity.object.object as DislikeObject |
82 | 82 | ||
83 | const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: dislike.object }) | 83 | const { video } = await getOrCreateAPVideo({ videoObject: dislike.object }) |
84 | 84 | ||
85 | return sequelizeTypescript.transaction(async t => { | 85 | return sequelizeTypescript.transaction(async t => { |
86 | if (!byActor.Account) throw new Error('Unknown account ' + byActor.url) | 86 | if (!byActor.Account) throw new Error('Unknown account ' + byActor.url) |
@@ -103,7 +103,7 @@ async function processUndoDislike (byActor: MActorSignature, activity: ActivityU | |||
103 | async function processUndoCacheFile (byActor: MActorSignature, activity: ActivityUndo) { | 103 | async function processUndoCacheFile (byActor: MActorSignature, activity: ActivityUndo) { |
104 | const cacheFileObject = activity.object.object as CacheFileObject | 104 | const cacheFileObject = activity.object.object as CacheFileObject |
105 | 105 | ||
106 | const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: cacheFileObject.object }) | 106 | const { video } = await getOrCreateAPVideo({ videoObject: cacheFileObject.object }) |
107 | 107 | ||
108 | return sequelizeTypescript.transaction(async t => { | 108 | return sequelizeTypescript.transaction(async t => { |
109 | const cacheFile = await VideoRedundancyModel.loadByUrl(cacheFileObject.id) | 109 | const cacheFile = await VideoRedundancyModel.loadByUrl(cacheFileObject.id) |
diff --git a/server/lib/activitypub/process/process-update.ts b/server/lib/activitypub/process/process-update.ts index 516bd8d70..be3f6acac 100644 --- a/server/lib/activitypub/process/process-update.ts +++ b/server/lib/activitypub/process/process-update.ts | |||
@@ -17,7 +17,7 @@ import { getImageInfoIfExists, updateActorImageInstance, updateActorInstance } f | |||
17 | import { createOrUpdateCacheFile } from '../cache-file' | 17 | import { createOrUpdateCacheFile } from '../cache-file' |
18 | import { createOrUpdateVideoPlaylist } from '../playlist' | 18 | import { createOrUpdateVideoPlaylist } from '../playlist' |
19 | import { forwardVideoRelatedActivity } from '../send/utils' | 19 | import { forwardVideoRelatedActivity } from '../send/utils' |
20 | import { APVideoUpdater, getOrCreateVideoAndAccountAndChannel } from '../videos' | 20 | import { APVideoUpdater, getOrCreateAPVideo } from '../videos' |
21 | 21 | ||
22 | async function processUpdateActivity (options: APProcessorOptions<ActivityUpdate>) { | 22 | async function processUpdateActivity (options: APProcessorOptions<ActivityUpdate>) { |
23 | const { activity, byActor } = options | 23 | const { activity, byActor } = options |
@@ -63,7 +63,7 @@ async function processUpdateVideo (activity: ActivityUpdate) { | |||
63 | return undefined | 63 | return undefined |
64 | } | 64 | } |
65 | 65 | ||
66 | const { video, created } = await getOrCreateVideoAndAccountAndChannel({ | 66 | const { video, created } = await getOrCreateAPVideo({ |
67 | videoObject: videoObject.id, | 67 | videoObject: videoObject.id, |
68 | allowRefresh: false, | 68 | allowRefresh: false, |
69 | fetchType: 'all' | 69 | fetchType: 'all' |
@@ -85,7 +85,7 @@ async function processUpdateCacheFile (byActor: MActorSignature, activity: Activ | |||
85 | return undefined | 85 | return undefined |
86 | } | 86 | } |
87 | 87 | ||
88 | const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: cacheFileObject.object }) | 88 | const { video } = await getOrCreateAPVideo({ videoObject: cacheFileObject.object }) |
89 | 89 | ||
90 | await sequelizeTypescript.transaction(async t => { | 90 | await sequelizeTypescript.transaction(async t => { |
91 | await createOrUpdateCacheFile(cacheFileObject, video, byActor, t) | 91 | await createOrUpdateCacheFile(cacheFileObject, video, byActor, t) |
diff --git a/server/lib/activitypub/process/process-view.ts b/server/lib/activitypub/process/process-view.ts index 84697673b..c2d41dd28 100644 --- a/server/lib/activitypub/process/process-view.ts +++ b/server/lib/activitypub/process/process-view.ts | |||
@@ -1,4 +1,4 @@ | |||
1 | import { getOrCreateVideoAndAccountAndChannel } from '../videos' | 1 | import { getOrCreateAPVideo } from '../videos' |
2 | import { forwardVideoRelatedActivity } from '../send/utils' | 2 | import { forwardVideoRelatedActivity } from '../send/utils' |
3 | import { Redis } from '../../redis' | 3 | import { Redis } from '../../redis' |
4 | import { ActivityCreate, ActivityView, ViewObject } from '../../../../shared/models/activitypub' | 4 | import { ActivityCreate, ActivityView, ViewObject } from '../../../../shared/models/activitypub' |
@@ -29,7 +29,7 @@ async function processCreateView (activity: ActivityView | ActivityCreate, byAct | |||
29 | fetchType: 'only-video' as 'only-video', | 29 | fetchType: 'only-video' as 'only-video', |
30 | allowRefresh: false as false | 30 | allowRefresh: false as false |
31 | } | 31 | } |
32 | const { video } = await getOrCreateVideoAndAccountAndChannel(options) | 32 | const { video } = await getOrCreateAPVideo(options) |
33 | 33 | ||
34 | if (!video.isLive) { | 34 | if (!video.isLive) { |
35 | await Redis.Instance.addVideoView(video.id) | 35 | await Redis.Instance.addVideoView(video.id) |