Added filter for new header and doing atob on the response (#5974)
* Added filter for new header and doing atob on the response * Added check for status code 200 * Added const vars, added condition of 200 and action type API * Added comments, NPE check for headers
This commit is contained in:
parent
1dfc624a13
commit
cab6c12471
|
|
@ -110,6 +110,7 @@ export const urlGroupsRegexExp = /^(https?:\/{2}\S+?)(\/[\s\S]*?)(\?(?![^{]*})[\
|
|||
export const EXECUTION_PARAM_KEY = "executionParams";
|
||||
export const EXECUTION_PARAM_REFERENCE_REGEX = /this.params/g;
|
||||
|
||||
export const RESP_HEADER_DATATYPE = "X-APPSMITH-DATATYPE";
|
||||
export const API_REQUEST_HEADERS: APIHeaders = {
|
||||
"Content-Type": "application/json",
|
||||
};
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import {
|
|||
ExecuteActionPayload,
|
||||
ExecuteActionPayloadEvent,
|
||||
PageAction,
|
||||
RESP_HEADER_DATATYPE,
|
||||
} from "constants/AppsmithActionConstants/ActionConstants";
|
||||
import * as log from "loglevel";
|
||||
import {
|
||||
|
|
@ -119,6 +120,10 @@ import LOG_TYPE from "entities/AppsmithConsole/logtype";
|
|||
import { matchPath } from "react-router";
|
||||
import { setDataUrl } from "./PageSagas";
|
||||
|
||||
enum ActionResponseDataTypes {
|
||||
BINARY = "BINARY",
|
||||
}
|
||||
|
||||
export enum NavigationTargetType {
|
||||
SAME_WINDOW = "SAME_WINDOW",
|
||||
NEW_WINDOW = "NEW_WINDOW",
|
||||
|
|
@ -863,6 +868,26 @@ function* runActionSaga(
|
|||
eventName = "RUN_SAAS_API";
|
||||
}
|
||||
|
||||
if (
|
||||
actionObject.pluginType === PluginType.API &&
|
||||
payload.statusCode === "200 OK" &&
|
||||
payload.hasOwnProperty("headers")
|
||||
) {
|
||||
const respHeaders = payload.headers;
|
||||
if (
|
||||
respHeaders.hasOwnProperty(RESP_HEADER_DATATYPE) &&
|
||||
respHeaders[RESP_HEADER_DATATYPE].length > 0 &&
|
||||
respHeaders[RESP_HEADER_DATATYPE][0] ===
|
||||
ActionResponseDataTypes.BINARY &&
|
||||
getType(payload.body) === Types.STRING
|
||||
) {
|
||||
// Decoding from base64 to handle the binary files because direct
|
||||
// conversion of binary files to string causes corruption in the final output
|
||||
// this is to only handle the download of binary files
|
||||
payload.body = atob(payload.body as string);
|
||||
}
|
||||
}
|
||||
|
||||
AnalyticsUtil.logEvent(eventName, {
|
||||
actionId,
|
||||
actionName: actionObject.name,
|
||||
|
|
|
|||
Loading…
Reference in New Issue