From 1c7bdf302eab712db777857881d23d732b2a0547 Mon Sep 17 00:00:00 2001 From: Florian Kinder Date: Tue, 3 Feb 2026 22:07:33 +0100 Subject: [PATCH] fix: download button not working in streaming mode The download button threw "ReferenceError: fileName is not defined" when using streaming mode because processOpStreaming didn't set the global fileName variable. Additionally, the filename stored in the database includes ".json" extension, but the /file/:name endpoint adds ".json.gz", causing double extension lookups. Now strips ".json" when setting fileName in both streaming and legacy modes. --- static/scripts/ocap.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/static/scripts/ocap.js b/static/scripts/ocap.js index e333a28b..a4a233fa 100644 --- a/static/scripts/ocap.js +++ b/static/scripts/ocap.js @@ -1038,7 +1038,7 @@ async function loadOperation(op) { // Get schema version from operation or default to 1 const schemaVersion = op.schemaVersion || 1; console.log(`Loading operation ${op.id} using streaming mode (${op.storageFormat}, schema v${schemaVersion})`); - return processOpStreaming(op.id, op.storageFormat, schemaVersion); + return processOpStreaming(op.id, op.storageFormat, schemaVersion, op.filename); } // Fall back to legacy JSON loading console.log(`Loading operation using legacy JSON mode`); @@ -1075,7 +1075,8 @@ async function loadOperationByFilename(filename) { function processOp (filepath, opRecord) { console.log("Processing operation: (" + filepath + ")..."); const time = new Date(); - fileName = filepath.substr(5, filepath.length); + // Strip "data/" prefix and .json extension since /file/:name endpoint adds .json.gz + fileName = filepath.substr(5, filepath.length).replace(/\.json$/, ''); let data; return fetch(filepath) @@ -1772,10 +1773,14 @@ async function getOperationFormat(operationId) { * @param {number} schemaVersion - Schema version (default: 1) * @returns {Promise} */ -async function processOpStreaming(operationId, format = 'protobuf', schemaVersion = 1) { +async function processOpStreaming(operationId, format = 'protobuf', schemaVersion = 1, operationFilename = null) { console.log(`Processing operation (streaming mode): ${operationId} (format: ${format}, schema: v${schemaVersion})`); const time = new Date(); + // Set global fileName for download functionality + // Strip .json extension since /file/:name endpoint adds .json.gz + fileName = (operationFilename || operationId).replace(/\.json$/, ''); + // Get versioned loader from registry const loader = LoaderRegistry.getLoader(schemaVersion);