mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
fix(GitHub Node): File Create operation prevent duplicated base64 encoding (#10040)
This commit is contained in:
@@ -114,3 +114,8 @@ export async function githubApiRequestAllItems(
|
|||||||
} while (responseData.headers.link?.includes('next'));
|
} while (responseData.headers.link?.includes('next'));
|
||||||
return returnData;
|
return returnData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isBase64(content: string) {
|
||||||
|
const base64regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
|
||||||
|
return base64regex.test(content);
|
||||||
|
}
|
||||||
|
|||||||
@@ -9,7 +9,12 @@ import type {
|
|||||||
import { NodeOperationError } from 'n8n-workflow';
|
import { NodeOperationError } from 'n8n-workflow';
|
||||||
|
|
||||||
import { snakeCase } from 'change-case';
|
import { snakeCase } from 'change-case';
|
||||||
import { getFileSha, githubApiRequest, githubApiRequestAllItems } from './GenericFunctions';
|
import {
|
||||||
|
getFileSha,
|
||||||
|
githubApiRequest,
|
||||||
|
githubApiRequestAllItems,
|
||||||
|
isBase64,
|
||||||
|
} from './GenericFunctions';
|
||||||
|
|
||||||
import { getRepositories, getUsers } from './SearchFunctions';
|
import { getRepositories, getUsers } from './SearchFunctions';
|
||||||
|
|
||||||
@@ -1981,11 +1986,12 @@ export class Github implements INodeType {
|
|||||||
// TODO: Does this work with filesystem mode
|
// TODO: Does this work with filesystem mode
|
||||||
body.content = binaryData.data;
|
body.content = binaryData.data;
|
||||||
} else {
|
} else {
|
||||||
// Is text file
|
const fileContent = this.getNodeParameter('fileContent', i) as string;
|
||||||
// body.content = Buffer.from(this.getNodeParameter('fileContent', i) as string, 'base64');
|
if (isBase64(fileContent)) {
|
||||||
body.content = Buffer.from(
|
body.content = fileContent;
|
||||||
this.getNodeParameter('fileContent', i) as string,
|
} else {
|
||||||
).toString('base64');
|
body.content = Buffer.from(fileContent).toString('base64');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
endpoint = `/repos/${owner}/${repository}/contents/${encodeURI(filePath)}`;
|
endpoint = `/repos/${owner}/${repository}/contents/${encodeURI(filePath)}`;
|
||||||
|
|||||||
Reference in New Issue
Block a user