aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/process-delete.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-11-13 17:39:41 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-11-27 19:40:51 +0100
commit7a7724e66e4533523083e7336cd0d0c747c4a33b (patch)
tree805299eb9c6829158cd17e5a823a84a3a54d8209 /server/lib/activitypub/process-delete.ts
parent571389d43b8fc8aaf27e77c06f19b320b08dbbc9 (diff)
downloadPeerTube-7a7724e66e4533523083e7336cd0d0c747c4a33b.tar.gz
PeerTube-7a7724e66e4533523083e7336cd0d0c747c4a33b.tar.zst
PeerTube-7a7724e66e4533523083e7336cd0d0c747c4a33b.zip
Handle follow/accept
Diffstat (limited to 'server/lib/activitypub/process-delete.ts')
-rw-r--r--server/lib/activitypub/process-delete.ts105
1 files changed, 105 insertions, 0 deletions
diff --git a/server/lib/activitypub/process-delete.ts b/server/lib/activitypub/process-delete.ts
new file mode 100644
index 000000000..377df432d
--- /dev/null
+++ b/server/lib/activitypub/process-delete.ts
@@ -0,0 +1,105 @@
1import { ActivityDelete } from '../../../shared/models/activitypub/activity'
2import { getOrCreateAccount } from '../../helpers/activitypub'
3import { retryTransactionWrapper } from '../../helpers/database-utils'
4import { logger } from '../../helpers/logger'
5import { database as db } from '../../initializers'
6import { AccountInstance } from '../../models/account/account-interface'
7import { VideoChannelInstance } from '../../models/video/video-channel-interface'
8import { VideoInstance } from '../../models/video/video-interface'
9
10async function processDeleteActivity (activity: ActivityDelete) {
11 const account = await getOrCreateAccount(activity.actor)
12
13 if (account.url === activity.id) {
14 return processDeleteAccount(account)
15 }
16
17 {
18 let videoObject = await db.Video.loadByUrl(activity.id)
19 if (videoObject !== undefined) {
20 return processDeleteVideo(account, videoObject)
21 }
22 }
23
24 {
25 let videoChannelObject = await db.VideoChannel.loadByUrl(activity.id)
26 if (videoChannelObject !== undefined) {
27 return processDeleteVideoChannel(account, videoChannelObject)
28 }
29 }
30
31 return undefined
32}
33
34// ---------------------------------------------------------------------------
35
36export {
37 processDeleteActivity
38}
39
40// ---------------------------------------------------------------------------
41
42async function processDeleteVideo (account: AccountInstance, videoToDelete: VideoInstance) {
43 const options = {
44 arguments: [ account, videoToDelete ],
45 errorMessage: 'Cannot remove the remote video with many retries.'
46 }
47
48 await retryTransactionWrapper(deleteRemoteVideo, options)
49}
50
51async function deleteRemoteVideo (account: AccountInstance, videoToDelete: VideoInstance) {
52 logger.debug('Removing remote video "%s".', videoToDelete.uuid)
53
54 await db.sequelize.transaction(async t => {
55 if (videoToDelete.VideoChannel.Account.id !== account.id) {
56 throw new Error('Account ' + account.url + ' does not own video channel ' + videoToDelete.VideoChannel.url)
57 }
58
59 await videoToDelete.destroy({ transaction: t })
60 })
61
62 logger.info('Remote video with uuid %s removed.', videoToDelete.uuid)
63}
64
65async function processDeleteVideoChannel (account: AccountInstance, videoChannelToRemove: VideoChannelInstance) {
66 const options = {
67 arguments: [ account, videoChannelToRemove ],
68 errorMessage: 'Cannot remove the remote video channel with many retries.'
69 }
70
71 await retryTransactionWrapper(deleteRemoteVideoChannel, options)
72}
73
74async function deleteRemoteVideoChannel (account: AccountInstance, videoChannelToRemove: VideoChannelInstance) {
75 logger.debug('Removing remote video channel "%s".', videoChannelToRemove.uuid)
76
77 await db.sequelize.transaction(async t => {
78 if (videoChannelToRemove.Account.id !== account.id) {
79 throw new Error('Account ' + account.url + ' does not own video channel ' + videoChannelToRemove.url)
80 }
81
82 await videoChannelToRemove.destroy({ transaction: t })
83 })
84
85 logger.info('Remote video channel with uuid %s removed.', videoChannelToRemove.uuid)
86}
87
88async function processDeleteAccount (accountToRemove: AccountInstance) {
89 const options = {
90 arguments: [ accountToRemove ],
91 errorMessage: 'Cannot remove the remote account with many retries.'
92 }
93
94 await retryTransactionWrapper(deleteRemoteAccount, options)
95}
96
97async function deleteRemoteAccount (accountToRemove: AccountInstance) {
98 logger.debug('Removing remote account "%s".', accountToRemove.uuid)
99
100 await db.sequelize.transaction(async t => {
101 await accountToRemove.destroy({ transaction: t })
102 })
103
104 logger.info('Remote account with uuid %s removed.', accountToRemove.uuid)
105}