From: Chocobozzz Date: Tue, 19 Dec 2017 16:07:58 +0000 (+0100) Subject: Handle mastodon shares X-Git-Tag: v0.0.1-alpha~110 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=d7a7c248b36af5f9cf7375ba62720e4a1530eca6;p=oweals%2Fpeertube.git Handle mastodon shares --- diff --git a/server/helpers/custom-validators/activitypub/announce.ts b/server/helpers/custom-validators/activitypub/announce.ts index 80511129c..469ed5127 100644 --- a/server/helpers/custom-validators/activitypub/announce.ts +++ b/server/helpers/custom-validators/activitypub/announce.ts @@ -1,9 +1,11 @@ -import { isBaseActivityValid } from './misc' +import { isActivityPubUrlValid, isBaseActivityValid } from './misc' import { isVideoTorrentCreateActivityValid } from './videos' function isAnnounceActivityValid (activity: any) { + console.log(activity) return isBaseActivityValid(activity, 'Announce') && ( + isActivityPubUrlValid(activity.object) || isVideoTorrentCreateActivityValid(activity.object) ) } diff --git a/server/lib/activitypub/process/process-announce.ts b/server/lib/activitypub/process/process-announce.ts index 7dfee2f60..5568ff538 100644 --- a/server/lib/activitypub/process/process-announce.ts +++ b/server/lib/activitypub/process/process-announce.ts @@ -1,4 +1,4 @@ -import { ActivityAnnounce } from '../../../../shared/models/activitypub' +import { ActivityAnnounce, ActivityCreate } from '../../../../shared/models/activitypub' import { logger, retryTransactionWrapper } from '../../../helpers' import { sequelizeTypescript } from '../../../initializers' import { ActorModel } from '../../../models/activitypub/actor' @@ -12,7 +12,9 @@ async function processAnnounceActivity (activity: ActivityAnnounce) { const announcedActivity = activity.object const actorAnnouncer = await getOrCreateActorAndServerAndModel(activity.actor) - if (announcedActivity.type === 'Create' && announcedActivity.object.type === 'Video') { + if (typeof announcedActivity === 'string') { + return processVideoShare(actorAnnouncer, activity) + } else if (announcedActivity.type === 'Create' && announcedActivity.object.type === 'Video') { return processVideoShare(actorAnnouncer, activity) } @@ -35,18 +37,25 @@ export { function processVideoShare (actorAnnouncer: ActorModel, activity: ActivityAnnounce) { const options = { arguments: [ actorAnnouncer, activity ], - errorMessage: 'Cannot share the video with many retries.' + errorMessage: 'Cannot share the video activity with many retries.' } return retryTransactionWrapper(shareVideo, options) } function shareVideo (actorAnnouncer: ActorModel, activity: ActivityAnnounce) { - const announcedActivity = activity.object + const announced = activity.object return sequelizeTypescript.transaction(async t => { // Add share entry - const video: VideoModel = await processCreateActivity(announcedActivity) + let video: VideoModel + + if (typeof announced === 'string') { + video = await VideoModel.loadByUrlAndPopulateAccount(announced as string) + if (!video) throw new Error('Unknown video to share ' + announced) + } else { + video = await processCreateActivity(announced as ActivityCreate) + } const share = { actorId: actorAnnouncer.id, diff --git a/shared/models/activitypub/activity.ts b/shared/models/activitypub/activity.ts index 84f5d851f..d5359eba1 100644 --- a/shared/models/activitypub/activity.ts +++ b/shared/models/activitypub/activity.ts @@ -51,7 +51,7 @@ export interface ActivityAccept extends BaseActivity { export interface ActivityAnnounce extends BaseActivity { type: 'Announce' - object: ActivityCreate + object: ActivityCreate | string } export interface ActivityUndo extends BaseActivity {