aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/account/actor-image.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-05-11 11:15:29 +0200
committerChocobozzz <me@florianbigard.com>2021-05-11 11:32:31 +0200
commit7d9ba5c08999c6482f0bc5e0c09c6f55b7724090 (patch)
tree5f4ea1f06dcb781c9e61062522b53a28a401111f /server/models/account/actor-image.ts
parentc07902b9083ab5756436cd020bed5bdfa51028bf (diff)
downloadPeerTube-7d9ba5c08999c6482f0bc5e0c09c6f55b7724090.tar.gz
PeerTube-7d9ba5c08999c6482f0bc5e0c09c6f55b7724090.tar.zst
PeerTube-7d9ba5c08999c6482f0bc5e0c09c6f55b7724090.zip
Cleanup models directory organization
Diffstat (limited to 'server/models/account/actor-image.ts')
-rw-r--r--server/models/account/actor-image.ts100
1 files changed, 0 insertions, 100 deletions
diff --git a/server/models/account/actor-image.ts b/server/models/account/actor-image.ts
deleted file mode 100644
index ae05b4969..000000000
--- a/server/models/account/actor-image.ts
+++ /dev/null
@@ -1,100 +0,0 @@
1import { remove } from 'fs-extra'
2import { join } from 'path'
3import { AfterDestroy, AllowNull, Column, CreatedAt, Default, Is, Model, Table, UpdatedAt } from 'sequelize-typescript'
4import { MActorImageFormattable } from '@server/types/models'
5import { ActorImageType } from '@shared/models'
6import { ActorImage } from '../../../shared/models/actors/actor-image.model'
7import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
8import { logger } from '../../helpers/logger'
9import { CONFIG } from '../../initializers/config'
10import { LAZY_STATIC_PATHS } from '../../initializers/constants'
11import { throwIfNotValid } from '../utils'
12
13@Table({
14 tableName: 'actorImage',
15 indexes: [
16 {
17 fields: [ 'filename' ],
18 unique: true
19 }
20 ]
21})
22export class ActorImageModel extends Model {
23
24 @AllowNull(false)
25 @Column
26 filename: string
27
28 @AllowNull(true)
29 @Default(null)
30 @Column
31 height: number
32
33 @AllowNull(true)
34 @Default(null)
35 @Column
36 width: number
37
38 @AllowNull(true)
39 @Is('ActorImageFileUrl', value => throwIfNotValid(value, isActivityPubUrlValid, 'fileUrl', true))
40 @Column
41 fileUrl: string
42
43 @AllowNull(false)
44 @Column
45 onDisk: boolean
46
47 @AllowNull(false)
48 @Column
49 type: ActorImageType
50
51 @CreatedAt
52 createdAt: Date
53
54 @UpdatedAt
55 updatedAt: Date
56
57 @AfterDestroy
58 static removeFilesAndSendDelete (instance: ActorImageModel) {
59 logger.info('Removing actor image file %s.', instance.filename)
60
61 // Don't block the transaction
62 instance.removeImage()
63 .catch(err => logger.error('Cannot remove actor image file %s.', instance.filename, err))
64 }
65
66 static loadByName (filename: string) {
67 const query = {
68 where: {
69 filename
70 }
71 }
72
73 return ActorImageModel.findOne(query)
74 }
75
76 toFormattedJSON (this: MActorImageFormattable): ActorImage {
77 return {
78 path: this.getStaticPath(),
79 createdAt: this.createdAt,
80 updatedAt: this.updatedAt
81 }
82 }
83
84 getStaticPath () {
85 if (this.type === ActorImageType.AVATAR) {
86 return join(LAZY_STATIC_PATHS.AVATARS, this.filename)
87 }
88
89 return join(LAZY_STATIC_PATHS.BANNERS, this.filename)
90 }
91
92 getPath () {
93 return join(CONFIG.STORAGE.ACTOR_IMAGES, this.filename)
94 }
95
96 removeImage () {
97 const imagePath = join(CONFIG.STORAGE.ACTOR_IMAGES, this.filename)
98 return remove(imagePath)
99 }
100}