aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/avatar
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/avatar')
-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}