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/avatar/avatar.ts | |
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/avatar/avatar.ts')
-rw-r--r-- | server/models/avatar/avatar.ts | 30 |
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 @@ | |||
1 | import { AllowNull, Column, CreatedAt, Model, Table, UpdatedAt } from 'sequelize-typescript' | 1 | import { join } from 'path' |
2 | import { AfterDestroy, AllowNull, Column, CreatedAt, Model, Table, UpdatedAt } from 'sequelize-typescript' | ||
3 | import { Avatar } from '../../../shared/models/avatars/avatar.model' | ||
4 | import { unlinkPromise } from '../../helpers/core-utils' | ||
5 | import { logger } from '../../helpers/logger' | ||
6 | import { CONFIG, STATIC_PATHS } from '../../initializers' | ||
7 | import { 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 | } |