X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fshared%2Fshared-actor-image-edit%2Factor-avatar-edit.component.ts;h=fc925083ea4e67555edf899ed394fb1b972bb286;hb=52798aa5f277492d4dd2482bca9396d2e982fa19;hp=840946690c8b80c3eddb1dda9a3987c31c8527d1;hpb=746018f6b81b40e8858303662ac9ec5ce59ac6eb;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/shared/shared-actor-image-edit/actor-avatar-edit.component.ts b/client/src/app/shared/shared-actor-image-edit/actor-avatar-edit.component.ts index 840946690..fc925083e 100644 --- a/client/src/app/shared/shared-actor-image-edit/actor-avatar-edit.component.ts +++ b/client/src/app/shared/shared-actor-image-edit/actor-avatar-edit.component.ts @@ -1,9 +1,8 @@ import { Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core' -import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser' import { Notifier, ServerService } from '@app/core' import { Account, VideoChannel } from '@app/shared/shared-main' -import { NgbPopover } from '@ng-bootstrap/ng-bootstrap' import { getBytes } from '@root-helpers/bytes' +import { imageToDataURL } from '@root-helpers/images' @Component({ selector: 'my-actor-avatar-edit', @@ -15,7 +14,6 @@ import { getBytes } from '@root-helpers/bytes' }) export class ActorAvatarEditComponent implements OnInit { @ViewChild('avatarfileInput') avatarfileInput: ElementRef - @ViewChild('avatarPopover') avatarPopover: NgbPopover @Input() actor: VideoChannel | Account @Input() editable = true @@ -30,29 +28,27 @@ export class ActorAvatarEditComponent implements OnInit { maxAvatarSize = 0 avatarExtensions = '' - preview: SafeResourceUrl + preview: string constructor ( - private sanitizer: DomSanitizer, private serverService: ServerService, private notifier: Notifier ) { } ngOnInit (): void { - this.serverService.getConfig() - .subscribe(config => { - this.maxAvatarSize = config.avatar.file.size.max - this.avatarExtensions = config.avatar.file.extensions.join(', ') - - this.avatarFormat = `${$localize`max size`}: 192*192px, ` + - `${getBytes(this.maxAvatarSize)} ${$localize`extensions`}: ${this.avatarExtensions}` - }) + const config = this.serverService.getHTMLConfig() + + this.maxAvatarSize = config.avatar.file.size.max + this.avatarExtensions = config.avatar.file.extensions.join(', ') + + this.avatarFormat = `${$localize`max size`}: 192*192px, ` + + `${getBytes(this.maxAvatarSize)} ${$localize`extensions`}: ${this.avatarExtensions}` } onAvatarChange (input: HTMLInputElement) { this.avatarfileInput = new ElementRef(input) - const avatarfile = this.avatarfileInput.nativeElement.files[ 0 ] + const avatarfile = this.avatarfileInput.nativeElement.files[0] if (avatarfile.size > this.maxAvatarSize) { this.notifier.error('Error', $localize`This image is too large.`) return @@ -60,11 +56,10 @@ export class ActorAvatarEditComponent implements OnInit { const formData = new FormData() formData.append('avatarfile', avatarfile) - this.avatarPopover?.close() this.avatarChange.emit(formData) if (this.previewImage) { - this.preview = this.sanitizer.bypassSecurityTrustResourceUrl(URL.createObjectURL(avatarfile)) + imageToDataURL(avatarfile).then(result => this.preview = result) } } @@ -74,22 +69,12 @@ export class ActorAvatarEditComponent implements OnInit { } hasAvatar () { - return !!this.preview || !!this.actor.avatar - } - - isChannel () { - return !!(this.actor as VideoChannel).ownerAccount - } - - getChannel (): VideoChannel { - if (this.isChannel()) return this.actor as VideoChannel - - return undefined + return !!this.preview || this.actor.avatars.length !== 0 } - getAccount (): Account { - if (this.isChannel()) return undefined + getActorType () { + if ((this.actor as VideoChannel).ownerAccount) return 'channel' - return this.actor as Account + return 'account' } }