mirror of
https://github.com/zotero/zotero.git
synced 2026-10-05 02:43:38 +00:00
Drop streaming SDT
This commit is contained in:
parent
216554d62b
commit
470207f98e
2 changed files with 0 additions and 113 deletions
|
|
@ -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
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue