[desktop] Tauri HTTP interceptor: content-type support

This commit is contained in:
Alexandr Stelnykovych
2025-04-17 16:58:44 +03:00
parent 4ef04c72ca
commit 1e7baff6bd
3 changed files with 24 additions and 11 deletions

View File

@@ -8,18 +8,14 @@ import { PortapiService, PORTMASTER_HTTP_API_ENDPOINT, PORTMASTER_WS_API_ENDPOIN
import { SPNService } from "./spn.service";
import { WebsocketService } from "./websocket.service";
import { provideHttpClient, withInterceptors } from '@angular/common/http';
import { TauriHttpInterceptor } from "./tauri-http-interceptor";
import { TauriHttpInterceptor } from "./platform-specific/tauri/tauri-http-interceptor";
import { IsTauriEnvironment } from "./platform-specific/utils";
export interface ModuleConfig {
httpAPI?: string;
websocketAPI?: string;
}
// Simple function to detect if the app is running in a Tauri environment
export function IsTauriEnvironment(): boolean {
return '__TAURI__' in window;
}
// Factory function to provide the appropriate HTTP client configuration
//
// This function determines the appropriate HTTP client configuration based on the runtime environment.

View File

@@ -64,12 +64,25 @@ export function TauriHttpInterceptor(req: HttpRequest<unknown>, next: HttpHandle
};
switch (responseType) {
case 'arraybuffer':
return from(response.arrayBuffer()).pipe(map(createResponse));
case 'blob':
return from(response.blob()).pipe(map(createResponse));
case 'text':
return from(response.text()).pipe(map(createResponse));
return from(response.text()).pipe(map(createResponse));
case 'arraybuffer':
return from(response.arrayBuffer()).pipe(map(createResponse));
case 'blob':
return from(response.blob()).pipe(
map(blob => {
// Get content-type from response headers
const contentType = response.headers.get('content-type') || '';
// Create a new blob with the proper MIME type
if (contentType && (!blob.type || blob.type === 'application/octet-stream')) {
// Create new blob with the correct MIME type
const typedBlob = new Blob([blob], { type: contentType });
return createResponse(typedBlob);
}
return createResponse(blob);
})
);
case 'json':
default:
return from(response.text()).pipe(

View File

@@ -0,0 +1,4 @@
// Simple function to detect if the app is running in a Tauri environment
export function IsTauriEnvironment(): boolean {
return '__TAURI__' in window;
}