mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
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:
@@ -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,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user