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
address review (codex): federate /data/image-refs board pins, not just /data/images (#1564)
[._.]/ Adam Eivyb3d2b08100b4
diff --git a/server/services/moodBoard/index.js b/server/services/moodBoard/index.jsindex e375a1bbae..263087476d 100644--- a/server/services/moodBoard/index.js+++ b/server/services/moodBoard/index.js@@ -29,7 +29,7 @@ export {mergeBoardsFromSync,pruneTombstonedBoards,} from './db.js';-export { imageUrlToImageFilename } from './logic.js';+export { imageUrlToAppAsset } from './logic.js';// Announce a newly-created board to the per-record peer-sync pipeline: emit the// 'updated' event so any existing subscription pushes it, AND auto-subscribediff --git a/server/services/moodBoard/logic.js b/server/services/moodBoard/logic.jsindex dcff3b54dc..bba22b8d16 100644--- a/server/services/moodBoard/logic.js+++ b/server/services/moodBoard/logic.js@@ -86,28 +86,50 @@ export function mergeBoardRecord(local, remoteRaw) {return { next, inserted: false, remoteWins, changed };}+// Served-asset dir prefix → peer-sync asset-manifest `kind`. A board item's+// `imageUrl` can point at any same-origin app-path image the media UI surfaces:+// gallery renders (`/data/images/`) AND character/canon reference sheets+// (`/data/image-refs/`) — synthetic sources like `canon-sheet:`/`noun:` aren't+// valid media-keys, so PinToMoodBoardMenu pins them as an `imageUrl` only (their+// `previewUrl` is the `/data/image-refs/...` served path). Both dirs are+// federated asset kinds (see directoryForAssetKind in peerSync.js), so both must+// be advertised in the manifest or the receiver stores a board item pointing at+// a missing local file. Mirrors the prefix vocabulary of directoryForAssetKind.+const APP_IMAGE_URL_PREFIXES = Object.freeze([+ ['/data/images/', 'image'],+ ['/data/image-refs/', 'image-ref'],+]);+/**- * Resolve a board item's app-path `imageUrl` to the bare gallery-image filename- * under `data/images/` so the peer-sync asset pipeline can hash + transfer it.- * Mirrors `startingImageFilename` in creativeDirector/projectsLogic.js: returns- * null for an empty/non-string value, an external URL (`http(s)://…`, `data:`,- * `blob:`), or any non-images absolute path — the receiver resolves those- * itself. A media-key reference (`image:<ref>`) is handled separately by the- * manifest builder (it carries the bare ref directly); this covers only the- * `imageUrl` pointer.+ * Resolve a board item's app-path `imageUrl` to `{ kind, filename }` so the+ * peer-sync asset pipeline can hash + transfer the bytes via the right dir.+ * Returns null for an empty/non-string value, an external URL (`http(s)://…`,+ * `data:`, `blob:`), or any absolute path outside the served-asset dirs above —+ * the receiver resolves those itself. A bare/relative ref (no leading `/`) is+ * treated as a gallery image filename (legacy shape). A media-key reference+ * (`image:<ref>`) is handled separately by the manifest builder (it carries the+ * bare ref directly); this covers only the `imageUrl` pointer.*/-export function imageUrlToImageFilename(imageUrl) {+export function imageUrlToAppAsset(imageUrl) {if (!isStr(imageUrl)) return null;const url = imageUrl.trim();if (!url) return null;if (/^(https?:|data:|blob:)/i.test(url)) return null;- 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- name = name.split(/[?#]/)[0];- const base = name.split('/').pop();- return base || 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 (url.startsWith(prefix)) {+ const filename = baseOf(url.slice(prefix.length));+ return filename ? { kind, filename } : null;+ }+ }+ return null; // some other absolute path → not a served gallery asset}// Apply a PATCH to board-level fields (name/description). Absent keys preservediff --git a/server/services/moodBoard/logic.test.js b/server/services/moodBoard/logic.test.jsindex f55dac06fc..859339caaf 100644--- a/server/services/moodBoard/logic.test.js+++ b/server/services/moodBoard/logic.test.js@@ -14,7 +14,7 @@ import {removeItem,sanitizeBoardForSync,mergeBoardRecord,- imageUrlToImageFilename,+ imageUrlToAppAsset,MAX_ITEMS_PER_BOARD,} from './logic.js';@@ -195,17 +195,24 @@ describe('mergeBoardRecord (LWW)', () => {});});-describe('imageUrlToImageFilename', () => {- it('strips the app-path prefix to a bare gallery filename', () => {- expect(imageUrlToImageFilename('/data/images/foo.png')).toBe('foo.png');- expect(imageUrlToImageFilename('/data/images/sub/foo.png?v=2')).toBe('foo.png');- });- it('returns null for external / non-images / empty values', () => {- expect(imageUrlToImageFilename('https://x/y.png')).toBeNull();- expect(imageUrlToImageFilename('data:image/png;base64,AAA')).toBeNull();- expect(imageUrlToImageFilename('/data/videos/clip.mp4')).toBeNull();- expect(imageUrlToImageFilename('')).toBeNull();- expect(imageUrlToImageFilename(null)).toBeNull();+describe('imageUrlToAppAsset', () => {+ it('resolves a gallery image path to { kind: image, filename }', () => {+ expect(imageUrlToAppAsset('/data/images/foo.png')).toEqual({ kind: 'image', filename: 'foo.png' });+ expect(imageUrlToAppAsset('/data/images/sub/foo.png?v=2')).toEqual({ kind: 'image', filename: 'foo.png' });+ });+ it('resolves an image-ref path (canon-sheet / noun pins) to { kind: image-ref, filename }', () => {+ expect(imageUrlToAppAsset('/data/image-refs/canon-abc.png')).toEqual({ kind: 'image-ref', filename: 'canon-abc.png' });+ });+ it('treats a bare/relative ref as a gallery image (legacy shape)', () => {+ expect(imageUrlToAppAsset('foo.png')).toEqual({ kind: 'image', filename: 'foo.png' });+ });+ it('returns null for external / other-absolute / empty values', () => {+ expect(imageUrlToAppAsset('https://x/y.png')).toBeNull();+ expect(imageUrlToAppAsset('data:image/png;base64,AAA')).toBeNull();+ expect(imageUrlToAppAsset('/data/videos/clip.mp4')).toBeNull(); // video bytes ride a media-key, not an imageUrl+ expect(imageUrlToAppAsset('/etc/passwd')).toBeNull();+ expect(imageUrlToAppAsset('')).toBeNull();+ expect(imageUrlToAppAsset(null)).toBeNull();});});diff --git a/server/services/sharing/peerSync.js b/server/services/sharing/peerSync.jsindex e23a6309f7..f5618d5d70 100644--- a/server/services/sharing/peerSync.js+++ b/server/services/sharing/peerSync.js@@ -107,7 +107,7 @@ import {getBoard,listBoards,mergeBoardsFromSync,- imageUrlToImageFilename,+ imageUrlToAppAsset,} from '../moodBoard/index.js';import { parseKey } from '../../lib/mediaItemKey.js';import {@@ -1661,15 +1661,17 @@ async function buildProjectAssetManifest(project) {/*** Hash the local image bytes a mood board's items reference so the receiver can- * pull them from `/data/images/` (or `/data/videos/`). An image item points at+ * pull them from `/data/{images,image-refs,videos}/`. An image item points at* local bytes two ways: a media-key (`image:<ref>` / `video:<ref>`) into the- * gallery, or an app-path `imageUrl` (`/data/images/...`). External URLs- * (http(s)/data/blob) resolve on the receiver itself → skipped. Mirrors- * `buildAssetManifestForCollection`: path-traversal-guarded, missing-local-file- * skipped silently (including a null-hash entry would make every receiver- * re-request bytes the sender can't fulfill), dedup-by-`<kind>:<filename>` so a- * media-key and imageUrl pointing at the same file ship once. Text items carry- * no bytes.+ * gallery, or an app-path `imageUrl` — a gallery render (`/data/images/...`) OR a+ * character/canon reference sheet (`/data/image-refs/...`, the form+ * PinToMoodBoardMenu pins synthetic `canon-sheet:`/`noun:` sources under).+ * External URLs (http(s)/data/blob) resolve on the receiver itself → skipped.+ * Mirrors `buildAssetManifestForCollection`: path-traversal-guarded,+ * missing-local-file skipped silently (including a null-hash entry would make+ * every receiver re-request bytes the sender can't fulfill),+ * dedup-by-`<kind>:<filename>` so a media-key and imageUrl pointing at the same+ * file ship once. Text items carry no bytes.*/async function buildBoardAssetManifest(board) {const dedup = new Map();@@ -1688,9 +1690,16 @@ async function buildBoardAssetManifest(board) {}}if (typeof it.imageUrl === 'string') {- const filename = imageUrlToImageFilename(it.imageUrl);- const safeName = filename ? sanitizeAssetFilename(filename) : null;- if (safeName) pending.push(hashImageForManifest(safeName));+ const asset = imageUrlToAppAsset(it.imageUrl);+ const safeName = asset ? sanitizeAssetFilename(asset.filename) : null;+ if (safeName) {+ // `image-ref` bytes stream-hash from PATHS.imageRefs (same kind/dir the+ // universe-canon manifest uses); gallery `image` bytes go through the+ // sidecar-aware hashImageForManifest.+ pending.push(asset.kind === 'image-ref'+ ? hashSimpleAsset(safeName, 'image-ref', PATHS.imageRefs)+ : hashImageForManifest(safeName));+ }}for (const entry of await Promise.all(pending)) {if (entry) dedup.set(`${entry.kind}:${entry.filename}`, entry);