aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--server/helpers/custom-validators/activitypub/actor.ts21
-rw-r--r--server/helpers/custom-validators/activitypub/video-comments.ts2
-rw-r--r--server/lib/activitypub/actor.ts26
-rw-r--r--server/lib/activitypub/videos.ts3
4 files changed, 26 insertions, 26 deletions
diff --git a/server/helpers/custom-validators/activitypub/actor.ts b/server/helpers/custom-validators/activitypub/actor.ts
index 9908be4d3..9a0bb32c1 100644
--- a/server/helpers/custom-validators/activitypub/actor.ts
+++ b/server/helpers/custom-validators/activitypub/actor.ts
@@ -1,7 +1,7 @@
1import * as validator from 'validator' 1import * as validator from 'validator'
2import { CONSTRAINTS_FIELDS } from '../../../initializers' 2import { CONSTRAINTS_FIELDS } from '../../../initializers'
3import { normalizeActor } from '../../../lib/activitypub'
4import { exists } from '../misc' 3import { exists } from '../misc'
4import { truncate } from 'lodash'
5import { isActivityPubUrlValid, isBaseActivityValid, setValidAttributedTo } from './misc' 5import { isActivityPubUrlValid, isBaseActivityValid, setValidAttributedTo } from './misc'
6 6
7function isActorEndpointsObjectValid (endpointObject: any) { 7function isActorEndpointsObjectValid (endpointObject: any) {
@@ -91,9 +91,28 @@ function isActorUpdateActivityValid (activity: any) {
91 isActorObjectValid(activity.object) 91 isActorObjectValid(activity.object)
92} 92}
93 93
94function normalizeActor (actor: any) {
95 if (!actor) return
96
97 if (typeof actor.url !== 'string') {
98 actor.url = actor.url.href || actor.url.url
99 }
100
101 if (actor.summary && typeof actor.summary === 'string') {
102 actor.summary = truncate(actor.summary, { length: CONSTRAINTS_FIELDS.USERS.DESCRIPTION.max })
103
104 if (actor.summary.length < CONSTRAINTS_FIELDS.USERS.DESCRIPTION.min) {
105 actor.summary = null
106 }
107 }
108
109 return
110}
111
94// --------------------------------------------------------------------------- 112// ---------------------------------------------------------------------------
95 113
96export { 114export {
115 normalizeActor,
97 isActorEndpointsObjectValid, 116 isActorEndpointsObjectValid,
98 isActorPublicKeyObjectValid, 117 isActorPublicKeyObjectValid,
99 isActorTypeValid, 118 isActorTypeValid,
diff --git a/server/helpers/custom-validators/activitypub/video-comments.ts b/server/helpers/custom-validators/activitypub/video-comments.ts
index 151d13075..7a9f7326d 100644
--- a/server/helpers/custom-validators/activitypub/video-comments.ts
+++ b/server/helpers/custom-validators/activitypub/video-comments.ts
@@ -46,7 +46,7 @@ function isCommentContentValid (content: any) {
46function normalizeComment (comment: any) { 46function normalizeComment (comment: any) {
47 if (!comment) return 47 if (!comment) return
48 48
49 if (!comment.url || typeof comment.url !== 'string') { 49 if (typeof comment.url !== 'string') {
50 comment.url = comment.url.href || comment.url.url 50 comment.url = comment.url.href || comment.url.url
51 } 51 }
52 52
diff --git a/server/lib/activitypub/actor.ts b/server/lib/activitypub/actor.ts
index 5773fc34f..4c336f26e 100644
--- a/server/lib/activitypub/actor.ts
+++ b/server/lib/activitypub/actor.ts
@@ -6,20 +6,19 @@ import * as uuidv4 from 'uuid/v4'
6import { ActivityPubActor, ActivityPubActorType } from '../../../shared/models/activitypub' 6import { ActivityPubActor, ActivityPubActorType } from '../../../shared/models/activitypub'
7import { ActivityPubAttributedTo } from '../../../shared/models/activitypub/objects' 7import { ActivityPubAttributedTo } from '../../../shared/models/activitypub/objects'
8import { getActorUrl } from '../../helpers/activitypub' 8import { getActorUrl } from '../../helpers/activitypub'
9import { isActorObjectValid } from '../../helpers/custom-validators/activitypub/actor' 9import { isActorObjectValid, normalizeActor } from '../../helpers/custom-validators/activitypub/actor'
10import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' 10import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
11import { retryTransactionWrapper, updateInstanceWithAnother } from '../../helpers/database-utils' 11import { retryTransactionWrapper, updateInstanceWithAnother } from '../../helpers/database-utils'
12import { logger } from '../../helpers/logger' 12import { logger } from '../../helpers/logger'
13import { createPrivateAndPublicKeys } from '../../helpers/peertube-crypto' 13import { createPrivateAndPublicKeys } from '../../helpers/peertube-crypto'
14import { doRequest, doRequestAndSaveToFile } from '../../helpers/requests' 14import { doRequest, doRequestAndSaveToFile } from '../../helpers/requests'
15import { getUrlFromWebfinger } from '../../helpers/webfinger' 15import { getUrlFromWebfinger } from '../../helpers/webfinger'
16import { IMAGE_MIMETYPE_EXT, CONFIG, sequelizeTypescript, CONSTRAINTS_FIELDS } from '../../initializers' 16import { CONFIG, IMAGE_MIMETYPE_EXT, sequelizeTypescript } from '../../initializers'
17import { AccountModel } from '../../models/account/account' 17import { AccountModel } from '../../models/account/account'
18import { ActorModel } from '../../models/activitypub/actor' 18import { ActorModel } from '../../models/activitypub/actor'
19import { AvatarModel } from '../../models/avatar/avatar' 19import { AvatarModel } from '../../models/avatar/avatar'
20import { ServerModel } from '../../models/server/server' 20import { ServerModel } from '../../models/server/server'
21import { VideoChannelModel } from '../../models/video/video-channel' 21import { VideoChannelModel } from '../../models/video/video-channel'
22import { truncate } from 'lodash'
23 22
24// Set account keys, this could be long so process after the account creation and do not block the client 23// Set account keys, this could be long so process after the account creation and do not block the client
25function setAsyncActorKeys (actor: ActorModel) { 24function setAsyncActorKeys (actor: ActorModel) {
@@ -170,24 +169,6 @@ async function fetchAvatarIfExists (actorJSON: ActivityPubActor) {
170 return undefined 169 return undefined
171} 170}
172 171
173function normalizeActor (actor: any) {
174 if (!actor) return
175
176 if (!actor.url || typeof actor.url !== 'string') {
177 actor.url = actor.url.href || actor.url.url
178 }
179
180 if (actor.summary && typeof actor.summary === 'string') {
181 actor.summary = truncate(actor.summary, { length: CONSTRAINTS_FIELDS.USERS.DESCRIPTION.max })
182
183 if (actor.summary.length < CONSTRAINTS_FIELDS.USERS.DESCRIPTION.min) {
184 actor.summary = null
185 }
186 }
187
188 return
189}
190
191export { 172export {
192 getOrCreateActorAndServerAndModel, 173 getOrCreateActorAndServerAndModel,
193 buildActorInstance, 174 buildActorInstance,
@@ -195,8 +176,7 @@ export {
195 fetchActorTotalItems, 176 fetchActorTotalItems,
196 fetchAvatarIfExists, 177 fetchAvatarIfExists,
197 updateActorInstance, 178 updateActorInstance,
198 updateActorAvatarInstance, 179 updateActorAvatarInstance
199 normalizeActor
200} 180}
201 181
202// --------------------------------------------------------------------------- 182// ---------------------------------------------------------------------------
diff --git a/server/lib/activitypub/videos.ts b/server/lib/activitypub/videos.ts
index 2899acff3..dbd7385a4 100644
--- a/server/lib/activitypub/videos.ts
+++ b/server/lib/activitypub/videos.ts
@@ -306,7 +306,8 @@ export {
306 videoFileActivityUrlToDBAttributes, 306 videoFileActivityUrlToDBAttributes,
307 getOrCreateVideo, 307 getOrCreateVideo,
308 getOrCreateVideoChannel, 308 getOrCreateVideoChannel,
309 addVideoShares} 309 addVideoShares
310}
310 311
311// --------------------------------------------------------------------------- 312// ---------------------------------------------------------------------------
312 313