]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/models/avatar/avatar.ts
Begin to add avatar to actors
[github/Chocobozzz/PeerTube.git] / server / models / avatar / avatar.ts
CommitLineData
c5911fd3
C
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'
2295ce6c 8
3fd3ab2d
C
9@Table({
10 tableName: 'avatar'
11})
12export 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}