@luka-cat-mimi/n8n-nodes-feishu-project
Version:
飞书项目 N8N 集成插件,支持附件管理等功能
154 lines • 5.83 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 description_1 = require("../../../help/description");
const ViewPanoramicOperate = {
name: '获取视图下工作项列表(全景视图)',
value: 'view:panoramic',
order: 30,
options: [
description_1.DESCRIPTIONS.PROJECT_KEY,
{
displayName: '视图ID',
name: 'view_id',
type: 'string',
required: true,
default: '',
description: '视图的唯一标识ID',
},
{
displayName: 'Return All',
name: 'returnAll',
type: 'boolean',
default: false,
description: 'Whether to return all results or only up to a given limit',
},
{
displayName: 'Limit',
name: 'limit',
type: 'number',
default: 50,
typeOptions: {
minValue: 1,
},
displayOptions: {
show: {
returnAll: [false],
},
},
description: 'Max number of results to return',
},
{
displayName: 'Options',
name: 'options',
type: 'collection',
placeholder: 'Add option',
default: {},
options: [
{
displayName: 'Need Workflow',
name: 'need_workflow',
type: 'boolean',
default: true,
description: 'Whether to include workflow information',
},
{
displayName: 'Relation Fields Detail',
name: 'relation_fields_detail',
type: 'boolean',
default: true,
description: 'Whether to include related fields detail',
},
{
displayName: 'Need Multi Text',
name: 'need_multi_text',
type: 'boolean',
default: true,
description: 'Whether to include rich text detail',
},
{
displayName: 'Need User Detail',
name: 'need_user_detail',
type: 'boolean',
default: true,
description: 'Whether to include user detail',
},
{
displayName: 'Need Sub Task Parent',
name: 'need_sub_task_parent',
type: 'boolean',
default: true,
description: 'Whether to include sub task parent info',
},
{
displayName: 'Timeout',
name: 'timeout',
type: 'number',
default: 10000,
description: '请求超时时间(毫秒)',
},
],
},
],
async call(index) {
const project_key = this.getNodeParameter('project_key', index, '', {
extractValue: true,
});
const view_id = this.getNodeParameter('view_id', index);
const returnAll = this.getNodeParameter('returnAll', index, false);
const limit = this.getNodeParameter('limit', index, 50);
const options = this.getNodeParameter('options', index, {});
const expand = {
need_workflow: options.need_workflow !== false,
relation_fields_detail: options.relation_fields_detail !== false,
need_multi_text: options.need_multi_text !== false,
need_user_detail: options.need_user_detail !== false,
need_sub_task_parent: options.need_sub_task_parent !== false,
};
const fetchPage = async (pageNum, pageSize) => {
var _a;
const body = {
page_num: pageNum,
page_size: pageSize,
expand: expand,
};
const response = await RequestUtils_1.default.request.call(this, {
method: 'POST',
url: `/open_api/${project_key}/view/${view_id}`,
body: body,
timeout: options.timeout,
});
return {
data: (response === null || response === void 0 ? void 0 : response.data) || [],
total: ((_a = response === null || response === void 0 ? void 0 : response.pagination) === null || _a === void 0 ? void 0 : _a.total) || 0,
};
};
if (returnAll) {
let allResults = [];
let pageNum = 1;
const pageSize = 50;
while (true) {
const { data, total } = await fetchPage(pageNum, pageSize);
allResults = allResults.concat(data);
if (allResults.length >= total || data.length === 0 || pageNum >= 1000) {
if (pageNum >= 1000) {
this.logger.warn('已达到最大分页数限制(1000页),停止获取');
}
break;
}
pageNum++;
}
return allResults;
}
else {
const pageSize = Math.min(limit, 50);
const { data } = await fetchPage(1, pageSize);
return data.slice(0, limit);
}
}
};
exports.default = ViewPanoramicOperate;
//# sourceMappingURL=ViewPanoramicOperate.js.map