@luka-cat-mimi/n8n-nodes-feishu-project
Version:
飞书项目 N8N 集成插件,支持附件管理等功能
75 lines • 2.81 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const RequestUtils_1 = __importDefault(require("../../../help/utils/RequestUtils"));
const AttachmentUploadOperate = {
name: '添加附件',
value: 'attachment:upload',
options: [
{
displayName: '项目Key',
name: 'project_key',
type: 'string',
required: true,
default: '',
description: '项目的唯一标识Key',
},
{
displayName: '工作项ID',
name: 'work_item_id',
type: 'string',
required: true,
default: '',
description: '工作项的唯一标识ID',
},
{
displayName: '二进制数据字段名',
name: 'binaryPropertyName',
type: 'string',
required: true,
default: 'data',
description: '包含要上传文件的二进制数据字段名',
},
{
displayName: '字段Key',
name: 'field_key',
type: 'string',
required: true,
default: '',
description: '字段的唯一标识Key',
},
],
async call(index) {
const project_key = this.getNodeParameter('project_key', index);
const work_item_id = this.getNodeParameter('work_item_id', index);
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', index);
const field_key = this.getNodeParameter('field_key', index);
const items = this.getInputData();
const binaryData = items[index].binary;
if (!binaryData || !binaryData[binaryPropertyName]) {
throw new Error(`在索引 ${index} 的项目中未找到二进制数据 "${binaryPropertyName}"`);
}
const fileInfo = binaryData[binaryPropertyName];
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(index, binaryPropertyName);
const formData = {
file: {
value: binaryDataBuffer,
options: {
filename: fileInfo.fileName || 'file',
contentType: fileInfo.mimeType || 'application/octet-stream',
},
},
field_key: field_key,
};
return RequestUtils_1.default.request.call(this, {
method: 'POST',
url: `/open_api/${project_key}/work_item/story/${work_item_id}/file/upload`,
formData: formData,
json: true,
});
}
};
exports.default = AttachmentUploadOperate;
//# sourceMappingURL=AttachmentUploadOperate.js.map