import { Component, EventEmitter, forwardRef, Input, OnInit, Output } from '@angular/core'
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'
-import { NotificationsService } from 'angular2-notifications'
+import { Notifier } from '@app/core'
import { I18n } from '@ngx-translate/i18n-polyfill'
@Component({
@Output() fileChanged = new EventEmitter<Blob>()
allowedExtensionsMessage = ''
+ fileInputValue: any
private file: File
constructor (
- private notificationsService: NotificationsService,
+ private notifier: Notifier,
private i18n: I18n
) {}
const [ file ] = event.target.files
if (file.size > this.maxFileSize) {
- this.notificationsService.error(this.i18n('Error'), this.i18n('This file is too large.'))
+ this.notifier.error(this.i18n('This file is too large.'))
+ return
+ }
+
+ const extension = '.' + file.name.split('.').pop()
+ if (this.extensions.includes(extension) === false) {
+ const message = this.i18n(
+ 'PeerTube cannot handle this kind of file. Accepted extensions are {{extensions}}.',
+ { extensions: this.allowedExtensionsMessage }
+ )
+ this.notifier.error(message)
+
return
}
writeValue (file: any) {
this.file = file
+
+ if (!this.file) this.fileInputValue = null
}
registerOnChange (fn: (_: any) => void) {