mateclaw/mateclaw-ui/src/utils/wikiUpload.ts
RobinZhiBin 8a6dd1fa67
fix(wiki): stabilize concurrent raw-material uploads and PostgreSQL-compatible IDs
Give raw-material uploads a dedicated five-minute timeout and process file-picker and drag/drop uploads through a shared two-worker queue, so constrained uplinks no longer abort multipart requests at the global 30-second deadline.

Switch wiki processing jobs and page citations to application-assigned IDs: the PostgreSQL/Kingbase migrations define plain BIGINT primary keys without identity defaults, so database-generated keys fail on insert.
2026-07-15 09:51:20 +08:00

24 lines
700 B
TypeScript

export const WIKI_UPLOAD_TIMEOUT_MS = 5 * 60 * 1000
export const WIKI_UPLOAD_CONCURRENCY = 2
export async function processWithConcurrency<T>(
items: readonly T[],
worker: (item: T, index: number) => Promise<void>,
concurrency = WIKI_UPLOAD_CONCURRENCY,
): Promise<void> {
if (!Number.isInteger(concurrency) || concurrency < 1) {
throw new RangeError('concurrency must be a positive integer')
}
const iterator = items.entries()
async function runWorker() {
for (const [index, item] of iterator) {
await worker(item, index)
}
}
const workerCount = Math.min(concurrency, items.length)
await Promise.all(Array.from({ length: workerCount }, () => runWorker()))
}