From de94ac86a211dec657332d964693857ec235ce40 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 20 Nov 2020 11:21:08 +0100 Subject: Fix incorrect IDs in AP federation --- server/models/account/account-video-rate.ts | 3 ++- server/models/activitypub/actor-follow.ts | 36 +++++++++++++++++++---------- server/models/video/video-format-utils.ts | 16 ++++++------- 3 files changed, 34 insertions(+), 21 deletions(-) (limited to 'server/models') diff --git a/server/models/account/account-video-rate.ts b/server/models/account/account-video-rate.ts index 5064987dc..6955f45ee 100644 --- a/server/models/account/account-video-rate.ts +++ b/server/models/account/account-video-rate.ts @@ -168,7 +168,8 @@ export class AccountVideoRateModel extends Model { model: ActorModel.unscoped(), required: true, where: { - preferredUsername: accountName + preferredUsername: accountName, + serverId: null } } ] diff --git a/server/models/activitypub/actor-follow.ts b/server/models/activitypub/actor-follow.ts index 10c13304f..58bc63d34 100644 --- a/server/models/activitypub/actor-follow.ts +++ b/server/models/activitypub/actor-follow.ts @@ -1,5 +1,6 @@ import * as Bluebird from 'bluebird' import { difference, values } from 'lodash' +import { IncludeOptions, Op, QueryTypes, Transaction, WhereOptions } from 'sequelize' import { AfterCreate, AfterDestroy, @@ -11,22 +12,16 @@ import { DataType, Default, ForeignKey, + Is, IsInt, Max, Model, Table, UpdatedAt } from 'sequelize-typescript' -import { FollowState } from '../../../shared/models/actors' -import { ActorFollow } from '../../../shared/models/actors/follow.model' -import { logger } from '../../helpers/logger' -import { ACTOR_FOLLOW_SCORE, FOLLOW_STATES, SERVER_ACTOR_NAME } from '../../initializers/constants' -import { ServerModel } from '../server/server' -import { createSafeIn, getFollowsSort, getSort, searchAttribute } from '../utils' -import { ActorModel, unusedActorAttributesForAPI } from './actor' -import { VideoChannelModel } from '../video/video-channel' -import { AccountModel } from '../account/account' -import { IncludeOptions, Op, QueryTypes, Transaction, WhereOptions } from 'sequelize' +import { isActivityPubUrlValid } from '@server/helpers/custom-validators/activitypub/misc' +import { getServerActor } from '@server/models/application/application' +import { VideoModel } from '@server/models/video/video' import { MActorFollowActorsDefault, MActorFollowActorsDefaultSubscription, @@ -35,8 +30,15 @@ import { MActorFollowSubscriptions } from '@server/types/models' import { ActivityPubActorType } from '@shared/models' -import { VideoModel } from '@server/models/video/video' -import { getServerActor } from '@server/models/application/application' +import { FollowState } from '../../../shared/models/actors' +import { ActorFollow } from '../../../shared/models/actors/follow.model' +import { logger } from '../../helpers/logger' +import { ACTOR_FOLLOW_SCORE, CONSTRAINTS_FIELDS, FOLLOW_STATES, SERVER_ACTOR_NAME } from '../../initializers/constants' +import { AccountModel } from '../account/account' +import { ServerModel } from '../server/server' +import { createSafeIn, getFollowsSort, getSort, searchAttribute, throwIfNotValid } from '../utils' +import { VideoChannelModel } from '../video/video-channel' +import { ActorModel, unusedActorAttributesForAPI } from './actor' @Table({ tableName: 'actorFollow', @@ -53,6 +55,10 @@ import { getServerActor } from '@server/models/application/application' }, { fields: [ 'score' ] + }, + { + fields: [ 'url' ], + unique: true } ] }) @@ -69,6 +75,12 @@ export class ActorFollowModel extends Model { @Column score: number + // Allow null because we added this column in PeerTube v3, and don't want to generate fake URLs of remote follows + @AllowNull(true) + @Is('ActorFollowUrl', value => throwIfNotValid(value, isActivityPubUrlValid, 'url')) + @Column(DataType.STRING(CONSTRAINTS_FIELDS.COMMONS.URL.max)) + url: string + @CreatedAt createdAt: Date diff --git a/server/models/video/video-format-utils.ts b/server/models/video/video-format-utils.ts index d4b213686..b1adbcb86 100644 --- a/server/models/video/video-format-utils.ts +++ b/server/models/video/video-format-utils.ts @@ -4,10 +4,10 @@ import { ActivityTagObject, ActivityUrlObject, VideoObject } from '../../../shar import { MIMETYPES, WEBSERVER } from '../../initializers/constants' import { VideoCaptionModel } from './video-caption' import { - getVideoCommentsActivityPubUrl, - getVideoDislikesActivityPubUrl, - getVideoLikesActivityPubUrl, - getVideoSharesActivityPubUrl + getLocalVideoCommentsActivityPubUrl, + getLocalVideoDislikesActivityPubUrl, + getLocalVideoLikesActivityPubUrl, + getLocalVideoSharesActivityPubUrl } from '../../lib/activitypub/url' import { isArray } from '../../helpers/custom-validators/misc' import { VideoStreamingPlaylist } from '../../../shared/models/videos/video-streaming-playlist.model' @@ -382,10 +382,10 @@ function videoModelToActivityPubObject (video: MVideoAP): VideoObject { height: i.height })), url, - likes: getVideoLikesActivityPubUrl(video), - dislikes: getVideoDislikesActivityPubUrl(video), - shares: getVideoSharesActivityPubUrl(video), - comments: getVideoCommentsActivityPubUrl(video), + likes: getLocalVideoLikesActivityPubUrl(video), + dislikes: getLocalVideoDislikesActivityPubUrl(video), + shares: getLocalVideoSharesActivityPubUrl(video), + comments: getLocalVideoCommentsActivityPubUrl(video), attributedTo: [ { type: 'Person', -- cgit v1.2.3