OpenAPI client getResponseBody handle binary as blob
This commit is contained in:
@@ -232,13 +232,21 @@ export const getResponseBody = async (response: Response): Promise<any> => {
|
||||
try {
|
||||
const contentType = response.headers.get('Content-Type');
|
||||
if (contentType) {
|
||||
const jsonTypes = ['application/json', 'application/problem+json']
|
||||
const isJSON = jsonTypes.some(type => contentType.toLowerCase().startsWith(type));
|
||||
if (isJSON) {
|
||||
return await response.json();
|
||||
} else {
|
||||
return await response.text();
|
||||
}
|
||||
|
||||
const binaryTypes = ['application/octet-stream', 'application/pdf', 'application/zip'];
|
||||
const isBinary = binaryTypes.some(type => contentType.toLowerCase().startsWith(type));
|
||||
if (isBinary) {
|
||||
return await response.blob();
|
||||
}
|
||||
|
||||
const jsonTypes = ['application/json', 'application/problem+json']
|
||||
const isJSON = jsonTypes.some(type => contentType.toLowerCase().startsWith(type));
|
||||
if (isJSON) {
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
return await response.text();
|
||||
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
|
||||
@@ -82,10 +82,9 @@ export class UmbWorkspacePackageBuilderElement extends UmbLitElement {
|
||||
const data = await this.#packageRepository.getCreatePackageDownload(this._package.unique);
|
||||
if (!data) return;
|
||||
|
||||
// TODO: [LK] Need to review what the server is doing, as different data is returned depending on schema configuration.
|
||||
// e.g. selecting Media items will return a ZIP file, otherwise it's an XML file. It should be consistent.
|
||||
//blobDownload(data, 'package.xml', 'text/xml');
|
||||
blobDownload(data, 'package.zip', 'application/zip');
|
||||
const filename = typeof data === 'object' ? 'package.zip' : 'package.xml';
|
||||
const mimeType = typeof data === 'object' ? 'application/zip' : 'text/xml';
|
||||
blobDownload(data, filename, mimeType);
|
||||
}
|
||||
|
||||
#isNameDefined() {
|
||||
|
||||
Reference in New Issue
Block a user