]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/models/avatar/avatar.ts
(embed) sandbox the iframe
[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'
c5911fd3 5import { CONFIG, STATIC_PATHS } from '../../initializers'
2295ce6c 6
3fd3ab2d
C
7@Table({
8 tableName: 'avatar'
9})
10export class AvatarModel extends Model<AvatarModel> {
2295ce6c 11
3fd3ab2d
C
12 @AllowNull(false)
13 @Column
14 filename: string
2295ce6c 15
3fd3ab2d
C
16 @CreatedAt
17 createdAt: Date
2295ce6c 18
3fd3ab2d
C
19 @UpdatedAt
20 updatedAt: Date
c5911fd3
C
21
22 @AfterDestroy
23 static removeFilesAndSendDelete (instance: AvatarModel) {
24 return instance.removeAvatar()
25 }
26
27 toFormattedJSON (): Avatar {
28 return {
29 path: this.getWebserverPath(),
30 createdAt: this.createdAt,
31 updatedAt: this.updatedAt
32 }
33 }
34
35 getWebserverPath () {
36 return join(STATIC_PATHS.AVATARS, this.filename)
37 }
38
39 removeAvatar () {
40 const avatarPath = join(CONFIG.STORAGE.AVATARS_DIR, this.filename)
41 return unlinkPromise(avatarPath)
42 }
2295ce6c 43}