aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-05-11 15:55:39 +0200
committerChocobozzz <me@florianbigard.com>2018-05-11 15:55:39 +0200
commit938d3fa0ffb4cf3e4c88f94dcfcae5eb2ce5e190 (patch)
tree844768f122c8f06d1f90f006d9fdd0e2e4005aae /server/lib/activitypub
parent5cf135001124cd19183336dbfcae1cd432217b00 (diff)
downloadPeerTube-938d3fa0ffb4cf3e4c88f94dcfcae5eb2ce5e190.tar.gz
PeerTube-938d3fa0ffb4cf3e4c88f94dcfcae5eb2ce5e190.tar.zst
PeerTube-938d3fa0ffb4cf3e4c88f94dcfcae5eb2ce5e190.zip
Move normalize functions in helpers
Diffstat (limited to 'server/lib/activitypub')
-rw-r--r--server/lib/activitypub/actor.ts26
-rw-r--r--server/lib/activitypub/videos.ts3
2 files changed, 5 insertions, 24 deletions
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