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',
maxAvatarSize = 0
avatarExtensions = ''
- preview: SafeResourceUrl
+ preview: string
constructor (
- private sanitizer: DomSanitizer,
private serverService: ServerService,
private notifier: Notifier
) { }
this.avatarChange.emit(formData)
if (this.previewImage) {
- this.preview = this.sanitizer.bypassSecurityTrustResourceUrl(URL.createObjectURL(avatarfile))
+ imageToDataURL(avatarfile).then(result => this.preview = result)
}
}
import { Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core'
-import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser'
+import { SafeResourceUrl } from '@angular/platform-browser'
import { Notifier, ServerService } from '@app/core'
import { 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-banner-edit',
preview: SafeResourceUrl
constructor (
- private sanitizer: DomSanitizer,
private serverService: ServerService,
private notifier: Notifier
) { }
this.bannerChange.emit(formData)
if (this.previewImage) {
- this.preview = this.sanitizer.bypassSecurityTrustResourceUrl(URL.createObjectURL(bannerfile))
+ imageToDataURL(bannerfile).then(result => this.preview = result)
}
}
import { Component, Input } from '@angular/core'
-import { SafeResourceUrl } from '@angular/platform-browser'
import { VideoChannel } from '../shared-main'
import { Account } from '../shared-main/account/account.model'
@Input() account: ActorInput
@Input() channel: ActorInput
- @Input() previewImage: SafeResourceUrl
+ @Input() previewImage: string
@Input() size: ActorAvatarSize
import { Component, forwardRef, Input, OnInit } from '@angular/core'
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'
-import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser'
import { ServerService } from '@app/core'
+import { imageToDataURL } from '@root-helpers/images'
import { HTMLServerConfig } from '@shared/models'
import { BytesPipe } from '../shared-main'
@Input() previewWidth: string
@Input() previewHeight: string
- imageSrc: SafeResourceUrl
+ imageSrc: string
allowedExtensionsMessage = ''
maxSizeText: string
private file: Blob
constructor (
- private sanitizer: DomSanitizer,
private serverService: ServerService
) {
this.bytesPipe = new BytesPipe()
private updatePreview () {
if (this.file) {
- const url = URL.createObjectURL(this.file)
- this.imageSrc = this.sanitizer.bypassSecurityTrustResourceUrl(url)
+ imageToDataURL(this.file).then(result => this.imageSrc = result)
}
}
}
--- /dev/null
+function imageToDataURL (input: File | Blob) {
+ return new Promise<string>(res => {
+ const reader = new FileReader()
+
+ reader.onerror = err => console.error('Cannot read input file.', err)
+ reader.onloadend = () => res(reader.result as string)
+ reader.readAsDataURL(input)
+ })
+}
+
+export {
+ imageToDataURL
+}
export * from './users'
export * from './bytes'
+export * from './images'
export * from './peertube-web-storage'
export * from './utils'
export * from './plugins-manager'