2019-11-06 13:48:06 +09:00
|
|
|
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
|
|
|
|
import { ucapAnimations } from '../../animations';
|
2019-11-06 16:24:51 +09:00
|
|
|
import { FileEventJson } from '@ucap-webmessenger/protocol-event';
|
2019-11-06 17:25:59 +09:00
|
|
|
import { DeviceType, FileUtil, MimeUtil } from '@ucap-webmessenger/core';
|
2019-11-06 16:24:51 +09:00
|
|
|
import {
|
|
|
|
CommonApiService,
|
|
|
|
FileDownloadItem
|
|
|
|
} from '@ucap-webmessenger/api-common';
|
|
|
|
import { take, map } from 'rxjs/operators';
|
2019-11-06 18:19:37 +09:00
|
|
|
import { DomSanitizer } from '@angular/platform-browser';
|
2019-11-06 13:48:06 +09:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'ucap-image-viewer',
|
|
|
|
templateUrl: './image-viewer.component.html',
|
|
|
|
styleUrls: ['./image-viewer.component.scss'],
|
|
|
|
animations: ucapAnimations
|
|
|
|
})
|
|
|
|
export class ImageViewerComponent implements OnInit {
|
2019-11-06 16:24:51 +09:00
|
|
|
@Input()
|
|
|
|
fileInfo: FileEventJson;
|
|
|
|
|
|
|
|
@Input()
|
|
|
|
downloadUrl: string;
|
|
|
|
|
|
|
|
@Input()
|
|
|
|
userSeq: number;
|
|
|
|
|
|
|
|
@Input()
|
|
|
|
deviceType: DeviceType;
|
|
|
|
|
|
|
|
@Input()
|
|
|
|
token: string;
|
|
|
|
|
2019-11-06 13:48:06 +09:00
|
|
|
@Output()
|
|
|
|
closed = new EventEmitter<void>();
|
|
|
|
|
2019-11-06 18:19:37 +09:00
|
|
|
@Output()
|
|
|
|
download = new EventEmitter<Blob>();
|
|
|
|
|
|
|
|
blob: Blob;
|
2019-11-06 17:25:59 +09:00
|
|
|
imageSrc: string | ArrayBuffer;
|
2019-11-06 16:24:51 +09:00
|
|
|
|
|
|
|
fileDownloadItem: FileDownloadItem;
|
|
|
|
|
2019-11-06 18:19:37 +09:00
|
|
|
constructor(
|
|
|
|
private domSanitizer: DomSanitizer,
|
|
|
|
private commonApiService: CommonApiService
|
|
|
|
) {
|
2019-11-06 16:24:51 +09:00
|
|
|
this.fileDownloadItem = new FileDownloadItem();
|
2019-11-06 17:25:59 +09:00
|
|
|
}
|
2019-11-06 16:24:51 +09:00
|
|
|
|
2019-11-06 17:25:59 +09:00
|
|
|
ngOnInit() {
|
2019-11-06 16:24:51 +09:00
|
|
|
this.commonApiService
|
|
|
|
.fileTalkDownload(
|
|
|
|
{
|
|
|
|
userSeq: this.userSeq,
|
|
|
|
deviceType: this.deviceType,
|
|
|
|
token: this.token,
|
|
|
|
attachmentsSeq: this.fileInfo.attachmentSeq,
|
|
|
|
fileDownloadItem: this.fileDownloadItem
|
|
|
|
},
|
|
|
|
this.downloadUrl
|
|
|
|
)
|
|
|
|
.pipe(
|
|
|
|
take(1),
|
2019-11-06 17:25:59 +09:00
|
|
|
map(async blob => {
|
2019-11-06 18:19:37 +09:00
|
|
|
this.blob = blob.slice(
|
2019-11-06 17:25:59 +09:00
|
|
|
0,
|
|
|
|
blob.size,
|
|
|
|
MimeUtil.getMimeFromExtension(this.fileInfo.fileExt)
|
|
|
|
);
|
2019-11-07 11:37:33 +09:00
|
|
|
this.imageSrc = await FileUtil.fromBlobToDataUrl(this.blob);
|
2019-11-06 16:24:51 +09:00
|
|
|
})
|
|
|
|
)
|
|
|
|
.subscribe();
|
|
|
|
}
|
|
|
|
|
2019-11-06 18:19:37 +09:00
|
|
|
onClickDownload(): void {
|
|
|
|
this.download.emit(this.blob);
|
|
|
|
}
|
|
|
|
|
2019-11-06 16:24:51 +09:00
|
|
|
onClickClose(): void {
|
|
|
|
this.closed.emit();
|
|
|
|
}
|
2019-11-06 13:48:06 +09:00
|
|
|
}
|