feat: blobs fetch
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -28,6 +28,9 @@ import type {
|
||||
EntityPatchResponse,
|
||||
EntityPatchRequest,
|
||||
EntityDownloadRequest,
|
||||
EntityBlobsRequest,
|
||||
EntityBlobsResponse,
|
||||
EntityBlobsWireResponse,
|
||||
} from '../types/entity';
|
||||
import { useIntegrationStore } from '@KTXC/stores/integrationStore';
|
||||
import { EntityObject } from '../models';
|
||||
@@ -227,6 +230,36 @@ export const entityService = {
|
||||
download(request: EntityDownloadRequest): { transaction: string } {
|
||||
return transceiveDownload<EntityDownloadRequest>('entity.download', request);
|
||||
},
|
||||
|
||||
/**
|
||||
* Fetch one or more message parts (attachments) inline for rendering.
|
||||
*
|
||||
* Returns JSON with base64-encoded bytes; each result is decoded into a Blob
|
||||
* so callers can create object URLs for preview.
|
||||
*/
|
||||
async blobs(request: EntityBlobsRequest): Promise<EntityBlobsResponse> {
|
||||
const wire = await transceivePost<EntityBlobsRequest, EntityBlobsWireResponse>(
|
||||
'entity.blobs',
|
||||
request,
|
||||
);
|
||||
return wire.map((result) => ({
|
||||
source: result.source,
|
||||
part: result.part,
|
||||
mime: result.mime,
|
||||
filename: result.filename,
|
||||
blob: base64ToBlob(result.bytes, result.mime),
|
||||
}));
|
||||
},
|
||||
};
|
||||
|
||||
/** Decode base64 content into a Blob of the given MIME type. */
|
||||
function base64ToBlob(base64: string, mime: string): Blob {
|
||||
const binary = atob(base64);
|
||||
const bytes = new Uint8Array(binary.length);
|
||||
for (let i = 0; i < binary.length; i++) {
|
||||
bytes[i] = binary.charCodeAt(i);
|
||||
}
|
||||
return new Blob([bytes], { type: mime });
|
||||
}
|
||||
|
||||
export default entityService;
|
||||
|
||||
Reference in New Issue
Block a user