mirror of
https://github.com/open-webui/open-webui.git
synced 2026-06-13 19:20:05 +00:00
fix: polyfill readable stream async iteration for Safari PDF extraction (#25473)
This commit is contained in:
@@ -1764,7 +1764,42 @@ export const parseJsonValue = (value: string): any => {
|
||||
return value;
|
||||
};
|
||||
|
||||
type ReadableStreamWithAsyncIterator<T> = ReadableStream<T> & {
|
||||
[Symbol.asyncIterator]?: () => AsyncIterableIterator<T>;
|
||||
};
|
||||
|
||||
function ensureReadableStreamAsyncIterator() {
|
||||
if (typeof ReadableStream === 'undefined') {
|
||||
return;
|
||||
}
|
||||
|
||||
const prototype = ReadableStream.prototype as ReadableStreamWithAsyncIterator<unknown>;
|
||||
if (prototype[Symbol.asyncIterator]) {
|
||||
return;
|
||||
}
|
||||
|
||||
Object.defineProperty(prototype, Symbol.asyncIterator, {
|
||||
value: async function* (this: ReadableStream<unknown>) {
|
||||
const reader = this.getReader();
|
||||
try {
|
||||
while (true) {
|
||||
const { done, value } = await reader.read();
|
||||
if (done) {
|
||||
return;
|
||||
}
|
||||
yield value;
|
||||
}
|
||||
} finally {
|
||||
reader.releaseLock();
|
||||
}
|
||||
},
|
||||
configurable: true,
|
||||
writable: true
|
||||
});
|
||||
}
|
||||
|
||||
async function ensurePDFjsLoaded() {
|
||||
ensureReadableStreamAsyncIterator();
|
||||
if (!window.pdfjsLib) {
|
||||
const pdfjs = await import('pdfjs-dist');
|
||||
pdfjs.GlobalWorkerOptions.workerSrc = pdfWorkerUrl;
|
||||
|
||||
Reference in New Issue
Block a user