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 @@
import type { FileProperties } from '../../Interfaces';
export const fileDelDescription: FileProperties = [
{
displayName: 'File ID',
name: 'fileId',
type: 'string',
required: true,
displayOptions: {
show: {
operation: ['delete'],
resource: ['file'],
},
},
default: '',
description: 'ID of the file',
},
];

View File

@@ -0,0 +1,20 @@
import type { IExecuteFunctions, IDataObject, INodeExecutionData } from 'n8n-workflow';
import { apiRequest } from '../../../transport';
export async function del(this: IExecuteFunctions, index: number): Promise<INodeExecutionData[]> {
const body: IDataObject = {};
const requestMethod = 'DELETE';
//meta data
const fileId: string = this.getNodeParameter('fileId', index) as string;
//endpoint
const endpoint = `files/${fileId}`;
//response
await apiRequest.call(this, requestMethod, endpoint, body);
//return
return this.helpers.returnJsonArray({ success: true });
}

View File

@@ -0,0 +1,4 @@
import { fileDelDescription as description } from './description';
import { del as execute } from './execute';
export { description, execute };

View File

@@ -0,0 +1,32 @@
import type { FileProperties } from '../../Interfaces';
export const fileDownloadDescription: FileProperties = [
{
displayName: 'File ID',
name: 'fileId',
type: 'string',
required: true,
displayOptions: {
show: {
operation: ['download'],
resource: ['file'],
},
},
default: '',
description: 'ID of the file',
},
{
displayName: 'Put Output In Field',
name: 'output',
type: 'string',
default: 'data',
required: true,
description: 'The name of the output field to put the binary file data in',
displayOptions: {
show: {
operation: ['download'],
resource: ['file'],
},
},
},
];

View File

@@ -0,0 +1,57 @@
import type { IExecuteFunctions, IDataObject, INodeExecutionData } from 'n8n-workflow';
import { apiRequest } from '../../../transport';
export async function download(this: IExecuteFunctions, index: number) {
const body: IDataObject = {};
const requestMethod = 'GET';
const items = this.getInputData();
//meta data
const fileId: string = this.getNodeParameter('fileId', index) as string;
const output: string = this.getNodeParameter('output', index) as string;
//endpoint
const endpoint = `files/${fileId}/`;
//response
const response = await apiRequest.call(this, requestMethod, endpoint, body, {} as IDataObject, {
encoding: null,
json: false,
resolveWithFullResponse: true,
});
let mimeType = response.headers['content-type'] as string | undefined;
mimeType = mimeType ? mimeType.split(';').find((value) => value.includes('/')) : undefined;
const contentDisposition = response.headers['content-disposition'];
const fileNameRegex = /(?<=filename=").*\b/;
const match = fileNameRegex.exec(contentDisposition as string);
let fileName = '';
// file name was found
if (match !== null) {
fileName = match[0];
}
const newItem: INodeExecutionData = {
json: items[index].json,
binary: {},
};
if (items[index].binary !== undefined && newItem.binary) {
// Create a shallow copy of the binary data so that the old
// data references which do not get changed still stay behind
// but the incoming data does not get changed.
Object.assign(newItem.binary, items[index].binary);
}
newItem.binary = {
[output]: await this.helpers.prepareBinaryData(
response.body as unknown as Buffer,
fileName,
mimeType,
),
};
return [newItem as unknown as INodeExecutionData[]];
}

View File

@@ -0,0 +1,4 @@
import { fileDownloadDescription as description } from './description';
import { download as execute } from './execute';
export { description, execute };

View File

@@ -0,0 +1,48 @@
import type { FileProperties } from '../../Interfaces';
export const fileGetAllDescription: FileProperties = [
{
displayName: 'Return All',
name: 'returnAll',
type: 'boolean',
default: false,
description: 'Whether to return all results or only up to a given limit',
displayOptions: {
show: {
operation: ['getAll'],
resource: ['file'],
},
},
},
{
displayName: 'Limit',
name: 'limit',
type: 'number',
default: 5,
description: 'Max number of results to return',
typeOptions: {
minValue: 1,
maxValue: 1000,
},
displayOptions: {
show: {
operation: ['getAll'],
resource: ['file'],
returnAll: [false],
},
},
},
{
displayName: 'Simplify',
name: 'simplifyOutput',
type: 'boolean',
default: true,
displayOptions: {
show: {
operation: ['getAll'],
resource: ['file'],
},
},
description: 'Whether to return a simplified version of the response instead of the raw data',
},
];

View File

@@ -0,0 +1,47 @@
import type { IExecuteFunctions, IDataObject, INodeExecutionData } from 'n8n-workflow';
import { apiRequest } from '../../../transport';
export async function getAll(
this: IExecuteFunctions,
index: number,
): Promise<INodeExecutionData[]> {
const body: IDataObject = {};
const requestMethod = 'GET';
const endpoint = 'files/view';
//limit parameters
const simplifyOutput: boolean = this.getNodeParameter('simplifyOutput', index) as boolean;
const returnAll: boolean = this.getNodeParameter('returnAll', 0, false);
const limit: number = this.getNodeParameter('limit', 0, 0);
//response
const responseData = await apiRequest.call(this, requestMethod, endpoint, body);
const onlyFilesArray = [];
//return only files without categories
if (simplifyOutput) {
for (let i = 0; i < responseData.categories.length; i++) {
if (responseData.categories[i].hasOwnProperty('files')) {
for (let j = 0; j < responseData.categories[i].files.length; j++) {
onlyFilesArray.push(responseData.categories[i].files[j]);
}
}
}
if (!returnAll && onlyFilesArray.length > limit) {
return this.helpers.returnJsonArray(onlyFilesArray.slice(0, limit));
} else {
return this.helpers.returnJsonArray(onlyFilesArray);
}
}
//return limited result
if (!returnAll && responseData.categories.length > limit) {
return this.helpers.returnJsonArray(responseData.categories.slice(0, limit) as IDataObject[]);
}
//return
return this.helpers.returnJsonArray(responseData.categories as IDataObject[]);
}

View File

@@ -0,0 +1,4 @@
import { fileGetAllDescription as description } from './description';
import { getAll as execute } from './execute';
export { description, execute };

View File

@@ -0,0 +1,61 @@
import type { INodeProperties } from 'n8n-workflow';
import * as del from './del';
import * as download from './download';
import * as getAll from './getAll';
import * as update from './update';
import * as upload from './upload';
export { del, download, getAll, update, upload };
export const descriptions: INodeProperties[] = [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
displayOptions: {
show: {
resource: ['file'],
},
},
options: [
{
name: 'Delete',
value: 'delete',
description: 'Delete a company file',
action: 'Delete a file',
},
{
name: 'Download',
value: 'download',
description: 'Download a company file',
action: 'Download a file',
},
{
name: 'Get Many',
value: 'getAll',
description: 'Get many company files',
action: 'Get many files',
},
{
name: 'Update',
value: 'update',
description: 'Update a company file',
action: 'Update a file',
},
{
name: 'Upload',
value: 'upload',
description: 'Upload a company file',
action: 'Upload a file',
},
],
default: 'delete',
},
...del.description,
...download.description,
...getAll.description,
...update.description,
...upload.description,
];

View File

@@ -0,0 +1,58 @@
import type { FileProperties } from '../../Interfaces';
export const fileUpdateDescription: FileProperties = [
{
displayName: 'File ID',
name: 'fileId',
type: 'string',
required: true,
displayOptions: {
show: {
operation: ['update'],
resource: ['file'],
},
},
default: '',
description: 'ID of the file',
},
{
displayName: 'Update Fields',
name: 'updateFields',
type: 'collection',
placeholder: 'Add Field',
default: {},
displayOptions: {
show: {
operation: ['update'],
resource: ['file'],
},
},
options: [
{
displayName: 'Category Name or ID',
name: 'categoryId',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getCompanyFileCategories',
},
default: '',
description:
'Move the file to a different category. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
},
{
displayName: 'Name',
name: 'name',
type: 'string',
default: '',
description: 'New name of the file',
},
{
displayName: 'Share with Employee',
name: 'shareWithEmployee',
type: 'boolean',
default: true,
description: 'Whether this file is shared or not',
},
],
},
];

View File

@@ -0,0 +1,32 @@
import type { IExecuteFunctions, IDataObject, INodeExecutionData } from 'n8n-workflow';
import { apiRequest } from '../../../transport';
export async function update(
this: IExecuteFunctions,
index: number,
): Promise<INodeExecutionData[]> {
const body: IDataObject = {};
const requestMethod = 'POST';
//meta data
const fileId: string = this.getNodeParameter('fileId', index) as string;
//endpoint
const endpoint = `files/${fileId}`;
//body parameters
const shareWithEmployee = this.getNodeParameter(
'updateFields.shareWithEmployee',
index,
true,
) as boolean;
body.shareWithEmployee = shareWithEmployee ? 'yes' : 'no';
//response
await apiRequest.call(this, requestMethod, endpoint, body);
//return
return this.helpers.returnJsonArray({ success: true });
}

View File

@@ -0,0 +1,4 @@
import { fileUpdateDescription as description } from './description';
import { update as execute } from './execute';
export { description, execute };

View File

@@ -0,0 +1,59 @@
import type { INodeProperties } from 'n8n-workflow';
export const fileUploadDescription: INodeProperties[] = [
{
displayName: 'Input Data Field Name',
name: 'binaryPropertyName',
type: 'string',
default: 'data',
displayOptions: {
show: {
operation: ['upload'],
resource: ['file'],
},
},
required: true,
description:
'The name of the input field containing the binary file data to be uploaded. Supported file types: PNG, JPEG.',
},
{
displayName: 'Category Name or ID',
name: 'categoryId',
type: 'options',
description:
'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>',
typeOptions: {
loadOptionsMethod: 'getCompanyFileCategories',
},
required: true,
displayOptions: {
show: {
operation: ['upload'],
resource: ['file'],
},
},
default: '',
},
{
displayName: 'Options',
name: 'options',
type: 'collection',
placeholder: 'Add Field',
displayOptions: {
show: {
operation: ['upload'],
resource: ['file'],
},
},
default: {},
options: [
{
displayName: 'Share with Employee',
name: 'share',
type: 'boolean',
default: true,
description: 'Whether this file is shared or not',
},
],
},
];

View File

@@ -0,0 +1,40 @@
import type { IDataObject, IExecuteFunctions } from 'n8n-workflow';
import { apiRequest } from '../../../transport';
export async function upload(this: IExecuteFunctions, index: number) {
let body: IDataObject = {};
const requestMethod = 'POST';
const category = this.getNodeParameter('categoryId', index) as string;
const share = this.getNodeParameter('options.share', index, true) as boolean;
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', index);
const { fileName, mimeType } = this.helpers.assertBinaryData(index, binaryPropertyName);
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(index, binaryPropertyName);
body = {
json: false,
formData: {
file: {
value: binaryDataBuffer,
options: {
filename: fileName,
contentType: mimeType,
},
},
fileName,
category,
},
resolveWithFullResponse: true,
};
if (body.formData) {
Object.assign(body.formData, share ? { share: 'yes' } : { share: 'no' });
}
//endpoint
const endpoint = 'files';
const { headers } = await apiRequest.call(this, requestMethod, endpoint, {}, {}, body);
return this.helpers.returnJsonArray({ fileId: headers.location.split('/').pop() });
}

View File

@@ -0,0 +1,4 @@
import { fileUploadDescription as description } from './description';
import { upload as execute } from './execute';
export { description, execute };