diff options
author | Chocobozzz <me@florianbigard.com> | 2021-04-08 11:23:45 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-04-08 13:38:04 +0200 |
commit | 84531547bc0934a2abda586d539f7455b455d488 (patch) | |
tree | 128bf5f3a7f57e4e2f343d5da574a4e002163736 /server/models | |
parent | a0eeb45f14bab539f505861cad8f5d42d9ba30cb (diff) | |
download | PeerTube-84531547bc0934a2abda586d539f7455b455d488.tar.gz PeerTube-84531547bc0934a2abda586d539f7455b455d488.tar.zst PeerTube-84531547bc0934a2abda586d539f7455b455d488.zip |
Add size info in db for actor images
Diffstat (limited to 'server/models')
-rw-r--r-- | server/models/account/actor-image.ts | 17 | ||||
-rw-r--r-- | server/models/activitypub/actor.ts | 7 |
2 files changed, 17 insertions, 7 deletions
diff --git a/server/models/account/actor-image.ts b/server/models/account/actor-image.ts index f7438991a..ae05b4969 100644 --- a/server/models/account/actor-image.ts +++ b/server/models/account/actor-image.ts | |||
@@ -1,7 +1,6 @@ | |||
1 | import { remove } from 'fs-extra' | 1 | import { remove } from 'fs-extra' |
2 | import { join } from 'path' | 2 | import { join } from 'path' |
3 | import { AfterDestroy, AllowNull, Column, CreatedAt, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' | 3 | import { AfterDestroy, AllowNull, Column, CreatedAt, Default, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' |
4 | import { v4 as uuidv4 } from 'uuid' | ||
5 | import { MActorImageFormattable } from '@server/types/models' | 4 | import { MActorImageFormattable } from '@server/types/models' |
6 | import { ActorImageType } from '@shared/models' | 5 | import { ActorImageType } from '@shared/models' |
7 | import { ActorImage } from '../../../shared/models/actors/actor-image.model' | 6 | import { ActorImage } from '../../../shared/models/actors/actor-image.model' |
@@ -27,6 +26,16 @@ export class ActorImageModel extends Model { | |||
27 | filename: string | 26 | filename: string |
28 | 27 | ||
29 | @AllowNull(true) | 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) | ||
30 | @Is('ActorImageFileUrl', value => throwIfNotValid(value, isActivityPubUrlValid, 'fileUrl', true)) | 39 | @Is('ActorImageFileUrl', value => throwIfNotValid(value, isActivityPubUrlValid, 'fileUrl', true)) |
31 | @Column | 40 | @Column |
32 | fileUrl: string | 41 | fileUrl: string |
@@ -54,10 +63,6 @@ export class ActorImageModel extends Model { | |||
54 | .catch(err => logger.error('Cannot remove actor image file %s.', instance.filename, err)) | 63 | .catch(err => logger.error('Cannot remove actor image file %s.', instance.filename, err)) |
55 | } | 64 | } |
56 | 65 | ||
57 | static generateFilename () { | ||
58 | return uuidv4() + '.jpg' | ||
59 | } | ||
60 | |||
61 | static loadByName (filename: string) { | 66 | static loadByName (filename: string) { |
62 | const query = { | 67 | const query = { |
63 | where: { | 68 | where: { |
diff --git a/server/models/activitypub/actor.ts b/server/models/activitypub/actor.ts index 6595f11e2..a6c724f26 100644 --- a/server/models/activitypub/actor.ts +++ b/server/models/activitypub/actor.ts | |||
@@ -570,16 +570,21 @@ export class ActorModel extends Model { | |||
570 | icon = { | 570 | icon = { |
571 | type: 'Image', | 571 | type: 'Image', |
572 | mediaType: MIMETYPES.IMAGE.EXT_MIMETYPE[extension], | 572 | mediaType: MIMETYPES.IMAGE.EXT_MIMETYPE[extension], |
573 | height: this.Avatar.height, | ||
574 | width: this.Avatar.width, | ||
573 | url: this.getAvatarUrl() | 575 | url: this.getAvatarUrl() |
574 | } | 576 | } |
575 | } | 577 | } |
576 | 578 | ||
577 | if (this.bannerId) { | 579 | if (this.bannerId) { |
578 | const extension = extname((this as MActorAPChannel).Banner.filename) | 580 | const banner = (this as MActorAPChannel).Banner |
581 | const extension = extname(banner.filename) | ||
579 | 582 | ||
580 | image = { | 583 | image = { |
581 | type: 'Image', | 584 | type: 'Image', |
582 | mediaType: MIMETYPES.IMAGE.EXT_MIMETYPE[extension], | 585 | mediaType: MIMETYPES.IMAGE.EXT_MIMETYPE[extension], |
586 | height: banner.height, | ||
587 | width: banner.width, | ||
583 | url: this.getBannerUrl() | 588 | url: this.getBannerUrl() |
584 | } | 589 | } |
585 | } | 590 | } |