mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
fixing asset upload
This commit is contained in:
parent
871c24abe1
commit
6f41c759eb
|
@ -53,7 +53,7 @@ export async function upload(
|
||||||
table_name: tableName,
|
table_name: tableName,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
existingAssetArray = rowToUpdate[uploadColumnName];
|
existingAssetArray = rowToUpdate[uploadColumnName] ?? [];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the binary data and prepare asset for upload
|
// Get the binary data and prepare asset for upload
|
||||||
|
@ -85,6 +85,7 @@ export async function upload(
|
||||||
'',
|
'',
|
||||||
options,
|
options,
|
||||||
);
|
);
|
||||||
|
//console.log('uploadAsset: ' + uploadAsset);
|
||||||
|
|
||||||
// now step 2 (attaching the asset to a column in a base)
|
// now step 2 (attaching the asset to a column in a base)
|
||||||
for (let c = 0; c < uploadAsset.length; c++) {
|
for (let c = 0; c < uploadAsset.length; c++) {
|
||||||
|
@ -106,11 +107,21 @@ export async function upload(
|
||||||
}
|
}
|
||||||
|
|
||||||
// merge with existing assets in this column or with [] and remove duplicates
|
// merge with existing assets in this column or with [] and remove duplicates
|
||||||
rowInput[uploadColumnName] = [
|
//console.log('existingAssetArray: ' + existingAssetArray);
|
||||||
// @ts-ignore:
|
//console.log('rowInput_uploadedColumnName: ' + rowInput[uploadColumnName]);
|
||||||
...new Set([...rowInput[uploadColumnName], ...existingAssetArray]),
|
|
||||||
];
|
const mergedArray = existingAssetArray.concat(rowInput[uploadColumnName]);
|
||||||
|
|
||||||
|
// Remove duplicates based on "url", keeping the last one
|
||||||
|
const uniqueAssets = Array.from(
|
||||||
|
// @ts-ignore
|
||||||
|
mergedArray.reduce((map, asset) => map.set(asset.url, asset), new Map()).values(),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Update the rowInput with the unique assets and store into body.row.
|
||||||
|
rowInput[uploadColumnName] = uniqueAssets;
|
||||||
body.row = rowInput;
|
body.row = rowInput;
|
||||||
|
//console.log(body.row);
|
||||||
|
|
||||||
// attach assets to table row
|
// attach assets to table row
|
||||||
const responseData = await seaTableApiRequest.call(
|
const responseData = await seaTableApiRequest.call(
|
||||||
|
@ -120,6 +131,7 @@ export async function upload(
|
||||||
'/dtable-server/api/v1/dtables/{{dtable_uuid}}/rows/',
|
'/dtable-server/api/v1/dtables/{{dtable_uuid}}/rows/',
|
||||||
body,
|
body,
|
||||||
);
|
);
|
||||||
|
//console.log('responseData: ' + responseData);
|
||||||
|
|
||||||
uploadAsset[c]['upload_successful'] = responseData.success;
|
uploadAsset[c]['upload_successful'] = responseData.success;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue