@luka-cat-mimi/n8n-nodes-feishu-project
Version:
飞书项目 N8N 集成插件,支持附件管理等功能
92 lines • 3.53 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 sharedOptions_1 = require("../../../help/utils/sharedOptions");
const description_1 = require("../../../help/description");
const ViewWorkItemListOperate = {
name: '获取视图下工作项列表',
value: 'view:work_item_list',
order: 20,
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',
},
sharedOptions_1.timeoutOnlyOptions,
],
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 fetchPage = async (pageNum, pageSize) => {
var _a;
const response = await RequestUtils_1.default.request.call(this, {
method: 'GET',
url: `/open_api/${project_key}/fix_view/${view_id}?page_num=${pageNum}&page_size=${pageSize}`,
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 = ViewWorkItemListOperate;
//# sourceMappingURL=ViewWorkItemListOperate.js.map