feat: blobs fetch
PHP Unit Tests / test (pull_request) Failing after 11m59s
JS Unit Tests / test (pull_request) Failing after 12m1s
Build Test / test (pull_request) Failing after 12m3s

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-06-18 19:38:11 -04:00
parent 105f69c3a5
commit bb349646c3
4 changed files with 98 additions and 1 deletions
+33
View File
@@ -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;