aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/avatar/avatar.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2017-12-29 19:10:13 +0100
committerChocobozzz <me@florianbigard.com>2017-12-29 19:10:13 +0100
commitc5911fd347c76e8bdc05ea9f3ee9efed4a58c236 (patch)
treeb8d287daca6c45305090cbec9da97d1155f275bd /server/models/avatar/avatar.ts
parent8b0d42ee372de6589796be26b83e5bffb1b69cdf (diff)
downloadPeerTube-c5911fd347c76e8bdc05ea9f3ee9efed4a58c236.tar.gz
PeerTube-c5911fd347c76e8bdc05ea9f3ee9efed4a58c236.tar.zst
PeerTube-c5911fd347c76e8bdc05ea9f3ee9efed4a58c236.zip
Begin to add avatar to actors
Diffstat (limited to 'server/models/avatar/avatar.ts')
-rw-r--r--server/models/avatar/avatar.ts30
1 files changed, 29 insertions, 1 deletions
diff --git a/server/models/avatar/avatar.ts b/server/models/avatar/avatar.ts
index 2e7a8ae2c..7493c3d75 100644
--- a/server/models/avatar/avatar.ts
+++ b/server/models/avatar/avatar.ts
@@ -1,4 +1,10 @@
1import { AllowNull, Column, CreatedAt, Model, Table, UpdatedAt } from 'sequelize-typescript' 1import { join } from 'path'
2import { AfterDestroy, AllowNull, Column, CreatedAt, Model, Table, UpdatedAt } from 'sequelize-typescript'
3import { Avatar } from '../../../shared/models/avatars/avatar.model'
4import { unlinkPromise } from '../../helpers/core-utils'
5import { logger } from '../../helpers/logger'
6import { CONFIG, STATIC_PATHS } from '../../initializers'
7import { sendDeleteVideo } from '../../lib/activitypub/send'
2 8
3@Table({ 9@Table({
4 tableName: 'avatar' 10 tableName: 'avatar'
@@ -14,4 +20,26 @@ export class AvatarModel extends Model<AvatarModel> {
14 20
15 @UpdatedAt 21 @UpdatedAt
16 updatedAt: Date 22 updatedAt: Date
23
24 @AfterDestroy
25 static removeFilesAndSendDelete (instance: AvatarModel) {
26 return instance.removeAvatar()
27 }
28
29 toFormattedJSON (): Avatar {
30 return {
31 path: this.getWebserverPath(),
32 createdAt: this.createdAt,
33 updatedAt: this.updatedAt
34 }
35 }
36
37 getWebserverPath () {
38 return join(STATIC_PATHS.AVATARS, this.filename)
39 }
40
41 removeAvatar () {
42 const avatarPath = join(CONFIG.STORAGE.AVATARS_DIR, this.filename)
43 return unlinkPromise(avatarPath)
44 }
17} 45}