fix(Microsoft OneDrive Node): Try to download file using downloadUrl (#13200)

Co-authored-by: Michael Kret <michael.k@radency.com>
This commit is contained in:
Shireen Missi
2025-02-12 12:46:21 +00:00
committed by GitHub
parent 56426e989f
commit 67cd05c6dc
2 changed files with 106 additions and 12 deletions

View File

@@ -1,3 +1,4 @@
import { IncomingMessage } from 'http';
import type {
IDataObject,
IExecuteFunctions,
@@ -105,6 +106,7 @@ export class MicrosoftOneDrive implements INodeType {
responseData = await microsoftApiRequest.call(this, 'GET', `/drive/items/${fileId}`);
const fileName = responseData.name;
const downloadUrl = responseData['@microsoft.graph.downloadUrl'];
if (responseData.file === undefined) {
throw new NodeApiError(this.getNode(), responseData as JsonObject, {
@@ -117,16 +119,28 @@ export class MicrosoftOneDrive implements INodeType {
mimeType = responseData.file.mimeType;
}
responseData = await microsoftApiRequest.call(
this,
'GET',
`/drive/items/${fileId}/content`,
{},
{},
undefined,
{},
{ encoding: null, resolveWithFullResponse: true },
);
try {
responseData = await microsoftApiRequest.call(
this,
'GET',
`/drive/items/${fileId}/content`,
{},
{},
undefined,
{},
{ encoding: null, resolveWithFullResponse: true },
);
} catch (error) {
if (downloadUrl) {
responseData = await this.helpers.httpRequest({
method: 'GET',
url: downloadUrl,
returnFullResponse: true,
encoding: 'arraybuffer',
json: false,
});
}
}
const newItem: INodeExecutionData = {
json: items[i].json,
@@ -146,10 +160,15 @@ export class MicrosoftOneDrive implements INodeType {
items[i] = newItem;
const data = Buffer.from(responseData.body as Buffer);
let data;
if (responseData?.body instanceof IncomingMessage) {
data = responseData.body;
} else {
data = Buffer.from(responseData.body as Buffer);
}
items[i].binary![dataPropertyNameDownload] = await this.helpers.prepareBinaryData(
data as unknown as Buffer,
data,
fileName as string,
mimeType,
);