From 4af91235e1f9fc8c3c39a250d6fe355f377cac75 Mon Sep 17 00:00:00 2001 From: MayaTheShy Date: Sat, 21 Mar 2026 18:21:23 -0400 Subject: [PATCH] Refactor furnace input, fuel, and output handling: stringify on save and parse on load --- web/server/db.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/web/server/db.js b/web/server/db.js index 826f0d3..e707977 100644 --- a/web/server/db.js +++ b/web/server/db.js @@ -158,9 +158,9 @@ const saveFurnacesBatch = db.transaction((furnaces, now) => { name, type: f.type || 'minecraft:furnace', active: f.active ? 1 : 0, - input: f.input || null, - fuel: f.fuel || null, - output: f.output || null, + input: f.input ? JSON.stringify(f.input) : null, + fuel: f.fuel ? JSON.stringify(f.fuel) : null, + output: f.output ? JSON.stringify(f.output) : null, updatedAt: now, }); } @@ -260,12 +260,16 @@ export function loadFurnaces() { const rows = getAllFurnaces.all(); const result = {}; for (const row of rows) { + let input = null, fuel = null, output = null; + try { input = row.input ? JSON.parse(row.input) : null; } catch { input = row.input; } + try { fuel = row.fuel ? JSON.parse(row.fuel) : null; } catch { fuel = row.fuel; } + try { output = row.output ? JSON.parse(row.output) : null; } catch { output = row.output; } result[row.name] = { active: !!row.active, type: row.type, - input: row.input, - fuel: row.fuel, - output: row.output, + input, + fuel, + output, }; } return result; @@ -362,9 +366,9 @@ const _saveFullStateTransaction = db.transaction((state, now) => { name, type: f.type || 'minecraft:furnace', active: f.active ? 1 : 0, - input: f.input || null, - fuel: f.fuel || null, - output: f.output || null, + input: f.input ? JSON.stringify(f.input) : null, + fuel: f.fuel ? JSON.stringify(f.fuel) : null, + output: f.output ? JSON.stringify(f.output) : null, updatedAt: now, }); }