diff options
Diffstat (limited to 'server/models/account/account.ts')
-rw-r--r-- | server/models/account/account.ts | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/server/models/account/account.ts b/server/models/account/account.ts index 61a88524c..8b0819f39 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,6 +10,7 @@ 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' |
13 | import { addMethodsToModel } from '../utils' | 16 | import { addMethodsToModel } from '../utils' |
@@ -252,6 +255,14 @@ function associate (models) { | |||
252 | as: 'followers', | 255 | as: 'followers', |
253 | onDelete: 'cascade' | 256 | onDelete: 'cascade' |
254 | }) | 257 | }) |
258 | |||
259 | Account.hasOne(models.Avatar, { | ||
260 | foreignKey: { | ||
261 | name: 'avatarId', | ||
262 | allowNull: true | ||
263 | }, | ||
264 | onDelete: 'cascade' | ||
265 | }) | ||
255 | } | 266 | } |
256 | 267 | ||
257 | function afterDestroy (account: AccountInstance) { | 268 | function afterDestroy (account: AccountInstance) { |
@@ -265,6 +276,15 @@ function afterDestroy (account: AccountInstance) { | |||
265 | toFormattedJSON = function (this: AccountInstance) { | 276 | toFormattedJSON = function (this: AccountInstance) { |
266 | let host = CONFIG.WEBSERVER.HOST | 277 | let host = CONFIG.WEBSERVER.HOST |
267 | let score: number | 278 | let score: number |
279 | let avatar: Avatar = null | ||
280 | |||
281 | if (this.Avatar) { | ||
282 | avatar = { | ||
283 | path: join(AVATARS_DIR.ACCOUNT, this.Avatar.filename), | ||
284 | createdAt: this.Avatar.createdAt, | ||
285 | updatedAt: this.Avatar.updatedAt | ||
286 | } | ||
287 | } | ||
268 | 288 | ||
269 | if (this.Server) { | 289 | if (this.Server) { |
270 | host = this.Server.host | 290 | host = this.Server.host |
@@ -273,11 +293,15 @@ toFormattedJSON = function (this: AccountInstance) { | |||
273 | 293 | ||
274 | const json = { | 294 | const json = { |
275 | id: this.id, | 295 | id: this.id, |
296 | uuid: this.uuid, | ||
276 | host, | 297 | host, |
277 | score, | 298 | score, |
278 | name: this.name, | 299 | name: this.name, |
300 | followingCount: this.followingCount, | ||
301 | followersCount: this.followersCount, | ||
279 | createdAt: this.createdAt, | 302 | createdAt: this.createdAt, |
280 | updatedAt: this.updatedAt | 303 | updatedAt: this.updatedAt, |
304 | avatar | ||
281 | } | 305 | } |
282 | 306 | ||
283 | return json | 307 | return json |