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 { STATIC_PATHS } from '../../initializers'
5 import { logger } from '../../helpers/logger'
6 import { remove } from 'fs-extra'
7 import { CONFIG } from '../../initializers/config'
12 export class AvatarModel extends Model<AvatarModel> {
25 static removeFilesAndSendDelete (instance: AvatarModel) {
26 logger.info('Removing avatar file %s.', instance.filename)
28 // Don't block the transaction
29 instance.removeAvatar()
30 .catch(err => logger.error('Cannot remove avatar file %s.', instance.filename, err))
33 toFormattedJSON (): Avatar {
35 path: this.getWebserverPath(),
36 createdAt: this.createdAt,
37 updatedAt: this.updatedAt
42 return join(STATIC_PATHS.AVATARS, this.filename)
46 const avatarPath = join(CONFIG.STORAGE.AVATARS_DIR, this.filename)
47 return remove(avatarPath)