diff options
author | Chocobozzz <me@florianbigard.com> | 2018-05-11 15:55:39 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-05-11 15:55:39 +0200 |
commit | 938d3fa0ffb4cf3e4c88f94dcfcae5eb2ce5e190 (patch) | |
tree | 844768f122c8f06d1f90f006d9fdd0e2e4005aae /server/lib/activitypub | |
parent | 5cf135001124cd19183336dbfcae1cd432217b00 (diff) | |
download | PeerTube-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.ts | 26 | ||||
-rw-r--r-- | server/lib/activitypub/videos.ts | 3 |
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' | |||
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 | ||