pull:初次提交

This commit is contained in:
Yep_Q
2025-09-08 04:48:28 +08:00
parent 5c0619656d
commit f64f498365
11751 changed files with 1953723 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
{
"node": "n8n-nodes-base.awsTranscribe",
"nodeVersion": "1.0",
"codexVersion": "1.0",
"categories": ["Development"],
"resources": {
"credentialDocumentation": [
{
"url": "https://docs.n8n.io/integrations/builtin/credentials/aws/"
}
],
"primaryDocumentation": [
{
"url": "https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-base.awstranscribe/"
}
]
}
}

View File

@@ -0,0 +1,553 @@
import type {
IExecuteFunctions,
IDataObject,
INodeExecutionData,
INodeType,
INodeTypeDescription,
} from 'n8n-workflow';
import { NodeConnectionTypes } from 'n8n-workflow';
import { awsApiRequestREST, awsApiRequestRESTAllItems } from './GenericFunctions';
export class AwsTranscribe implements INodeType {
description: INodeTypeDescription = {
displayName: 'AWS Transcribe',
name: 'awsTranscribe',
icon: 'file:transcribe.svg',
group: ['output'],
version: 1,
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
description: 'Sends data to AWS Transcribe',
defaults: {
name: 'AWS Transcribe',
},
usableAsTool: true,
inputs: [NodeConnectionTypes.Main],
outputs: [NodeConnectionTypes.Main],
credentials: [
{
name: 'aws',
required: true,
},
],
properties: [
{
displayName: 'Resource',
name: 'resource',
type: 'options',
noDataExpression: true,
options: [
{
name: 'Transcription Job',
value: 'transcriptionJob',
},
],
default: 'transcriptionJob',
},
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
options: [
{
name: 'Create',
value: 'create',
description: 'Create a transcription job',
action: 'Create a transcription job',
},
{
name: 'Delete',
value: 'delete',
description: 'Delete a transcription job',
action: 'Delete a transcription job',
},
{
name: 'Get',
value: 'get',
description: 'Get a transcription job',
action: 'Get a transcription job',
},
{
name: 'Get Many',
value: 'getAll',
description: 'Get many transcription jobs',
action: 'Get many transcription jobs',
},
],
default: 'create',
},
{
displayName: 'Job Name',
name: 'transcriptionJobName',
type: 'string',
default: '',
displayOptions: {
show: {
resource: ['transcriptionJob'],
operation: ['create', 'get', 'delete'],
},
},
description: 'The name of the job',
},
{
displayName: 'Media File URI',
name: 'mediaFileUri',
type: 'string',
default: '',
displayOptions: {
show: {
resource: ['transcriptionJob'],
operation: ['create'],
},
},
description: 'The S3 object location of the input media file',
},
{
displayName: 'Detect Language',
name: 'detectLanguage',
type: 'boolean',
displayOptions: {
show: {
resource: ['transcriptionJob'],
operation: ['create'],
},
},
default: false,
description:
'Whether to set this field to true to enable automatic language identification',
},
{
displayName: 'Language',
name: 'languageCode',
type: 'options',
options: [
{
name: 'American English',
value: 'en-US',
},
{
name: 'British English',
value: 'en-GB',
},
{
name: 'German',
value: 'de-DE',
},
{
name: 'Indian English',
value: 'en-IN',
},
{
name: 'Irish English',
value: 'en-IE',
},
{
name: 'Russian',
value: 'ru-RU',
},
{
name: 'Spanish',
value: 'es-ES',
},
],
displayOptions: {
show: {
resource: ['transcriptionJob'],
operation: ['create'],
detectLanguage: [false],
},
},
default: 'en-US',
description: 'Language used in the input media file',
},
// ----------------------------------
// Transcription Job Settings
// ----------------------------------
{
displayName: 'Options',
name: 'options',
type: 'collection',
placeholder: 'Add option',
displayOptions: {
show: {
operation: ['create'],
},
},
default: {},
options: [
{
displayName: 'Channel Identification',
name: 'channelIdentification',
type: 'boolean',
default: false,
// eslint-disable-next-line n8n-nodes-base/node-param-description-boolean-without-whether
description:
"Instructs Amazon Transcribe to process each audiochannel separately and then merge the transcription output of each channel into a single transcription. You can't set both Max Speaker Labels and Channel Identification in the same request. If you set both, your request returns a BadRequestException.",
},
{
displayName: 'Max Alternatives',
name: 'maxAlternatives',
type: 'number',
default: 2,
typeOptions: {
minValue: 2,
maxValue: 10,
},
description: 'The number of alternative transcriptions that the service should return',
},
{
displayName: 'Max Speaker Labels',
name: 'maxSpeakerLabels',
type: 'number',
default: 2,
typeOptions: {
minValue: 2,
maxValue: 10,
},
description:
'The maximum number of speakers to identify in the input audio. If there are more speakers in the audio than this number, multiple speakers are identified as a single speaker.',
},
{
displayName: 'Vocabulary Name',
name: 'vocabularyName',
type: 'string',
default: '',
description: 'Name of vocabulary to use when processing the transcription job',
},
{
displayName: 'Vocabulary Filter Name',
name: 'vocabularyFilterName',
type: 'string',
default: '',
description:
'The name of the vocabulary filter to use when transcribing the audio. The filter that you specify must have the same language code as the transcription job.',
},
{
displayName: 'Vocabulary Filter Method',
name: 'vocabularyFilterMethod',
type: 'options',
options: [
{
name: 'Remove',
value: 'remove',
},
{
name: 'Mask',
value: 'mask',
},
{
name: 'Tag',
value: 'tag',
},
],
default: 'remove',
description:
'<p>Set to mask to remove filtered text from the transcript and replace it with three asterisks ("***") as placeholder text.</p><p>Set to remove to remove filtered text from the transcript without using placeholder text. Set to tag to mark the word in the transcription output that matches the vocabulary filter. When you set the filter method to tag, the words matching your vocabulary filter are not masked or removed.</p>',
},
],
},
{
displayName: 'Return Transcript',
name: 'returnTranscript',
type: 'boolean',
default: true,
displayOptions: {
show: {
resource: ['transcriptionJob'],
operation: ['get'],
},
},
// eslint-disable-next-line n8n-nodes-base/node-param-description-boolean-without-whether
description:
'By default, the response only contains metadata about the transcript. Enable this option to retrieve the transcript instead.',
},
{
displayName: 'Simplify',
name: 'simple',
type: 'boolean',
displayOptions: {
show: {
resource: ['transcriptionJob'],
operation: ['get'],
returnTranscript: [true],
},
},
default: true,
description:
'Whether to return a simplified version of the response instead of the raw data',
},
{
displayName: 'Return All',
name: 'returnAll',
type: 'boolean',
displayOptions: {
show: {
resource: ['transcriptionJob'],
operation: ['getAll'],
},
},
default: false,
description: 'Whether to return all results or only up to a given limit',
},
{
displayName: 'Limit',
name: 'limit',
type: 'number',
default: 20,
typeOptions: {
minValue: 1,
},
displayOptions: {
show: {
resource: ['transcriptionJob'],
operation: ['getAll'],
returnAll: [false],
},
},
description: 'Max number of results to return',
},
{
displayName: 'Filters',
name: 'filters',
type: 'collection',
placeholder: 'Add Filter',
default: {},
displayOptions: {
show: {
resource: ['transcriptionJob'],
operation: ['getAll'],
},
},
options: [
{
displayName: 'Job Name Contains',
name: 'jobNameContains',
type: 'string',
description: 'Return only transcription jobs whose name contains the specified string',
default: '',
},
{
displayName: 'Status',
name: 'status',
type: 'options',
options: [
{
name: 'Completed',
value: 'COMPLETED',
},
{
name: 'Failed',
value: 'FAILED',
},
{
name: 'In Progress',
value: 'IN_PROGRESS',
},
{
name: 'Queued',
value: 'QUEUED',
},
],
description: 'Return only transcription jobs with the specified status',
default: 'COMPLETED',
},
],
},
],
};
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const items = this.getInputData();
const returnData: IDataObject[] = [];
let responseData;
const resource = this.getNodeParameter('resource', 0);
const operation = this.getNodeParameter('operation', 0);
for (let i = 0; i < items.length; i++) {
try {
if (resource === 'transcriptionJob') {
//https://docs.aws.amazon.com/comprehend/latest/dg/API_DetectDominantLanguage.html
if (operation === 'create') {
const transcriptionJobName = this.getNodeParameter('transcriptionJobName', i) as string;
const mediaFileUri = this.getNodeParameter('mediaFileUri', i) as string;
const detectLang = this.getNodeParameter('detectLanguage', i) as boolean;
const options = this.getNodeParameter('options', i, {});
const body: IDataObject = {
TranscriptionJobName: transcriptionJobName,
Media: {
MediaFileUri: mediaFileUri,
},
Settings: {},
};
if (detectLang) {
body.IdentifyLanguage = detectLang;
} else {
body.LanguageCode = this.getNodeParameter('languageCode', i) as string;
}
if (body.Settings) {
if (options.channelIdentification) {
Object.assign(body.Settings, {
ChannelIdentification: options.channelIdentification,
});
}
if (options.maxAlternatives) {
Object.assign(body.Settings, {
ShowAlternatives: true,
MaxAlternatives: options.maxAlternatives,
});
}
if (options.maxSpeakerLabels) {
Object.assign(body.Settings, {
ShowSpeakerLabels: true,
MaxSpeakerLabels: options.maxSpeakerLabels,
});
}
if (options.vocabularyName) {
Object.assign(body.Settings, {
VocabularyName: options.vocabularyName,
});
}
if (options.vocabularyFilterName) {
Object.assign(body.Settings, {
VocabularyFilterName: options.vocabularyFilterName,
});
}
if (options.vocabularyFilterMethod) {
Object.assign(body.Settings, {
VocabularyFilterMethod: options.vocabularyFilterMethod,
});
}
}
const action = 'Transcribe.StartTranscriptionJob';
responseData = await awsApiRequestREST.call(
this,
'transcribe',
'POST',
'',
JSON.stringify(body),
{ 'x-amz-target': action, 'Content-Type': 'application/x-amz-json-1.1' },
);
responseData = responseData.TranscriptionJob;
}
//https://docs.aws.amazon.com/transcribe/latest/dg/API_DeleteTranscriptionJob.html
if (operation === 'delete') {
const transcriptionJobName = this.getNodeParameter('transcriptionJobName', i) as string;
const body: IDataObject = {
TranscriptionJobName: transcriptionJobName,
};
const action = 'Transcribe.DeleteTranscriptionJob';
responseData = await awsApiRequestREST.call(
this,
'transcribe',
'POST',
'',
JSON.stringify(body),
{ 'x-amz-target': action, 'Content-Type': 'application/x-amz-json-1.1' },
);
responseData = { success: true };
}
//https://docs.aws.amazon.com/transcribe/latest/dg/API_GetTranscriptionJob.html
if (operation === 'get') {
const transcriptionJobName = this.getNodeParameter('transcriptionJobName', i) as string;
const resolve = this.getNodeParameter('returnTranscript', 0) as boolean;
const body: IDataObject = {
TranscriptionJobName: transcriptionJobName,
};
const action = 'Transcribe.GetTranscriptionJob';
responseData = await awsApiRequestREST.call(
this,
'transcribe',
'POST',
'',
JSON.stringify(body),
{ 'x-amz-target': action, 'Content-Type': 'application/x-amz-json-1.1' },
);
responseData = responseData.TranscriptionJob;
if (resolve && responseData.TranscriptionJobStatus === 'COMPLETED') {
responseData = await this.helpers.request({
method: 'GET',
uri: responseData.Transcript.TranscriptFileUri,
json: true,
});
const simple = this.getNodeParameter('simple', 0) as boolean;
if (simple) {
responseData = {
transcript: responseData.results.transcripts
.map((data: IDataObject) => data.transcript)
.join(' '),
};
}
}
}
//https://docs.aws.amazon.com/transcribe/latest/dg/API_ListTranscriptionJobs.html
if (operation === 'getAll') {
const returnAll = this.getNodeParameter('returnAll', i);
const filters = this.getNodeParameter('filters', i);
const action = 'Transcribe.ListTranscriptionJobs';
const body: IDataObject = {};
if (filters.status) {
body.Status = filters.status;
}
if (filters.jobNameContains) {
body.JobNameContains = filters.jobNameContains;
}
if (returnAll) {
responseData = await awsApiRequestRESTAllItems.call(
this,
'TranscriptionJobSummaries',
'transcribe',
'POST',
'',
JSON.stringify(body),
{ 'x-amz-target': action, 'Content-Type': 'application/x-amz-json-1.1' },
);
} else {
const limit = this.getNodeParameter('limit', i);
body.MaxResults = limit;
responseData = await awsApiRequestREST.call(
this,
'transcribe',
'POST',
'',
JSON.stringify(body),
{ 'x-amz-target': action, 'Content-Type': 'application/x-amz-json-1.1' },
);
responseData = responseData.TranscriptionJobSummaries;
}
}
}
if (Array.isArray(responseData)) {
returnData.push.apply(returnData, responseData as IDataObject[]);
} else {
returnData.push(responseData as IDataObject);
}
} catch (error) {
if (this.continueOnFail()) {
returnData.push({ error: error.message });
continue;
}
throw error;
}
}
return [this.helpers.returnJsonArray(returnData)];
}
}

View File

@@ -0,0 +1,128 @@
import type { Request } from 'aws4';
import { sign } from 'aws4';
import get from 'lodash/get';
import type {
ICredentialDataDecryptedObject,
IDataObject,
IExecuteFunctions,
IHookFunctions,
IHttpRequestMethods,
ILoadOptionsFunctions,
IRequestOptions,
IWebhookFunctions,
JsonObject,
} from 'n8n-workflow';
import { NodeApiError } from 'n8n-workflow';
import { URL } from 'url';
function getEndpointForService(
service: string,
credentials: ICredentialDataDecryptedObject,
): string {
let endpoint;
if (service === 'lambda' && credentials.lambdaEndpoint) {
endpoint = credentials.lambdaEndpoint;
} else if (service === 'sns' && credentials.snsEndpoint) {
endpoint = credentials.snsEndpoint;
} else {
endpoint = `https://${service}.${credentials.region}.amazonaws.com`;
}
return (endpoint as string).replace('{region}', credentials.region as string);
}
export async function awsApiRequest(
this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions | IWebhookFunctions,
service: string,
method: IHttpRequestMethods,
path: string,
body?: string,
headers?: object,
): Promise<any> {
const credentials = await this.getCredentials('aws');
// Concatenate path and instantiate URL object so it parses correctly query strings
const endpoint = new URL(getEndpointForService(service, credentials) + path);
// Sign AWS API request with the user credentials
const signOpts = { headers: headers || {}, host: endpoint.host, method, path, body } as Request;
const securityHeaders = {
accessKeyId: `${credentials.accessKeyId}`.trim(),
secretAccessKey: `${credentials.secretAccessKey}`.trim(),
sessionToken: credentials.temporaryCredentials
? `${credentials.sessionToken}`.trim()
: undefined,
};
sign(signOpts, securityHeaders);
const options: IRequestOptions = {
headers: signOpts.headers,
method,
uri: endpoint.href,
body: signOpts.body,
};
try {
return await this.helpers.request(options);
} catch (error) {
throw new NodeApiError(this.getNode(), error as JsonObject); // no XML parsing needed
}
}
export async function awsApiRequestREST(
this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions,
service: string,
method: IHttpRequestMethods,
path: string,
body?: string,
headers?: object,
): Promise<any> {
const response = await awsApiRequest.call(this, service, method, path, body, headers);
try {
return JSON.parse(response as string);
} catch (error) {
return response;
}
}
export async function awsApiRequestRESTAllItems(
this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions,
propertyName: string,
service: string,
method: IHttpRequestMethods,
path: string,
body?: string,
query: IDataObject = {},
_headers: IDataObject = {},
_option: IDataObject = {},
_region?: string,
): Promise<any> {
const returnData: IDataObject[] = [];
let responseData;
const propertyNameArray = propertyName.split('.');
do {
responseData = await awsApiRequestREST.call(this, service, method, path, body, query);
if (get(responseData, [propertyNameArray[0], propertyNameArray[1], 'NextToken'])) {
query.NextToken = get(responseData, [
propertyNameArray[0],
propertyNameArray[1],
'NextToken',
]);
}
if (get(responseData, propertyName)) {
if (Array.isArray(get(responseData, propertyName))) {
returnData.push.apply(returnData, get(responseData, propertyName) as IDataObject[]);
} else {
returnData.push(get(responseData, propertyName) as IDataObject);
}
}
} while (
get(responseData, [propertyNameArray[0], propertyNameArray[1], 'NextToken']) !== undefined
);
return returnData;
}

View File

@@ -0,0 +1,26 @@
{
"type": "object",
"properties": {
"IdentifyLanguage": {
"type": "boolean"
},
"Media": {
"type": "object",
"properties": {
"MediaFileUri": {
"type": "string"
}
}
},
"StartTime": {
"type": "number"
},
"TranscriptionJobName": {
"type": "string"
},
"TranscriptionJobStatus": {
"type": "string"
}
},
"version": 1
}

View File

@@ -0,0 +1,43 @@
{
"type": "object",
"properties": {
"CreationTime": {
"type": "number"
},
"Media": {
"type": "object",
"properties": {
"MediaFileUri": {
"type": "string"
}
},
"required": [
"MediaFileUri"
]
},
"Settings": {
"type": "object",
"properties": {
"ChannelIdentification": {
"type": "boolean"
},
"ShowAlternatives": {
"type": "boolean"
}
},
"required": [
"ChannelIdentification",
"ShowAlternatives"
]
},
"StartTime": {
"type": "number"
},
"TranscriptionJobName": {
"type": "string"
},
"TranscriptionJobStatus": {
"type": "string"
}
}
}

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" fill="none"><path fill="url(#a)" d="M100 0H0v100h100z"/><path fill="#fff" d="M18.347 83.333a1.68 1.68 0 0 1-1.48-2.466l5.6-10.907a20.83 20.83 0 0 1-2.987-10.773A21.267 21.267 0 0 1 53.52 42.32l-1.6 2.133a18.507 18.507 0 0 0-26.813 24.72 1.33 1.33 0 0 1 .066 1.334l-4.586 8.933 9.173-4.56a1.33 1.33 0 0 1 1.333.067 18.666 18.666 0 0 0 25.214-5.614l2.213 1.48A21.333 21.333 0 0 1 30.307 77.6l-11.2 5.56a1.75 1.75 0 0 1-.76.173m34.32-29.16H50V62h2.667zm-4-5.453H46v18.667h2.667zm-4 4H42v10.667h2.667zm-4-4H38v18.667h2.667zm-4 2.667H34V64.72h2.667zm-4-1.334H30v16h2.667zm-4 4H26v9.334h2.667zM83.333 68.72V47.387h-2.666v20h-20v2.666H82a1.334 1.334 0 0 0 1.333-1.386zm-.4-38.32-13.44-13.333a1.25 1.25 0 0 0-.826-.374h-24a1.333 1.333 0 0 0-1.334 1.334V35.36H46v-16h21.333v12a1.186 1.186 0 0 0 1.227 1.333h12.107v6.667h2.666v-8a1.34 1.34 0 0 0-.4-1.013zM70 30.053v-8.866L78.747 30zm5.333 5.334H62v2.666h13.333zM74 40.72H56.667v2.667H74zM62 27.387H51.333v2.666H62zm-2.667 8h-8v2.666h8zm-2.666 14.666H54v16h2.667zm4 2.667H58v10.667h2.667z"/><defs><linearGradient id="a" x1="-20.707" x2="120.72" y1="120.707" y2="-20.72" gradientUnits="userSpaceOnUse"><stop stop-color="#055F4E"/><stop offset="1" stop-color="#56C0A7"/></linearGradient></defs></svg>

After

Width:  |  Height:  |  Size: 1.3 KiB