33 KartoffelstampfTerminalOutputEntry ,
44 KartoffelstampfImageUploadResponse ,
55 KartoffelstampfImageUploadRequest ,
6+ KartoffelstampfCompressInstruction ,
67 } from './types/kartoffelstampf-server' ;
78import { Observable , Subject , throwError } from 'rxjs' ;
89import { HttpClient , HttpHeaders , HttpErrorResponse } from '@angular/common/http' ;
@@ -24,16 +25,14 @@ export class BackendService {
2425
2526 constructor ( private http : HttpClient ) { }
2627
27- getDownloadUrl ( filePathOnServer : string ) {
28- return BackendService . REST_API_DOWNLOAD_URL + '/' + filePathOnServer ;
28+ getDownloadUrl ( temporaryFileName : string , originalFileName : string ) {
29+ return ` ${ BackendService . REST_API_DOWNLOAD_URL } / ${ temporaryFileName } / ${ originalFileName } ` ;
2930 }
3031
3132 uploadImage ( base64Image : string , type : string ) {
32- const sanitizedBase64 = base64Image . replace ( 'data:image/png;base64,' , '' ) ;
3333 return this . http . post < KartoffelstampfImageUploadResponse > (
3434 BackendService . REST_API_UPLOAD_URL , {
35- fileContent : sanitizedBase64 ,
36- fileType : type
35+ contentDataUri : base64Image ,
3736 } as KartoffelstampfImageUploadRequest , httpOptions )
3837 . pipe (
3938 catchError ( ( e : HttpErrorResponse ) => {
@@ -45,17 +44,11 @@ export class BackendService {
4544 ) ;
4645 }
4746
48- runCompressPngCommand ( filePathOnServer : string ) : Observable < KartoffelstampfTerminalOutputEntry > {
47+ runCompressCommand ( compressInstruction : KartoffelstampfCompressInstruction ) : Observable < KartoffelstampfTerminalOutputEntry > {
4948 const ws = new WebSocket ( BackendService . WEB_SOCKET_COMPRESS_URL ) ;
5049 const subject = new Subject < KartoffelstampfTerminalOutputEntry > ( ) ;
5150 ws . onopen = function ( event ) {
52- ws . send ( JSON . stringify ( {
53- command : 'optipng' ,
54- commandArguments : [
55- '-o5' ,
56- '/u/' + filePathOnServer // e.g. foo.png
57- ]
58- } ) ) ;
51+ ws . send ( JSON . stringify ( compressInstruction ) ) ;
5952 } ;
6053 ws . onmessage = function ( event : MessageEvent ) {
6154 const kartoffelstampfTerminalOutputEntry : KartoffelstampfTerminalOutputEntry = JSON . parse ( event . data ) ;
0 commit comments