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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
refactor([issue-1642]): build moodBoard imageUrlToAppAsset on the shared image resolver
[._.]/ Adam Eivy6cb5139eac65
diff --git a/server/lib/README.md b/server/lib/README.mdindex dd631e1a3c..a4987f2e47 100644--- a/server/lib/README.md+++ b/server/lib/README.md@@ -111,7 +111,7 @@ The barrel `server/lib/index.js` is a machine-checkable enumeration of every pub| `fileWriteQueue.js` | Single-tail promise chain for serializing writes to a file. || `imageClean.js` | `cleanImageBuffer` (sharp-based denoise + C2PA strip) + `autoCleanGeneratedImage` (in-place clean for post-generation hook). HTTP route in `routes/imageClean.js` wraps `cleanImageBuffer`. || `imageWatermark.js` | `removeCornerWatermark` (erases the visible Gemini/Nano-Banana bottom-right ✦ via dependency-free harmonic/Laplace inpaint) + pure helpers `resolveWatermarkRegion` / `inpaintRegion`. Distinct from SynthID regen — this targets the *visible* corner logo. |-| `localImageFilename.js` | `localImageFilename(urlOrPath)` resolves a stored image reference to the bare gallery-image filename under `data/images/` (or null for empty/external-URL/non-image-path) — the unit the peer-sync asset pipeline hashes + transfers. Single source of truth for the authors/artists/albums/Creative-Director filename resolvers (`headshotImageFilename`/`portraitImageFilename`/`coverImageFilename`/`startingImageFilename` are thin wrappers). |+| `localImageFilename.js` | `localImageFilename(urlOrPath)` resolves a stored image reference to the bare gallery-image filename under `data/images/` (or null for empty/external-URL/non-image-path) — the unit the peer-sync asset pipeline hashes + transfers. Single source of truth for the authors/artists/albums/Creative-Director filename resolvers (`headshotImageFilename`/`portraitImageFilename`/`coverImageFilename`/`startingImageFilename` are thin wrappers). Also exports `assetBasename(pathOrName)`, the shared strip-querystring→basename primitive (reused by moodBoard's `imageUrlToAppAsset`). || `multipart.js` | Streaming multipart/form-data parser. || `safetensors.js` | `readSafetensorsHeader(path)` reads only the JSON header of a `.safetensors` file (never the tensor payload). `detectFlux2VariantFromHeader(header)` / `detectFlux2Variant(path)` classify a LoRA as FLUX.2 Klein `'4b'` (hidden dim 3072) vs `'9b'` (4096) by transformer-block tensor shapes, so the LoRA picker can hide off-variant weights that would silently fail to load. || `pdfImageEmbed.js` | PDF image embed helpers for comic / volume PDFs. |diff --git a/server/lib/localImageFilename.js b/server/lib/localImageFilename.jsindex 9cb02baaf6..c9851b5c3e 100644--- a/server/lib/localImageFilename.js+++ b/server/lib/localImageFilename.js@@ -20,6 +20,23 @@const isStr = (v) => typeof v === 'string';+/**+ * Strip any querystring/hash a stored reference might carry, then reduce it to+ * the basename — the bare unit the peer-sync asset pipeline hashes + transfers.+ * This is the "what's the filename" primitive shared by every app-asset+ * resolver: `localImageFilename` below (gallery `/data/images/`) and+ * `imageUrlToAppAsset` in `moodBoard/logic.js` (which also resolves+ * `/data/image-refs/`), so the basename logic lives in exactly one place.+ *+ * @param {unknown} pathOrName - a path segment or bare filename (no mount prefix)+ * @returns {string|null} the basename, or null when it collapses to empty+ */+export function assetBasename(pathOrName) {+ if (!isStr(pathOrName)) return null;+ const base = pathOrName.split(/[?#]/)[0].split('/').pop();+ return base || null;+}+/*** Resolve a stored image URL/path to the bare gallery-image filename under* `data/images/`, or null when there's nothing local to ship.@@ -34,12 +51,8 @@ export function localImageFilename(urlOrPath) {if (/^(https?:|data:|blob:)/i.test(url)) return null;// Only gallery images sync as assets. Accept the canonical mount path or a// bare filename; reject any other absolute path (videos, image-refs, etc.).- let name = url;const imagesPrefix = '/data/images/';- if (url.startsWith(imagesPrefix)) name = url.slice(imagesPrefix.length);- else if (url.startsWith('/')) return null; // some other absolute path → not a gallery image- // Strip any querystring/hash a stored URL might carry, then take the basename.- name = name.split(/[?#]/)[0];- const base = name.split('/').pop();- return base || null;+ if (url.startsWith(imagesPrefix)) return assetBasename(url.slice(imagesPrefix.length));+ if (url.startsWith('/')) return null; // some other absolute path → not a gallery image+ return assetBasename(url);}diff --git a/server/lib/localImageFilename.test.js b/server/lib/localImageFilename.test.jsindex 30ee8330a3..2c81e54d47 100644--- a/server/lib/localImageFilename.test.js+++ b/server/lib/localImageFilename.test.js@@ -1,5 +1,5 @@import { describe, it, expect } from 'vitest';-import { localImageFilename } from './localImageFilename.js';+import { localImageFilename, assetBasename } from './localImageFilename.js';describe('localImageFilename', () => {it('returns null for non-string / empty input', () => {@@ -47,3 +47,29 @@ describe('localImageFilename', () => {expect(localImageFilename('/data/images/')).toBe(null);});});++describe('assetBasename', () => {+ it('returns null for non-string input', () => {+ expect(assetBasename(undefined)).toBe(null);+ expect(assetBasename(null)).toBe(null);+ expect(assetBasename(42)).toBe(null);+ });++ it('takes the basename of a path segment', () => {+ expect(assetBasename('photo.png')).toBe('photo.png');+ expect(assetBasename('nested/photo.png')).toBe('photo.png');+ expect(assetBasename('a/b/c/photo.png')).toBe('photo.png');+ });++ it('strips querystring / hash before taking the basename', () => {+ expect(assetBasename('photo.png?v=2')).toBe('photo.png');+ expect(assetBasename('photo.png#frag')).toBe('photo.png');+ expect(assetBasename('nested/photo.png?a=1#b')).toBe('photo.png');+ });++ it('returns null when the basename collapses to empty', () => {+ expect(assetBasename('')).toBe(null);+ expect(assetBasename('nested/')).toBe(null);+ expect(assetBasename('?v=2')).toBe(null);+ });+});diff --git a/server/services/moodBoard/logic.js b/server/services/moodBoard/logic.jsindex bba22b8d16..efaf1315f1 100644--- a/server/services/moodBoard/logic.js+++ b/server/services/moodBoard/logic.js@@ -15,6 +15,7 @@ import { randomUUID } from 'crypto';import { ServerError } from '../../lib/errorHandler.js';import { compareNewerWins } from '../../lib/lwwTimestamp.js';import { sanitizeSoftDeleteFields } from '../../lib/syncWire.js';+import { localImageFilename, assetBasename } from '../../lib/localImageFilename.js';const isStr = (v) => typeof v === 'string';@@ -111,21 +112,21 @@ const APP_IMAGE_URL_PREFIXES = Object.freeze([* bare ref directly); this covers only the `imageUrl` pointer.*/export function imageUrlToAppAsset(imageUrl) {+ // Gallery images (the `/data/images/` mount or a bare/relative legacy ref) and+ // every rejection — empty/non-string, external URL (`http(s)://…`/`data:`/+ // `blob:`), and any other absolute path — are exactly the shared resolver's+ // contract, so delegate to it instead of re-deriving them here.+ const galleryFilename = localImageFilename(imageUrl);+ if (galleryFilename) return { kind: 'image', filename: galleryFilename };+ // localImageFilename returned null: external/empty (nothing to ship) or a+ // non-gallery absolute path. The only served-asset dir it doesn't cover is+ // image-refs — resolve that here, sharing the basename primitive.if (!isStr(imageUrl)) return null;const url = imageUrl.trim();- if (!url) return null;- if (/^(https?:|data:|blob:)/i.test(url)) return null;- const baseOf = (s) => {- const cut = s.split(/[?#]/)[0].split('/').pop();- return cut || null;- };- if (!url.startsWith('/')) {- const filename = baseOf(url); // bare/relative → gallery image (legacy shape)- return filename ? { kind: 'image', filename } : null;- }for (const [prefix, kind] of APP_IMAGE_URL_PREFIXES) {+ if (kind === 'image') continue; // gallery is handled by localImageFilename aboveif (url.startsWith(prefix)) {- const filename = baseOf(url.slice(prefix.length));+ const filename = assetBasename(url.slice(prefix.length));return filename ? { kind, filename } : null;}}