refactor(compute): standardize compute mode detection for backend initialization

Update backend creation logic to consistently determine compute mode using
a local variable, ensuring correct handling when the mode is undefined. This
improves clarity and robustness in backend selection.
This commit is contained in:
Richard R 2026-05-20 16:39:25 -06:00
parent 29b7cfafb9
commit 91d9fe47a5

View file

@ -7,8 +7,11 @@ declare const __OPENREADER_COMPUTE_MODE__: 'local' | 'worker' | 'none';
let backendPromise: Promise<ComputeBackend> | null = null;
async function createBackend(): Promise<ComputeBackend> {
if (__OPENREADER_COMPUTE_MODE__ === 'worker') return new WorkerComputeBackend();
if (__OPENREADER_COMPUTE_MODE__ === 'local') {
const bundledMode =
typeof __OPENREADER_COMPUTE_MODE__ === 'undefined' ? 'none' : __OPENREADER_COMPUTE_MODE__;
if (bundledMode === 'worker') return new WorkerComputeBackend();
if (bundledMode === 'local') {
const { LocalComputeBackend } = await import('@/lib/server/compute/local');
return new LocalComputeBackend();
}