@max1874/feishu 0.2.8 → 0.2.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/docx.ts +33 -9
package/package.json
CHANGED
package/src/docx.ts
CHANGED
|
@@ -157,16 +157,20 @@ function extractTableFromBlocks(blocks: any[]): { tables: TableData[]; otherBloc
|
|
|
157
157
|
return { tables, otherBlocks };
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
-
/** Clean blocks for insertion (remove read-only fields) */
|
|
160
|
+
/** Clean blocks for insertion (remove read-only fields and unsupported nested structures) */
|
|
161
161
|
function cleanBlocksForInsert(blocks: any[]): { cleaned: any[]; skipped: string[] } {
|
|
162
162
|
const skipped: string[] = [];
|
|
163
163
|
const cleaned = blocks.map((block) => {
|
|
164
|
-
|
|
164
|
+
const { children, parent_id, block_id, ...rest } = block;
|
|
165
|
+
|
|
166
|
+
// Remove children from non-table blocks (nested lists not supported in create API)
|
|
167
|
+
// Table children are handled separately via table.cells
|
|
165
168
|
if (block.block_type === TABLE_BLOCK_TYPE && block.table?.merge_info) {
|
|
166
169
|
const { merge_info, ...tableRest } = block.table;
|
|
167
|
-
return { ...
|
|
170
|
+
return { ...rest, table: tableRest };
|
|
168
171
|
}
|
|
169
|
-
|
|
172
|
+
|
|
173
|
+
return rest;
|
|
170
174
|
});
|
|
171
175
|
return { cleaned, skipped };
|
|
172
176
|
}
|
|
@@ -185,7 +189,7 @@ async function convertMarkdown(client: Lark.Client, markdown: string) {
|
|
|
185
189
|
};
|
|
186
190
|
}
|
|
187
191
|
|
|
188
|
-
/** Insert blocks as children of a parent block */
|
|
192
|
+
/** Insert blocks as children of a parent block (with batching for >50 blocks) */
|
|
189
193
|
async function insertBlocks(
|
|
190
194
|
client: Lark.Client,
|
|
191
195
|
docToken: string,
|
|
@@ -199,12 +203,32 @@ async function insertBlocks(
|
|
|
199
203
|
return { children: [], skipped };
|
|
200
204
|
}
|
|
201
205
|
|
|
202
|
-
|
|
206
|
+
// Feishu API limits to 50 blocks per request
|
|
207
|
+
const BATCH_SIZE = 50;
|
|
208
|
+
const allChildren: any[] = [];
|
|
209
|
+
|
|
210
|
+
// Get current children count to determine insert index
|
|
211
|
+
let insertIndex = 0;
|
|
212
|
+
const existing = await client.docx.documentBlockChildren.get({
|
|
203
213
|
path: { document_id: docToken, block_id: blockId },
|
|
204
|
-
data: { children: cleaned },
|
|
205
214
|
});
|
|
206
|
-
if (
|
|
207
|
-
|
|
215
|
+
if (existing.code === 0) {
|
|
216
|
+
insertIndex = existing.data?.items?.length ?? 0;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
for (let i = 0; i < cleaned.length; i += BATCH_SIZE) {
|
|
220
|
+
const batch = cleaned.slice(i, i + BATCH_SIZE);
|
|
221
|
+
const res = await client.docx.documentBlockChildren.create({
|
|
222
|
+
path: { document_id: docToken, block_id: blockId },
|
|
223
|
+
data: { children: batch, index: insertIndex },
|
|
224
|
+
});
|
|
225
|
+
if (res.code !== 0) throw new Error(res.msg);
|
|
226
|
+
const inserted = res.data?.children ?? [];
|
|
227
|
+
allChildren.push(...inserted);
|
|
228
|
+
insertIndex += inserted.length;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
return { children: allChildren, skipped };
|
|
208
232
|
}
|
|
209
233
|
|
|
210
234
|
/** Delete all child blocks from a parent */
|