@@ -14,7 +14,9 @@ export type LocalAttachment =
1414 | Readonly < { type : "text" ; mime : "image/svg+xml" ; content : string } >
1515 | Readonly < { type : "binary" ; mime : string ; content : Uint8Array } >
1616
17- export function readLocalAttachment ( file : string , maxBytes = MAX_LOCAL_ATTACHMENT_BYTES ) {
17+ export type PasteAttach = "all" | "images" | "never"
18+
19+ export function readLocalAttachment ( file : string , maxBytes = MAX_LOCAL_ATTACHMENT_BYTES , mode : PasteAttach = "all" ) {
1820 return readLocalAttachmentWith (
1921 {
2022 readText : async ( value , limit ) => ( await readFileBounded ( value , limit ) ) . toString ( "utf8" ) ,
@@ -23,22 +25,25 @@ export function readLocalAttachment(file: string, maxBytes = MAX_LOCAL_ATTACHMEN
2325 } ,
2426 file ,
2527 maxBytes ,
28+ mode ,
2629 )
2730}
2831
29- export async function resolvePastedAttachments ( text : string , platform : string ) {
32+ export async function resolvePastedAttachments ( text : string , platform : string , mode : PasteAttach = "all" ) {
33+ if ( mode === "never" ) return undefined
3034 const pastedContent = text . trim ( )
3135 const filepath = normalizePastedFilepath ( pastedContent , platform )
3236 if ( / ^ ( h t t p s ? ) : \/ \/ / . test ( filepath ) ) return undefined
3337
34- const attachment = await readLocalAttachment ( filepath )
38+ const attachment = await readLocalAttachment ( filepath , MAX_LOCAL_ATTACHMENT_BYTES , mode )
3539 const attachments = attachment ? [ { filepath, attachment } ] : [ ]
3640 if ( ! attachment ) {
3741 const filepaths = parsePastedFilepaths ( pastedContent , platform )
3842 if ( filepaths . length <= 1 ) return undefined
3943 let remaining = MAX_LOCAL_ATTACHMENT_BYTES
4044 for ( const candidate of filepaths ) {
41- const next = await readLocalAttachment ( candidate , remaining )
45+ // Keep a mixed drop intact as text rather than silently omitting any paths.
46+ const next = await readLocalAttachment ( candidate , remaining , mode )
4247 if ( ! next ) return undefined
4348 remaining -= typeof next . content === "string" ? Buffer . byteLength ( next . content ) : next . content . byteLength
4449 attachments . push ( { filepath : candidate , attachment : next } )
@@ -161,9 +166,12 @@ export async function readLocalAttachmentWith(
161166 files : LocalFiles ,
162167 path : string ,
163168 maxBytes = MAX_LOCAL_ATTACHMENT_BYTES ,
169+ mode : PasteAttach = "all" ,
164170) : Promise < LocalAttachment | undefined > {
171+ if ( mode === "never" ) return undefined
165172 const mime = await files . mime ( path ) . catch ( ( ) => undefined )
166173 if ( ! mime ) return undefined
174+ if ( mode === "images" && ! mime . startsWith ( "image/" ) ) return undefined
167175 if ( ! mime . startsWith ( "image/" ) && mime !== "application/pdf" ) return undefined
168176 if ( mime === "image/svg+xml" ) {
169177 const content = await files . readText ( path , maxBytes ) . catch ( ( ) => undefined )
0 commit comments