UNPKG

n8n-nodes-feishu-lark

Version:

n8n custom nodes for n8n to interact with Feishu/Lark, including Lark Bot, Lark MCP, and Lark Trigger.

63 lines 2.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DataCache = void 0; class DataCache { constructor(params) { this.cache = new Map(); this.logger = params.logger; this.clearAtInterval(); } mergeData(params) { const { message_id, sum, seq, trace_id, data } = params; const cache = this.cache.get(message_id); if (!cache) { const buffer = new Array(sum).fill(undefined); buffer[seq] = data; this.cache.set(message_id, { buffer, trace_id, message_id, create_time: Date.now(), }); } else { cache.buffer[seq] = data; } const mergedCache = this.cache.get(message_id); if (mergedCache === null || mergedCache === void 0 ? void 0 : mergedCache.buffer.every((item) => !!item)) { const mergedBuffer = mergedCache.buffer.reduce((acc, cur) => { const combined = new Uint8Array(acc.byteLength + cur.byteLength); combined.set(acc, 0); combined.set(cur, acc.length); return combined; }, new Uint8Array([])); const string = new TextDecoder('utf-8').decode(mergedBuffer); const data = JSON.parse(string); this.deleteCache(message_id); return data; } return null; } deleteCache(message_id) { this.cache.delete(message_id); } clearAtInterval() { const clearIntervalMs = 10000; setInterval(() => { const now = Date.now(); this.cache.forEach((value, key) => { var _a; const { create_time, trace_id, message_id } = value; if (now - create_time > clearIntervalMs) { (_a = this.logger) === null || _a === void 0 ? void 0 : _a.debug(`${message_id} event data is deleted as expired, trace_id: ${trace_id}`); this.deleteCache(key); } }); }, clearIntervalMs); } clear() { this.cache.clear(); } } exports.DataCache = DataCache; //# sourceMappingURL=data-cache.js.map