From 470207f98ed4da999fe9d7a7820c87c7337f6a8a Mon Sep 17 00:00:00 2001 From: Abe Jellinek <1770299+AbeJellinek@users.noreply.github.com> Date: Thu, 21 May 2026 17:04:00 -0400 Subject: [PATCH] Drop streaming SDT --- .../content/zotero/xpcom/pdfWorker/manager.js | 79 ------------------- chrome/content/zotero/xpcom/reader.js | 34 -------- 2 files changed, 113 deletions(-) diff --git a/chrome/content/zotero/xpcom/pdfWorker/manager.js b/chrome/content/zotero/xpcom/pdfWorker/manager.js index 7ee648e4c3..aebd2345c0 100644 --- a/chrome/content/zotero/xpcom/pdfWorker/manager.js +++ b/chrome/content/zotero/xpcom/pdfWorker/manager.js @@ -86,23 +86,6 @@ class PDFWorker { }); } - // Like _query, but onPartial fires for each isPartial message before the - // terminal response resolves the promise. Returns { promise, abort }. - _streamingQuery(action, data, transfer, onPartial) { - this._lastPromiseID++; - let id = this._lastPromiseID; - let promise = new Promise((resolve, reject) => { - this._waitingPromises[id] = { resolve, reject, onPartial }; - this._worker.postMessage({ id, action, data }, transfer); - }); - let abort = () => { - if (this._worker && this._waitingPromises[id]) { - this._worker.postMessage({ action: 'abort', id }); - } - }; - return { promise, abort }; - } - _init() { if (this._worker) return; this._worker = new Worker(WORKER_URL); @@ -114,17 +97,6 @@ class PDFWorker { Zotero.debug(`Received response from PDF worker for unknown request ${message.responseID}`); return; } - if (message.isPartial) { - if (promise.onPartial) { - try { - promise.onPartial(message.data); - } - catch (e) { - Zotero.logError(e); - } - } - return; - } delete this._waitingPromises[message.responseID]; let { resolve, reject } = promise; if ('error' in message) { @@ -749,57 +721,6 @@ class PDFWorker { return error; } - // Streaming variant of getStructuredData. onChunk receives partial chunks - // ({ kind: 'partial', pages, content, pageIndexOffset, contentIndexOffset, - // pageIndexRange, totalPageCount }) followed by a final chunk - // ({ kind: 'final', structure }). Returns { promise, abort }. - getStructuredDataStream(itemID, onChunk, options = {}) { - let abortFn = null; - let aborted = false; - let { password, batchSize, isPriority } = options; - let promise = this._enqueue(async () => { - if (aborted) { - let e = new Error('Aborted'); - e.name = 'AbortError'; - throw e; - } - let prep = await this._prepareStructuredDataRequest(itemID); - if (!prep) return; - let { attachment, contentType, buf, sourceHash } = prep; - Zotero.debug(`Streaming structured document text from item ${attachment.libraryKey}`); - let t = new Date(); - try { - let { promise: queryPromise, abort } = this._streamingQuery( - 'getStructuredDocumentTextJSON', - { - buf, - contentType, - password, - sourceHash, - streaming: true, - ...(batchSize ? { batchSize } : {}), - }, - [buf], - onChunk - ); - abortFn = abort; - if (aborted) abort(); - await queryPromise; - } - catch (e) { - throw this._wrapStructuredDataError(e); - } - Zotero.debug(`Streamed structured document text for item ${attachment.libraryKey} in ${new Date() - t} ms`); - }, isPriority); - return { - promise, - abort: () => { - aborted = true; - if (abortFn) abortFn(); - }, - }; - } - /** * Get data for recognizer-server * diff --git a/chrome/content/zotero/xpcom/reader.js b/chrome/content/zotero/xpcom/reader.js index 4770dfbec1..387c3d8358 100644 --- a/chrome/content/zotero/xpcom/reader.js +++ b/chrome/content/zotero/xpcom/reader.js @@ -644,40 +644,6 @@ class ReaderInstance { } }); }, - getSDTStream: (password, onChunk, onStart) => { - return new this._iframeWindow.Promise((resolve, reject) => { - let { promise, abort } = Zotero.PDFWorker.getStructuredDataStream( - this._item.id, - (chunk) => { - try { - onChunk(Cu.cloneInto(chunk, this._iframeWindow)); - } - catch (e) { - Zotero.logError(e); - } - }, - { - password, - isPriority: true, - } - ); - if (onStart) { - try { - onStart(Cu.exportFunction(() => abort(), this._iframeWindow)); - } - catch (e) { - Zotero.logError(e); - } - } - promise.then( - () => resolve(), - (e) => { - Zotero.logError(e); - reject(new this._iframeWindow.Error(e.message)); - } - ); - }); - }, }, this._iframeWindow, { cloneFunctions: true })); this._resolveInitPromise();