diff options
author | Chocobozzz <me@florianbigard.com> | 2017-12-29 19:10:13 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2017-12-29 19:10:13 +0100 |
commit | c5911fd347c76e8bdc05ea9f3ee9efed4a58c236 (patch) | |
tree | b8d287daca6c45305090cbec9da97d1155f275bd /server/models/activitypub | |
parent | 8b0d42ee372de6589796be26b83e5bffb1b69cdf (diff) | |
download | PeerTube-c5911fd347c76e8bdc05ea9f3ee9efed4a58c236.tar.gz PeerTube-c5911fd347c76e8bdc05ea9f3ee9efed4a58c236.tar.zst PeerTube-c5911fd347c76e8bdc05ea9f3ee9efed4a58c236.zip |
Begin to add avatar to actors
Diffstat (limited to 'server/models/activitypub')
-rw-r--r-- | server/models/activitypub/actor.ts | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/server/models/activitypub/actor.ts b/server/models/activitypub/actor.ts index 3d96b3706..8422653df 100644 --- a/server/models/activitypub/actor.ts +++ b/server/models/activitypub/actor.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import { values } from 'lodash' | 1 | import { values } from 'lodash' |
2 | import { join } from 'path' | 2 | import { extname, join } from 'path' |
3 | import * as Sequelize from 'sequelize' | 3 | import * as Sequelize from 'sequelize' |
4 | import { | 4 | import { |
5 | AllowNull, BelongsTo, Column, CreatedAt, DataType, Default, DefaultScope, ForeignKey, HasMany, HasOne, Is, IsUUID, Model, Scopes, | 5 | AllowNull, BelongsTo, Column, CreatedAt, DataType, Default, DefaultScope, ForeignKey, HasMany, HasOne, Is, IsUUID, Model, Scopes, |
@@ -30,6 +30,10 @@ enum ScopeNames { | |||
30 | { | 30 | { |
31 | model: () => ServerModel, | 31 | model: () => ServerModel, |
32 | required: false | 32 | required: false |
33 | }, | ||
34 | { | ||
35 | model: () => AvatarModel, | ||
36 | required: false | ||
33 | } | 37 | } |
34 | ] | 38 | ] |
35 | }) | 39 | }) |
@@ -47,6 +51,10 @@ enum ScopeNames { | |||
47 | { | 51 | { |
48 | model: () => ServerModel, | 52 | model: () => ServerModel, |
49 | required: false | 53 | required: false |
54 | }, | ||
55 | { | ||
56 | model: () => AvatarModel, | ||
57 | required: false | ||
50 | } | 58 | } |
51 | ] | 59 | ] |
52 | } | 60 | } |
@@ -141,7 +149,7 @@ export class ActorModel extends Model<ActorModel> { | |||
141 | foreignKey: { | 149 | foreignKey: { |
142 | allowNull: true | 150 | allowNull: true |
143 | }, | 151 | }, |
144 | onDelete: 'cascade' | 152 | onDelete: 'set null' |
145 | }) | 153 | }) |
146 | Avatar: AvatarModel | 154 | Avatar: AvatarModel |
147 | 155 | ||
@@ -253,11 +261,7 @@ export class ActorModel extends Model<ActorModel> { | |||
253 | toFormattedJSON () { | 261 | toFormattedJSON () { |
254 | let avatar: Avatar = null | 262 | let avatar: Avatar = null |
255 | if (this.Avatar) { | 263 | if (this.Avatar) { |
256 | avatar = { | 264 | avatar = this.Avatar.toFormattedJSON() |
257 | path: join(AVATARS_DIR.ACCOUNT, this.Avatar.filename), | ||
258 | createdAt: this.Avatar.createdAt, | ||
259 | updatedAt: this.Avatar.updatedAt | ||
260 | } | ||
261 | } | 265 | } |
262 | 266 | ||
263 | let score: number | 267 | let score: number |
@@ -286,6 +290,16 @@ export class ActorModel extends Model<ActorModel> { | |||
286 | activityPubType = 'Group' as 'Group' | 290 | activityPubType = 'Group' as 'Group' |
287 | } | 291 | } |
288 | 292 | ||
293 | let icon = undefined | ||
294 | if (this.avatarId) { | ||
295 | const extension = extname(this.Avatar.filename) | ||
296 | icon = { | ||
297 | type: 'Image', | ||
298 | mediaType: extension === '.png' ? 'image/png' : 'image/jpeg', | ||
299 | url: this.getAvatarUrl() | ||
300 | } | ||
301 | } | ||
302 | |||
289 | const json = { | 303 | const json = { |
290 | type: activityPubType, | 304 | type: activityPubType, |
291 | id: this.url, | 305 | id: this.url, |
@@ -304,7 +318,8 @@ export class ActorModel extends Model<ActorModel> { | |||
304 | id: this.getPublicKeyUrl(), | 318 | id: this.getPublicKeyUrl(), |
305 | owner: this.url, | 319 | owner: this.url, |
306 | publicKeyPem: this.publicKey | 320 | publicKeyPem: this.publicKey |
307 | } | 321 | }, |
322 | icon | ||
308 | } | 323 | } |
309 | 324 | ||
310 | return activityPubContextify(json) | 325 | return activityPubContextify(json) |
@@ -353,4 +368,10 @@ export class ActorModel extends Model<ActorModel> { | |||
353 | getHost () { | 368 | getHost () { |
354 | return this.Server ? this.Server.host : CONFIG.WEBSERVER.HOST | 369 | return this.Server ? this.Server.host : CONFIG.WEBSERVER.HOST |
355 | } | 370 | } |
371 | |||
372 | getAvatarUrl () { | ||
373 | if (!this.avatarId) return undefined | ||
374 | |||
375 | return CONFIG.WEBSERVER.URL + this.Avatar.getWebserverPath | ||
376 | } | ||
356 | } | 377 | } |