okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
fcb0c2d0e
main
1import { rawUrlOf } from './deliverables' ; 2 3/** 4* Which picture addresses a model's Markdown may put in an <img> (tools and images review O3, 2026-10-22). 5* 6* An answer can carry ``. It is shown only when the picture is already on this computer or inside the message: 7* - a data: address of a PNG, JPEG, WebP or GIF (never SVG: an SVG can carry script and styles); 8* - the host's own /api/files/raw address (a file inside the chat's folder, served by the host and by nobody else); 9* - a path without a scheme, which is read as a file of the chat's folder through that same address. 10* Nothing is fetched from the internet by default (an address in the answer would tell its owner that the answer was read, and 11* which IP read it): an http(s) picture stays a link the person can open. file:, javascript:, blob: and every other scheme show as text. 12*/ 13export type ImagePlan = 14| { kind :'img' ; src :string } 15| { kind :'link' ; href :string } 16| { kind :'text' }; 17 18const DATA_IMAGE = / ^data:image\/(?:png|jpe?g|webp|gif);base64,[A-Za-z0-9+/]+={0,2}$ / i ; 19const SCHEME = / ^[a-z][a-z0-9+.-]*: / i ; 20 21export function imagePlan ( src :string , sessionId ?:string | null ) :ImagePlan { 22const value = src . trim (); 23if ( ! value ) return { kind :'text' }; 24if ( DATA_IMAGE . test ( value )) return { kind :'img' , src :value }; 25if ( / ^https?:\/\/ / i . test ( value )) return { kind :'link' , href :value }; 26if ( value . startsWith ( '/api/files/raw?' )) return { kind :'img' , src :value }; 27// a drive letter (C:\x.png, C:/x.png) is a path, not a scheme 28if ( SCHEME . test ( value ) && ! /^[a-z]:[\\/] / i . test ( value )) return { kind :'text' }; 29if ( value . startsWith ( '//' ) || value . startsWith ( '\\\\' )) return { kind :'text' }; // another computer's share 30if ( ! sessionId ) return { kind :'text' }; 31return { kind :'img' , src :rawUrlOf ( sessionId , value ) }; 32}