diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/helpers/custom-validators/activitypub/actor.ts | 21 | ||||
-rw-r--r-- | server/helpers/custom-validators/activitypub/video-comments.ts | 2 | ||||
-rw-r--r-- | server/lib/activitypub/actor.ts | 26 | ||||
-rw-r--r-- | server/lib/activitypub/videos.ts | 3 |
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 @@ | |||
1 | import * as validator from 'validator' | 1 | import * as validator from 'validator' |
2 | import { CONSTRAINTS_FIELDS } from '../../../initializers' | 2 | import { CONSTRAINTS_FIELDS } from '../../../initializers' |
3 | import { normalizeActor } from '../../../lib/activitypub' | ||
4 | import { exists } from '../misc' | 3 | import { exists } from '../misc' |
4 | import { truncate } from 'lodash' | ||
5 | import { isActivityPubUrlValid, isBaseActivityValid, setValidAttributedTo } from './misc' | 5 | import { isActivityPubUrlValid, isBaseActivityValid, setValidAttributedTo } from './misc' |
6 | 6 | ||
7 | function isActorEndpointsObjectValid (endpointObject: any) { | 7 | function isActorEndpointsObjectValid (endpointObject: any) { |
@@ -91,9 +91,28 @@ function isActorUpdateActivityValid (activity: any) { | |||
91 | isActorObjectValid(activity.object) | 91 | isActorObjectValid(activity.object) |
92 | } | 92 | } |
93 | 93 | ||
94 | function 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 | ||
96 | export { | 114 | export { |
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) { | |||
46 | function normalizeComment (comment: any) { | 46 | function 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' | |||
6 | import { ActivityPubActor, ActivityPubActorType } from '../../../shared/models/activitypub' | 6 | import { ActivityPubActor, ActivityPubActorType } from '../../../shared/models/activitypub' |
7 | import { ActivityPubAttributedTo } from '../../../shared/models/activitypub/objects' | 7 | import { ActivityPubAttributedTo } from '../../../shared/models/activitypub/objects' |
8 | import { getActorUrl } from '../../helpers/activitypub' | 8 | import { getActorUrl } from '../../helpers/activitypub' |
9 | import { isActorObjectValid } from '../../helpers/custom-validators/activitypub/actor' | 9 | import { isActorObjectValid, normalizeActor } from '../../helpers/custom-validators/activitypub/actor' |
10 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' | 10 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' |
11 | import { retryTransactionWrapper, updateInstanceWithAnother } from '../../helpers/database-utils' | 11 | import { retryTransactionWrapper, updateInstanceWithAnother } from '../../helpers/database-utils' |
12 | import { logger } from '../../helpers/logger' | 12 | import { logger } from '../../helpers/logger' |
13 | import { createPrivateAndPublicKeys } from '../../helpers/peertube-crypto' | 13 | import { createPrivateAndPublicKeys } from '../../helpers/peertube-crypto' |
14 | import { doRequest, doRequestAndSaveToFile } from '../../helpers/requests' | 14 | import { doRequest, doRequestAndSaveToFile } from '../../helpers/requests' |
15 | import { getUrlFromWebfinger } from '../../helpers/webfinger' | 15 | import { getUrlFromWebfinger } from '../../helpers/webfinger' |
16 | import { IMAGE_MIMETYPE_EXT, CONFIG, sequelizeTypescript, CONSTRAINTS_FIELDS } from '../../initializers' | 16 | import { CONFIG, IMAGE_MIMETYPE_EXT, sequelizeTypescript } from '../../initializers' |
17 | import { AccountModel } from '../../models/account/account' | 17 | import { AccountModel } from '../../models/account/account' |
18 | import { ActorModel } from '../../models/activitypub/actor' | 18 | import { ActorModel } from '../../models/activitypub/actor' |
19 | import { AvatarModel } from '../../models/avatar/avatar' | 19 | import { AvatarModel } from '../../models/avatar/avatar' |
20 | import { ServerModel } from '../../models/server/server' | 20 | import { ServerModel } from '../../models/server/server' |
21 | import { VideoChannelModel } from '../../models/video/video-channel' | 21 | import { VideoChannelModel } from '../../models/video/video-channel' |
22 | import { 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 |
25 | function setAsyncActorKeys (actor: ActorModel) { | 24 | function setAsyncActorKeys (actor: ActorModel) { |
@@ -170,24 +169,6 @@ async function fetchAvatarIfExists (actorJSON: ActivityPubActor) { | |||
170 | return undefined | 169 | return undefined |
171 | } | 170 | } |
172 | 171 | ||
173 | function 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 | |||
191 | export { | 172 | export { |
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 | ||