import { Component , OnInit , Input , Output , EventEmitter } from "@angular/core" ; import { UploadQueueService , ImagePayload , HashCode , } from "src/app/services/upload-queue.service" ; import { environment } from "src/environments/environment" ; import { filter } from "rxjs/operators" ; import { Observable } from "rxjs" ; @ Component ( { selector : "app-photograph" , templateUrl : "./photograph.component.html" , styleUrls : [ "./photograph.component.scss" ] , } ) export class PhotographComponent implements OnInit { type : string = "custom" ; @ Input ( ) set photos ( input ) { if ( ! input ) { input = [ ] ; } input = input . map ( ( res ) => this . imgOrigin + res ) ; if ( ! ! input ) { this . _photos = input ; } } random : number = Math . random ( ) ; constructor ( public uQueue ) { } imgOrigin : string = environment . apiUrl ; @ Output ( ) onPhotograph : EventEmitter < string [ ] > = new EventEmitter < string [ ] > ( ) ; _photos : string [ ] = [ ] ; metaPhotos : string [ ] = [ ] ; _caches : Array < ImagePayload > = [ ] ; rmClicked : number [ ] = [ ] ; ngOnInit ( ) { let that = this ; this . uQueue . alreadyUploadPayload$ . asObservable ( ) . pipe ( filter ( ( node ) => node . type === "file" ) ) . subscribe ( ( res ) => { this . _photos . push ( that . imgOrigin + res . path ) ; } ) ; } removal ( arr ) { return arr . reduce ( ( prev , cur ) => ( prev . includes ( cur ) ? prev : [ ... prev , cur ] ) , [ ] ) ; } param base64 doWorkerGetBlob ( base64 ) { let obs = new Observable ( ( observer ) => { const worker = new Worker ( "../assets/js/dataURItoBlob.js" ) ; worker . postMessage ( { res : base64 } ) ; worker . onmessage = ( e ) => { observer . next ( e ) ; } ; } ) ; return obs ; } doWorkerGetBase64 ( blob ) { let obs = new Observable ( ( observer ) => { const worker = new Worker ( "../assets/js/blobtobase64.js" ) ; worker . postMessage ( { data : blob } ) ; worker . onmessage = ( e ) => { observer . next ( e ) ; } ; } ) ; return obs ; } doCheckImg ( e ) { let params = { type : this . type , hash : null , } ; Array . prototype . map . call ( e . target . files , ( file ) => { params . hash = HashCode ( params . type ) ; } ) ; } }