aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/process/process-create.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-06-13 14:27:40 +0200
committerChocobozzz <me@florianbigard.com>2018-06-13 14:27:40 +0200
commit90d4bb8125e80c8060416d4d135ddeaf0a622ede (patch)
treeb3b7181329a08ecc930b54fe7b48095c4155393c /server/lib/activitypub/process/process-create.ts
parent3cd0734fd9b0ff21aaef02317a874e8f1c06e027 (diff)
downloadPeerTube-90d4bb8125e80c8060416d4d135ddeaf0a622ede.tar.gz
PeerTube-90d4bb8125e80c8060416d4d135ddeaf0a622ede.tar.zst
PeerTube-90d4bb8125e80c8060416d4d135ddeaf0a622ede.zip
Refractor retry transaction function
Diffstat (limited to 'server/lib/activitypub/process/process-create.ts')
-rw-r--r--server/lib/activitypub/process/process-create.ts37
1 files changed, 5 insertions, 32 deletions
diff --git a/server/lib/activitypub/process/process-create.ts b/server/lib/activitypub/process/process-create.ts
index 38dacf772..6364bf135 100644
--- a/server/lib/activitypub/process/process-create.ts
+++ b/server/lib/activitypub/process/process-create.ts
@@ -21,13 +21,13 @@ async function processCreateActivity (activity: ActivityCreate) {
21 if (activityType === 'View') { 21 if (activityType === 'View') {
22 return processCreateView(actor, activity) 22 return processCreateView(actor, activity)
23 } else if (activityType === 'Dislike') { 23 } else if (activityType === 'Dislike') {
24 return processCreateDislike(actor, activity) 24 return retryTransactionWrapper(processCreateDislike, actor, activity)
25 } else if (activityType === 'Video') { 25 } else if (activityType === 'Video') {
26 return processCreateVideo(actor, activity) 26 return processCreateVideo(actor, activity)
27 } else if (activityType === 'Flag') { 27 } else if (activityType === 'Flag') {
28 return processCreateVideoAbuse(actor, activityObject as VideoAbuseObject) 28 return retryTransactionWrapper(processCreateVideoAbuse, actor, activityObject as VideoAbuseObject)
29 } else if (activityType === 'Note') { 29 } else if (activityType === 'Note') {
30 return processCreateVideoComment(actor, activity) 30 return retryTransactionWrapper(processCreateVideoComment, actor, activity)
31 } 31 }
32 32
33 logger.warn('Unknown activity object type %s when creating activity.', activityType, { activity: activity.id }) 33 logger.warn('Unknown activity object type %s when creating activity.', activityType, { activity: activity.id })
@@ -54,15 +54,6 @@ async function processCreateVideo (
54} 54}
55 55
56async function processCreateDislike (byActor: ActorModel, activity: ActivityCreate) { 56async function processCreateDislike (byActor: ActorModel, activity: ActivityCreate) {
57 const options = {
58 arguments: [ byActor, activity ],
59 errorMessage: 'Cannot dislike the video with many retries.'
60 }
61
62 return retryTransactionWrapper(createVideoDislike, options)
63}
64
65async function createVideoDislike (byActor: ActorModel, activity: ActivityCreate) {
66 const dislike = activity.object as DislikeObject 57 const dislike = activity.object as DislikeObject
67 const byAccount = byActor.Account 58 const byAccount = byActor.Account
68 59
@@ -109,16 +100,7 @@ async function processCreateView (byActor: ActorModel, activity: ActivityCreate)
109 } 100 }
110} 101}
111 102
112function processCreateVideoAbuse (actor: ActorModel, videoAbuseToCreateData: VideoAbuseObject) { 103async function processCreateVideoAbuse (actor: ActorModel, videoAbuseToCreateData: VideoAbuseObject) {
113 const options = {
114 arguments: [ actor, videoAbuseToCreateData ],
115 errorMessage: 'Cannot insert the remote video abuse with many retries.'
116 }
117
118 return retryTransactionWrapper(addRemoteVideoAbuse, options)
119}
120
121async function addRemoteVideoAbuse (actor: ActorModel, videoAbuseToCreateData: VideoAbuseObject) {
122 logger.debug('Reporting remote abuse for video %s.', videoAbuseToCreateData.object) 104 logger.debug('Reporting remote abuse for video %s.', videoAbuseToCreateData.object)
123 105
124 const account = actor.Account 106 const account = actor.Account
@@ -139,16 +121,7 @@ async function addRemoteVideoAbuse (actor: ActorModel, videoAbuseToCreateData: V
139 }) 121 })
140} 122}
141 123
142function processCreateVideoComment (byActor: ActorModel, activity: ActivityCreate) { 124async function processCreateVideoComment (byActor: ActorModel, activity: ActivityCreate) {
143 const options = {
144 arguments: [ byActor, activity ],
145 errorMessage: 'Cannot create video comment with many retries.'
146 }
147
148 return retryTransactionWrapper(createVideoComment, options)
149}
150
151async function createVideoComment (byActor: ActorModel, activity: ActivityCreate) {
152 const comment = activity.object as VideoCommentObject 125 const comment = activity.object as VideoCommentObject
153 const byAccount = byActor.Account 126 const byAccount = byActor.Account
154 127