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
fix: reuse shared media-key validator + reject invalid item PATCH (#911)
Adam Eivy5ba2bd913b93
diff --git a/server/lib/moodBoardValidation.js b/server/lib/moodBoardValidation.jsindex 7e6c1aa47b..e71959fb84 100644--- a/server/lib/moodBoardValidation.js+++ b/server/lib/moodBoardValidation.js@@ -1,4 +1,5 @@import { z } from 'zod';+import { isValidKey } from './mediaItemKey.js';// =============================================================================// MOOD BOARD SCHEMAS (issue #911)@@ -9,13 +10,11 @@ import { z } from 'zod';export const MOOD_BOARD_ITEM_TYPES = Object.freeze(['image', 'text']);-// A media-key references an indexed asset as `<kind>:<ref>` (see mediaItemKey.js)-// — e.g. `image:my-render.png` or `video:job-123`. Kept permissive (the index is-// the source of truth); just bound the length and require the `<kind>:<ref>` shape.-const mediaKeySchema = z.string().trim().min(3).max(512).regex(- /^[a-z]+:.+$/,- 'mediaKey must be in `<kind>:<ref>` form',-);+// A media-key references an indexed asset as `<kind>:<ref>` (e.g.+// `image:my-render.png`, `video:job-123`). Reuse the shared key validator from+// mediaItemKey.js (the same vocabulary mediaCollections / mediaAnnotations use)+// so a board can't pin a key the rest of PortOS would reject.+const mediaKeySchema = z.string().trim().refine(isValidKey, 'mediaKey must be a valid `<kind>:<ref>` media key');// External/pinned image URL. http(s) or a same-origin app path (e.g. a served// `/data/images/...` URL). Bounded; the UI renders it in an <img>, so no exoticdiff --git a/server/services/moodBoard/logic.js b/server/services/moodBoard/logic.jsindex 9dc76447f1..06c5ce1324 100644--- a/server/services/moodBoard/logic.js+++ b/server/services/moodBoard/logic.js@@ -99,6 +99,16 @@ export function updateItem(board, itemId, patch) {for (const key of editableKeys) {if (patch[key] !== undefined) updated[key] = patch[key];}+ // Reject a patch that would strip the item's required content (the schema+ // permits nulls so a partial edit can clear one of two image sources, but the+ // MERGED result must stay valid): an image keeps at least one of+ // mediaKey/imageUrl; a text item keeps non-empty text.+ if (updated.type === 'image' && !updated.mediaKey && !updated.imageUrl) {+ throw new ServerError('An image item must keep a mediaKey or imageUrl', { status: 400, code: 'INVALID_ITEM' });+ }+ if (updated.type === 'text' && (typeof updated.text !== 'string' || !updated.text.trim())) {+ throw new ServerError('A text item must keep non-empty text', { status: 400, code: 'INVALID_ITEM' });+ }const nextItems = [...items];nextItems[idx] = updated;const next = { ...board, items: nextItems, updatedAt: nowIso() };diff --git a/server/services/moodBoard/logic.test.js b/server/services/moodBoard/logic.test.jsindex 42c98407dd..1c3da91487 100644--- a/server/services/moodBoard/logic.test.js+++ b/server/services/moodBoard/logic.test.js@@ -103,6 +103,14 @@ describe('updateItem', () => {expect(item.text).toBeNull();expect(item.caption).toBe('ok');});+ it('rejects clearing an image item’s only source', () => {+ const { board } = addItem(buildBoardRecord({ name: 'A' }, { id: 'mb-3', now: 't0' }), { type: 'image', imageUrl: 'https://x/y.png' });+ const imgId = board.items[0].id;+ expect(() => updateItem(board, imgId, { imageUrl: null })).toThrow(/mediaKey or imageUrl/i);+ });+ it('rejects blanking a text item', () => {+ expect(() => updateItem(withItem, itemId, { text: ' ' })).toThrow(/non-empty text/i);+ });});describe('removeItem', () => {