The OSINT investigator's workbench. One case, one folder, every tool. Local-first: your media and your investigations never leave your machine.
JavaScript
Keep a Geo Report when a second proof arrives
OsintMeThat6c61a5e8e270
diff --git a/frontend/src/lib/post.js b/frontend/src/lib/post.jsindex ab9aa86..bc2df83 100644--- a/frontend/src/lib/post.js+++ b/frontend/src/lib/post.js@@ -158,7 +158,7 @@ export function postReportMarkdown({entityReference(proofEntity),'','::: center',- `${mediaReference(proofEntity)}{width=100% align=center}`,+ `${mediaReference(proofEntity)}{width=70% align=center}`,':::',].join('\n'));} else if (cleanAttachments[0]?.startsWith('proofs/')) {diff --git a/frontend/src/lib/post.test.js b/frontend/src/lib/post.test.jsindex ac57d09..d321efb 100644--- a/frontend/src/lib/post.test.js+++ b/frontend/src/lib/post.test.js@@ -405,7 +405,7 @@ describe('postReportMarkdown', () => {expect(report).toContain('## Assessment\n\nMatch against reference imagery.');expect(report).not.toContain('## Prepared thread');expect(report).toContain('[[entity:e_proof|Rooftop proof]]');- expect(report).toContain('[[media:e_proof|Rooftop proof]]{width=100% align=center}');+ expect(report).toContain('[[media:e_proof|Rooftop proof]]{width=70% align=center}');expect(report).toContain('[[entity:e_frame|Frame]]');expect(report).toContain('[[media:e_frame|Frame]]{width=100% align=center}');expect(report).not.toContain('- proofs/match.png');diff --git a/frontend/src/tools/PostComposer.svelte b/frontend/src/tools/PostComposer.svelteindex 82ce4c2..3587db9 100644--- a/frontend/src/tools/PostComposer.svelte+++ b/frontend/src/tools/PostComposer.svelte@@ -8,6 +8,7 @@import { deletedToast, RESTORABLE } from '../lib/trash.js';import { proofCoordsText, proofSource } from '../lib/composer.js';import { isDefaultName, nextName, savedSlugs, savedTitles, savedTitle, slugify } from '../lib/naming.js';+ import { filingName, planProofHandoff } from './post/handoff.js';import {buildTweet1 as buildTweet1Lines, DEFAULT_TWEET_BODY,extraPostTweetText, groupPostMedia, MAX_POST_MEDIA, mediaTweetText,@@ -170,6 +171,48 @@const p = uiState.postProof;if (!p) return;uiState.postProof = null;+ adoptProof(p);+ });++ /**+ * A proof arriving from the Proof Composer opens its own thread. The one on+ * screen is filed under its own name first and then makes way, so sending a+ * second proof over does not write over the post the first one produced.+ * Re-sending the proof this thread already carries stays in place instead —+ * that is the same piece of work, edited.+ */+ async function adoptProof(p) {+ const plan = planProofHandoff({ incomingPng: p.png, currentPng: proofPng, hasContent });+ if (plan === 'file-then-apply') {+ if (!(await fileCurrentDraft())) return;+ resetDraft();+ }+ applyProof(p);+ }++ /** Save what the composer holds under its own name, before something else+ * takes its place. Answers whether the thread is safely on disk. */+ async function fileCurrentDraft() {+ if (!caseState.current) return true;+ const title = postName.trim();+ if (!title) return true;+ postName = filingName({+ title,+ bound: !!draftName,+ takenSlugs: savedSlugs(draftEntities, 'draft'),+ slug: slugify(title, 'draft'),+ fresh: freshPostName(),+ });+ const saved = await performDraftSave(`Post saved: ${postName.trim()}`);+ if (!saved) return false;+ // The name for the next thread has to count past the one just written,+ // which the case-wide list does not know about yet.+ draftEntities = await fetchAllEntities(caseState.current.id, { types: ['post'] })+ .catch(() => draftEntities);+ return true;+ }++ function applyProof(p) {description = isDefaultName(p.title, 'proof') ? '' : (p.title ?? '');const proofSourceUrl = p.source ?? p.sources?.[0] ?? '';source = proofSourceUrl;@@ -180,7 +223,7 @@?? (p.coords ? `${p.coords.lat.toFixed(6)}, ${p.coords.lon.toFixed(6)}` : '');if (coordsText.trim()) resolveCoords();else regenerate();- });+ }// Consume an "open this draft" handoff from the sidebar$effect(() => {@@ -683,7 +726,7 @@return performDraftSave();}- async function performDraftSave() {+ async function performDraftSave(message = 'Draft saved') {saving = true;try {const r = await api.post(`/api/cases/${caseState.current.id}/drafts`, {@@ -694,9 +737,11 @@draftName = r.name;postName = r.title;await reloadCase(); // surface the post entity in the sidebar- toast('Draft saved', 'ok', 1600);+ toast(message, 'ok', 1600);+ return true;} catch (e) {toast(`Draft not saved: ${e.message}`, 'danger');+ return false;} finally {saving = false;overwritePrompt = null;diff --git a/frontend/src/tools/PostComposer.test.js b/frontend/src/tools/PostComposer.test.jsindex 55024fc..407dfc5 100644--- a/frontend/src/tools/PostComposer.test.js+++ b/frontend/src/tools/PostComposer.test.js@@ -38,6 +38,23 @@ describe('Geo Report actions', () => {});});+describe('Proof handoff', () => {+ it('files the current thread and starts a fresh one when a new proof arrives', () => {+ expect(source).toContain("import { filingName, planProofHandoff } from './post/handoff.js';");+ expect(source).toContain(+ 'const plan = planProofHandoff({ incomingPng: p.png, currentPng: proofPng, hasContent });'+ );+ expect(source).toContain("if (plan === 'file-then-apply') {");+ expect(source).toContain('if (!(await fileCurrentDraft())) return;');+ expect(source).toContain('resetDraft();\n }\n applyProof(p);');+ });++ it('keeps the outgoing thread when its save fails, rather than losing it', () => {+ expect(source).toContain('const saved = await performDraftSave(`Post saved: ${postName.trim()}`);');+ expect(source).toContain('if (!saved) return false;');+ });+});+describe('Post naming', () => {it('names the draft in the header, like Inspect and the Proof Composer', () => {expect(source).toContain('<input class="input title-input" bind:value={postName}');diff --git a/frontend/src/tools/post/handoff.js b/frontend/src/tools/post/handoff.jsnew file mode 100644index 0000000..614a085--- /dev/null+++ b/frontend/src/tools/post/handoff.js@@ -0,0 +1,27 @@+/**+ * What the Post Composer does with a proof handed over by the Proof Composer+ * ("To Post").+ *+ * A second proof is a second piece of work, so it gets its own thread: the one+ * on screen is written to its own file first, then makes way. Sending the same+ * proof again is the same work edited, so it stays in the thread that already+ * carries it.+ */++/** `'apply'` to load the proof into the thread on screen, `'file-then-apply'`+ * to save that thread and start a fresh one for the proof. */+export function planProofHandoff({ incomingPng, currentPng, hasContent }) {+ if (incomingPng && incomingPng === currentPng) return 'apply';+ return hasContent ? 'file-then-apply' : 'apply';+}++/**+ * Name to file the outgoing thread under. A bound draft keeps its own name+ * (it writes back over its own file). An unbound one whose name is already+ * taken would land on another draft, and the handoff has nobody to ask, so it+ * takes `fresh` instead.+ */+export function filingName({ title, bound, takenSlugs, slug, fresh }) {+ if (bound) return title;+ return takenSlugs.has(slug) ? fresh : title;+}diff --git a/frontend/src/tools/post/handoff.test.js b/frontend/src/tools/post/handoff.test.jsnew file mode 100644index 0000000..8157ecf--- /dev/null+++ b/frontend/src/tools/post/handoff.test.js@@ -0,0 +1,55 @@+import { describe, expect, it } from 'vitest';+import { filingName, planProofHandoff } from './handoff.js';++describe('planProofHandoff', () => {+ it('files the thread on screen before a different proof takes the composer', () => {+ expect(planProofHandoff({+ incomingPng: 'proofs/second.png',+ currentPng: 'proofs/first.png',+ hasContent: true,+ })).toBe('file-then-apply');+ });++ it('stays in the same thread when the proof it already carries comes back', () => {+ expect(planProofHandoff({+ incomingPng: 'proofs/first.png',+ currentPng: 'proofs/first.png',+ hasContent: true,+ })).toBe('apply');+ });++ it('loads straight into an empty composer', () => {+ expect(planProofHandoff({+ incomingPng: 'proofs/first.png',+ currentPng: null,+ hasContent: false,+ })).toBe('apply');+ });++ it('treats a proof handed over without an image as a new thread', () => {+ expect(planProofHandoff({ incomingPng: null, currentPng: null, hasContent: true }))+ .toBe('file-then-apply');+ });+});++describe('filingName', () => {+ const takenSlugs = new Set(['Post 1']);++ it('keeps the name a bound draft is saved under', () => {+ expect(filingName({+ title: 'Post 1', bound: true, takenSlugs, slug: 'Post 1', fresh: 'Post 2',+ })).toBe('Post 1');+ });++ it('moves an unbound draft off a name another draft holds', () => {+ expect(filingName({+ title: 'Post 1', bound: false, takenSlugs, slug: 'Post 1', fresh: 'Post 2',+ })).toBe('Post 2');+ });++ it('leaves a free name alone', () => {+ expect(filingName({+ title: 'Rooftop shot', bound: false, takenSlugs, slug: 'Rooftop shot', fresh: 'Post 2',+ })).toBe('Rooftop shot');+ });+});