]>
Commit | Line | Data |
---|---|---|
c5911fd3 C |
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' | |
2295ce6c | 8 | |
3fd3ab2d C |
9 | @Table({ |
10 | tableName: 'avatar' | |
11 | }) | |
12 | export class AvatarModel extends Model<AvatarModel> { | |
2295ce6c | 13 | |
3fd3ab2d C |
14 | @AllowNull(false) |
15 | @Column | |
16 | filename: string | |
2295ce6c | 17 | |
3fd3ab2d C |
18 | @CreatedAt |
19 | createdAt: Date | |
2295ce6c | 20 | |
3fd3ab2d C |
21 | @UpdatedAt |
22 | updatedAt: Date | |
c5911fd3 C |
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 | } | |
2295ce6c | 45 | } |