fake image 쪽지쪽 처리.

This commit is contained in:
leejinho 2020-02-17 13:12:42 +09:00
parent f113e66377
commit d6b518f29b

View File

@ -178,26 +178,32 @@ export class WriteComponent implements OnInit, OnDestroy, AfterViewInit {
return; return;
} }
for (let i = 0; i < fileList.length; i++) { this.validUploadFile(fileList).then(async result => {
const file = fileList.item(i); if (!result) {
return;
} else {
for (let i = 0; i < fileList.length; i++) {
const file = fileList.item(i);
const dataUrl = await FileUtil.fromBlobToDataUrl(file); const dataUrl = await FileUtil.fromBlobToDataUrl(file);
const img = document.createElement('img'); const img = document.createElement('img');
img.src = dataUrl as string; img.src = dataUrl as string;
img.setAttribute('style', 'max-height:250px; max-width:250px;'); img.setAttribute('style', 'max-height:250px; max-width:250px;');
img[ATTR_FILE] = file; img[ATTR_FILE] = file;
self.insertNode(img); self.insertNode(img);
const empty = document.createElement('div'); const empty = document.createElement('div');
empty.innerHTML = '&nbsp;<br/>'; empty.innerHTML = '&nbsp;<br/>';
self.insertNode(empty, true); self.insertNode(empty, true);
} }
self.fileInput.nativeElement.value = ''; self.fileInput.nativeElement.value = '';
self.fileInput.nativeElement.onchange = undefined; self.fileInput.nativeElement.onchange = undefined;
self.checkContentLength(); self.checkContentLength();
self.changeDetectorRef.detectChanges(); self.changeDetectorRef.detectChanges();
}
});
}; };
} }
@ -228,7 +234,7 @@ export class WriteComponent implements OnInit, OnDestroy, AfterViewInit {
}; };
} }
validUploadFile(fileList: FileList): boolean { async validUploadFile(fileList: FileList): Promise<boolean> {
let valid = true; let valid = true;
if (this.fileAllowSize > 0) { if (this.fileAllowSize > 0) {
for (let i = 0; i < fileList.length; i++) { for (let i = 0; i < fileList.length; i++) {
@ -284,6 +290,39 @@ export class WriteComponent implements OnInit, OnDestroy, AfterViewInit {
return valid; return valid;
} }
const files: File[] = [];
for (let i = 0; i < fileList.length; i++) {
files.push(fileList.item(i));
}
const fakeMedia = await this.commonApiService.checkInvalidMediaMimeForFileTalk(
files
);
if (!fakeMedia.accept) {
this.ngZone.run(() => {
this.snackBarService.openFromComponent<
AlertSnackbarComponent,
AlertSnackbarData
>(AlertSnackbarComponent, {
duration: 1000,
verticalPosition: 'bottom',
horizontalPosition: 'center',
data: {
html: this.translateService.instant(
'common.file.errors.notAcceptableMime',
{
supporedType:
fakeMedia.rejected.length > 0
? fakeMedia.rejected.join(',')
: ''
}
)
}
});
});
valid = false;
return valid;
}
return valid; return valid;
} }