mirror of
https://github.com/n8n-io/n8n.git
synced 2024-09-19 08:57:09 +03:00
fix(Google Drive Node): Create from text operation (#9185)
This commit is contained in:
parent
1efeeccc5b
commit
d9e74949c4
@ -11,7 +11,7 @@ jest.mock('../../../../v2/transport', () => {
|
|||||||
return {
|
return {
|
||||||
...originalModule,
|
...originalModule,
|
||||||
googleApiRequest: jest.fn(async function () {
|
googleApiRequest: jest.fn(async function () {
|
||||||
return {};
|
return { id: 42 };
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@ -69,23 +69,34 @@ describe('test GoogleDriveV2: file createFromText', () => {
|
|||||||
|
|
||||||
await createFromText.execute.call(fakeExecuteFunction, 0);
|
await createFromText.execute.call(fakeExecuteFunction, 0);
|
||||||
|
|
||||||
expect(transport.googleApiRequest).toBeCalledTimes(1);
|
expect(transport.googleApiRequest).toBeCalledTimes(2);
|
||||||
expect(transport.googleApiRequest).toHaveBeenCalledWith(
|
expect(transport.googleApiRequest).toHaveBeenCalledWith(
|
||||||
'POST',
|
'POST',
|
||||||
'/upload/drive/v3/files',
|
'/upload/drive/v3/files',
|
||||||
'\n\t\t\n--XXXXXX\t\t\nContent-Type: application/json; charset=UTF-8\t\t\n\n{"name":"helloDrive.txt","parents":["folderIDxxxxxx"],"mimeType":"text/plain","properties":{"prop1":"value1","prop2":"value2"},"appProperties":{"appKey1":"appValue1"}}\t\t\n--XXXXXX\t\t\nContent-Type: text/plain\t\t\nContent-Transfer-Encoding: base64\t\t\n\nhello drive!\t\t\n--XXXXXX--',
|
expect.anything(), // Buffer of content goes here
|
||||||
|
{ uploadType: 'media' },
|
||||||
|
undefined,
|
||||||
|
{ headers: { 'Content-Length': 12, 'Content-Type': 'text/plain' } },
|
||||||
|
);
|
||||||
|
expect(transport.googleApiRequest).toHaveBeenCalledWith(
|
||||||
|
'PATCH',
|
||||||
|
'/drive/v3/files/42',
|
||||||
{
|
{
|
||||||
|
appProperties: { appKey1: 'appValue1' },
|
||||||
|
mimeType: 'text/plain',
|
||||||
|
name: 'helloDrive.txt',
|
||||||
|
properties: { prop1: 'value1', prop2: 'value2' },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
addParents: 'folderIDxxxxxx',
|
||||||
corpora: 'allDrives',
|
corpora: 'allDrives',
|
||||||
includeItemsFromAllDrives: true,
|
includeItemsFromAllDrives: true,
|
||||||
keepRevisionForever: true,
|
keepRevisionForever: true,
|
||||||
ocrLanguage: 'en',
|
ocrLanguage: 'en',
|
||||||
spaces: 'appDataFolder, drive',
|
spaces: 'appDataFolder, drive',
|
||||||
supportsAllDrives: true,
|
supportsAllDrives: true,
|
||||||
uploadType: 'multipart',
|
|
||||||
useContentAsIndexableText: true,
|
useContentAsIndexableText: true,
|
||||||
},
|
},
|
||||||
undefined,
|
|
||||||
{ headers: { 'Content-Length': 12, 'Content-Type': 'multipart/related; boundary=XXXXXX' } },
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -96,8 +96,6 @@ export async function execute(this: IExecuteFunctions, i: number): Promise<INode
|
|||||||
options,
|
options,
|
||||||
);
|
);
|
||||||
|
|
||||||
const boundary = 'XXXXXX';
|
|
||||||
|
|
||||||
const qs = setUpdateCommonParams(
|
const qs = setUpdateCommonParams(
|
||||||
{
|
{
|
||||||
includeItemsFromAllDrives: true,
|
includeItemsFromAllDrives: true,
|
||||||
@ -147,34 +145,36 @@ export async function execute(this: IExecuteFunctions, i: number): Promise<INode
|
|||||||
const content = Buffer.from(this.getNodeParameter('content', i, '') as string, 'utf8');
|
const content = Buffer.from(this.getNodeParameter('content', i, '') as string, 'utf8');
|
||||||
const contentLength = content.byteLength;
|
const contentLength = content.byteLength;
|
||||||
|
|
||||||
const body = `
|
const uploadData = await googleApiRequest.call(
|
||||||
\n--${boundary}\
|
|
||||||
\nContent-Type: application/json; charset=UTF-8\
|
|
||||||
\n\n${JSON.stringify(bodyParameters)}\
|
|
||||||
\n--${boundary}\
|
|
||||||
\nContent-Type: text/plain\
|
|
||||||
\nContent-Transfer-Encoding: base64\
|
|
||||||
\n\n${content}\
|
|
||||||
\n--${boundary}--`;
|
|
||||||
|
|
||||||
const responseData = await googleApiRequest.call(
|
|
||||||
this,
|
this,
|
||||||
'POST',
|
'POST',
|
||||||
'/upload/drive/v3/files',
|
'/upload/drive/v3/files',
|
||||||
body,
|
content,
|
||||||
{
|
{
|
||||||
uploadType: 'multipart',
|
uploadType: 'media',
|
||||||
...qs,
|
|
||||||
},
|
},
|
||||||
undefined,
|
undefined,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': `multipart/related; boundary=${boundary}`,
|
'Content-Type': mimeType,
|
||||||
'Content-Length': contentLength,
|
'Content-Length': contentLength,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const uploadId = uploadData.id;
|
||||||
|
|
||||||
|
qs.addParents = setParentFolder(folderId, driveId);
|
||||||
|
delete bodyParameters.parents;
|
||||||
|
|
||||||
|
const responseData = await googleApiRequest.call(
|
||||||
|
this,
|
||||||
|
'PATCH',
|
||||||
|
`/drive/v3/files/${uploadId}`,
|
||||||
|
bodyParameters,
|
||||||
|
qs,
|
||||||
|
);
|
||||||
|
|
||||||
response = { id: responseData.id };
|
response = { id: responseData.id };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user