@max1874/feishu 0.2.5 → 0.2.7
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 +23 -6
package/package.json
CHANGED
package/src/docx.ts
CHANGED
|
@@ -172,6 +172,9 @@ async function convertMarkdown(client: Lark.Client, markdown: string) {
|
|
|
172
172
|
}
|
|
173
173
|
|
|
174
174
|
/** Insert blocks as children of a parent block */
|
|
175
|
+
// Batch size for inserting blocks (API may have limits)
|
|
176
|
+
const INSERT_BATCH_SIZE = 50;
|
|
177
|
+
|
|
175
178
|
async function insertBlocks(
|
|
176
179
|
client: Lark.Client,
|
|
177
180
|
docToken: string,
|
|
@@ -185,12 +188,26 @@ async function insertBlocks(
|
|
|
185
188
|
return { children: [], skipped };
|
|
186
189
|
}
|
|
187
190
|
|
|
188
|
-
const
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
191
|
+
const allChildren: any[] = [];
|
|
192
|
+
|
|
193
|
+
// Insert in batches to avoid API limits
|
|
194
|
+
for (let i = 0; i < cleaned.length; i += INSERT_BATCH_SIZE) {
|
|
195
|
+
const batch = cleaned.slice(i, i + INSERT_BATCH_SIZE);
|
|
196
|
+
try {
|
|
197
|
+
const res = await client.docx.documentBlockChildren.create({
|
|
198
|
+
path: { document_id: docToken, block_id: blockId },
|
|
199
|
+
data: { children: batch },
|
|
200
|
+
});
|
|
201
|
+
if (res.code !== 0) throw new Error(res.msg);
|
|
202
|
+
allChildren.push(...(res.data?.children ?? []));
|
|
203
|
+
} catch (err) {
|
|
204
|
+
const blockTypes = batch.map((b) => BLOCK_TYPE_NAMES[b.block_type] || `type_${b.block_type}`);
|
|
205
|
+
const errMsg = err instanceof Error ? err.message : String(err);
|
|
206
|
+
throw new Error(`insertBlocks failed at batch ${Math.floor(i / INSERT_BATCH_SIZE) + 1}: ${errMsg}. Batch types: [${blockTypes.join(", ")}]. Batch size: ${batch.length}`);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return { children: allChildren, skipped };
|
|
194
211
|
}
|
|
195
212
|
|
|
196
213
|
/** Delete all child blocks from a parent */
|