diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-12-04 10:34:40 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-12-04 10:34:40 +0100 |
commit | 2295ce6c4e7ba805cc100ff961527bebc2cd89e5 (patch) | |
tree | fce0a24074ac119aad730ef5c73c680500ff9578 /server/models/account/account.ts | |
parent | 202f6b6c9dcc9b0aec4b0c1b15e455c22a7952a7 (diff) | |
download | PeerTube-2295ce6c4e7ba805cc100ff961527bebc2cd89e5.tar.gz PeerTube-2295ce6c4e7ba805cc100ff961527bebc2cd89e5.tar.zst PeerTube-2295ce6c4e7ba805cc100ff961527bebc2cd89e5.zip |
Add account avatar
Diffstat (limited to 'server/models/account/account.ts')
-rw-r--r-- | server/models/account/account.ts | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/server/models/account/account.ts b/server/models/account/account.ts index 61a88524c..15be1126b 100644 --- a/server/models/account/account.ts +++ b/server/models/account/account.ts | |||
@@ -1,4 +1,6 @@ | |||
1 | import { join } from 'path' | ||
1 | import * as Sequelize from 'sequelize' | 2 | import * as Sequelize from 'sequelize' |
3 | import { Avatar } from '../../../shared/models/avatars/avatar.model' | ||
2 | import { | 4 | import { |
3 | activityPubContextify, | 5 | activityPubContextify, |
4 | isAccountFollowersCountValid, | 6 | isAccountFollowersCountValid, |
@@ -8,8 +10,10 @@ import { | |||
8 | isUserUsernameValid | 10 | isUserUsernameValid |
9 | } from '../../helpers' | 11 | } from '../../helpers' |
10 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' | 12 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' |
13 | import { AVATARS_DIR } from '../../initializers' | ||
11 | import { CONFIG, CONSTRAINTS_FIELDS } from '../../initializers/constants' | 14 | import { CONFIG, CONSTRAINTS_FIELDS } from '../../initializers/constants' |
12 | import { sendDeleteAccount } from '../../lib/activitypub/send/send-delete' | 15 | import { sendDeleteAccount } from '../../lib/activitypub/send/send-delete' |
16 | import { AvatarModel } from '../avatar' | ||
13 | import { addMethodsToModel } from '../utils' | 17 | import { addMethodsToModel } from '../utils' |
14 | import { AccountAttributes, AccountInstance, AccountMethods } from './account-interface' | 18 | import { AccountAttributes, AccountInstance, AccountMethods } from './account-interface' |
15 | 19 | ||
@@ -252,6 +256,14 @@ function associate (models) { | |||
252 | as: 'followers', | 256 | as: 'followers', |
253 | onDelete: 'cascade' | 257 | onDelete: 'cascade' |
254 | }) | 258 | }) |
259 | |||
260 | Account.hasOne(models.Avatar, { | ||
261 | foreignKey: { | ||
262 | name: 'avatarId', | ||
263 | allowNull: true | ||
264 | }, | ||
265 | onDelete: 'cascade' | ||
266 | }) | ||
255 | } | 267 | } |
256 | 268 | ||
257 | function afterDestroy (account: AccountInstance) { | 269 | function afterDestroy (account: AccountInstance) { |
@@ -265,6 +277,15 @@ function afterDestroy (account: AccountInstance) { | |||
265 | toFormattedJSON = function (this: AccountInstance) { | 277 | toFormattedJSON = function (this: AccountInstance) { |
266 | let host = CONFIG.WEBSERVER.HOST | 278 | let host = CONFIG.WEBSERVER.HOST |
267 | let score: number | 279 | let score: number |
280 | let avatar: Avatar = null | ||
281 | |||
282 | if (this.Avatar) { | ||
283 | avatar = { | ||
284 | path: join(AVATARS_DIR.ACCOUNT, this.Avatar.filename), | ||
285 | createdAt: this.Avatar.createdAt, | ||
286 | updatedAt: this.Avatar.updatedAt | ||
287 | } | ||
288 | } | ||
268 | 289 | ||
269 | if (this.Server) { | 290 | if (this.Server) { |
270 | host = this.Server.host | 291 | host = this.Server.host |
@@ -273,11 +294,15 @@ toFormattedJSON = function (this: AccountInstance) { | |||
273 | 294 | ||
274 | const json = { | 295 | const json = { |
275 | id: this.id, | 296 | id: this.id, |
297 | uuid: this.uuid, | ||
276 | host, | 298 | host, |
277 | score, | 299 | score, |
278 | name: this.name, | 300 | name: this.name, |
301 | followingCount: this.followingCount, | ||
302 | followersCount: this.followersCount, | ||
279 | createdAt: this.createdAt, | 303 | createdAt: this.createdAt, |
280 | updatedAt: this.updatedAt | 304 | updatedAt: this.updatedAt, |
305 | avatar | ||
281 | } | 306 | } |
282 | 307 | ||
283 | return json | 308 | return json |