Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Test promisifying resolvingBlobUrls #36460

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 24 additions & 27 deletions app/client/src/sagas/ActionExecution/PluginActionSaga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,11 @@ const isErrorResponse = (response: ActionExecutionResponse) => {
* @param blobUrl string A blob url with type added a query param
* @returns promise that resolves to file content
*/
// TODO: Fix this the next time the file is edited
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function* readBlob(blobUrl: string): any {
async function readBlob(blobUrl: string) {
const [url, fileType] = parseBlobUrl(blobUrl);
const file = yield fetch(url).then(async (r) => r.blob());
const file = await fetch(url).then(async (r) => r.blob());

return yield new Promise((resolve) => {
return new Promise((resolve) => {
const reader = new FileReader();

if (fileType === FileDataTypes.Base64) {
Expand Down Expand Up @@ -286,37 +284,36 @@ function* readBlob(blobUrl: string): any {
* @param value
*/

function* resolvingBlobUrls(
// TODO: Fix this the next time the file is edited
// eslint-disable-next-line @typescript-eslint/no-explicit-any
value: any,
async function resolvingBlobUrls(
value: unknown,
executeActionRequest: ExecuteActionRequest,
index: number,
isArray?: boolean,
arrDatatype?: string[],
) {
//Get datatypes of evaluated value.
const dataType: string = findDatatype(value);
const dataType = findDatatype(value);

//If array elements then dont push datatypes to payload.
isArray
? arrDatatype?.push(dataType)
: (executeActionRequest.paramProperties[`k${index}`] = {
datatype: dataType,
});
if (isArray) {
arrDatatype?.push(dataType);
} else {
executeActionRequest.paramProperties[`k${index}`] = {
datatype: dataType,
};
}

if (isTrueObject(value)) {
const blobUrlPaths: string[] = [];

Object.keys(value).forEach((propertyName) => {
if (isBlobUrl(value[propertyName])) {
Object.entries(value).forEach(([propertyName, propertyValue]) => {
if (typeof propertyValue === "string" && isBlobUrl(propertyValue)) {
blobUrlPaths.push(propertyName);
}
});

for (const blobUrlPath of blobUrlPaths) {
const blobUrl = value[blobUrlPath] as string;
const resolvedBlobValue: unknown = yield call(readBlob, blobUrl);
const resolvedBlobValue: unknown = await readBlob(blobUrl);

set(value, blobUrlPath, resolvedBlobValue);

Expand All @@ -332,9 +329,8 @@ function* resolvingBlobUrls(
set(blobUrlPathMap, blobUrlPath, blobUrl);
set(value, "blobUrlPaths", blobUrlPathMap);
}
} else if (isBlobUrl(value)) {
// @ts-expect-error: Values can take many types
value = yield call(readBlob, value);
} else if (typeof value === "string" && isBlobUrl(value)) {
value = await readBlob(value);
}

return value;
Expand Down Expand Up @@ -394,7 +390,7 @@ function updateBlobDataFromUrls(
* @param bindings
* @param executionParams
*/
function* evaluateActionParams(
async function* evaluateActionParams(
bindings: string[] | undefined,
formData: FormData,
executeActionRequest: ExecuteActionRequest,
Expand Down Expand Up @@ -444,17 +440,17 @@ function* evaluateActionParams(
for (const val of value) {
// TODO: Fix this the next time the file is edited
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const newVal: Record<string, any> = yield call(
resolvingBlobUrls,
const newVal = await resolvingBlobUrls(
val,
executeActionRequest,
i,
true,
arrDatatype,
);

if (newVal.hasOwnProperty("blobUrlPaths")) {
if (newVal && newVal.hasOwnProperty("blobUrlPaths")) {
updateBlobDataFromUrls(
// @ts-expect-error: blobUrlPaths is a property of newVal
newVal.blobUrlPaths,
newVal,
blobMap,
Expand All @@ -468,7 +464,8 @@ function* evaluateActionParams(

if (key.includes(".files") && recordFilePickerInstrumentation) {
filePickerInstrumentation["numberOfFiles"] += 1;
const { size, type } = newVal;

const { size, type } = newVal as { size: number; type: string };

filePickerInstrumentation["totalSize"] += size;
filePickerInstrumentation["fileSizes"].push(size);
Expand Down
Loading