Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: drop stale flattened PNG when re-saving vectors-only sketch (#2036)

Adam Eivy0bfd67297d38
diff --git a/server/services/mediaSketches.js b/server/services/mediaSketches.js
index 67ecc536a9..7a3abce419 100644
--- a/server/services/mediaSketches.js
+++ b/server/services/mediaSketches.js
@@ -128,6 +128,10 @@ export async function saveSketch(key, input) {
const hasPng = !!clean.png;
if (hasPng) await atomicWrite(pngPathFor(key), clean.png);
+ // A re-save that carries only vectors (no PNG) must drop any prior flattened
+ // export, otherwise `hasPng:false` in the JSON disagrees with a stale
+ // `<id>.png` that getSketchPng() would keep streaming.
+ else await unlink(pngPathFor(key)).catch(() => {});
const record = {
key,
width: clean.width,
diff --git a/server/services/mediaSketches.test.js b/server/services/mediaSketches.test.js
index df8254e347..390f182a5c 100644
--- a/server/services/mediaSketches.test.js
+++ b/server/services/mediaSketches.test.js
@@ -52,6 +52,16 @@ describe('mediaSketches service', () => {
expect(png.toString()).toBe('fake-png-bytes');
});
+ it('re-saving with strokes but no PNG drops the stale flattened export', async () => {
+ await svc.saveSketch(KEY, { width: 10, height: 10, strokes: sampleStrokes, png: PNG_DATA_URL });
+ expect(await svc.getSketchPng(KEY)).not.toBeNull();
+ // Second save carries vectors only — the old PNG must be removed so hasPng
+ // (false) agrees with what /png serves.
+ const resaved = await svc.saveSketch(KEY, { width: 10, height: 10, strokes: sampleStrokes });
+ expect(resaved.hasPng).toBe(false);
+ expect(await svc.getSketchPng(KEY)).toBeNull();
+ });
+
it('saveSketch with empty strokes removes the sidecar', async () => {
await svc.saveSketch(KEY, { width: 10, height: 10, strokes: sampleStrokes, png: PNG_DATA_URL });
expect(await svc.getSketch(KEY)).not.toBeNull();