Fix: Omit attached base64 images on copy

Co-authored-by: gemini-3.7-flash <noreply@google.com>
This commit is contained in:
2026-08-29 20:47:34 -07:00
parent 1365e6c4ca
commit 731b6a2dcc

View File

@@ -33,12 +33,52 @@ export const b64 = x => x.split(',')[1] || '';
export const utob = s => btoa(unescape(encodeURIComponent(s))); export const utob = s => btoa(unescape(encodeURIComponent(s)));
export const btou = s => decodeURIComponent(escape(atob(s.replace(/\s/g, '')))); export const btou = s => decodeURIComponent(escape(atob(s.replace(/\s/g, ''))));
export function partsToText(m) { export async function copyToClipboard(text) {
if (typeof text !== 'string') text = String(text ?? '');
if (navigator.clipboard?.writeText) {
try { await navigator.clipboard.writeText(text); return true; } catch {}
}
try {
const ta = document.createElement('textarea');
ta.value = text;
ta.style.position = 'fixed';
ta.style.opacity = '0';
ta.style.left = '-9999px';
document.body.appendChild(ta);
ta.focus();
ta.select();
const ok = document.execCommand('copy');
ta.remove();
return ok;
} catch { return false; }
}
export function partsToText(m, stripData = false) {
if (!m) return ''; if (!m) return '';
const c = m.content, i = m.images; const c = m.content, i = m.images, out = [];
let t = Array.isArray(c) ? c.map(p => p?.type === 'text' ? p.text : (p?.type === 'image_url' ? `![](${p.image_url?.url || ''})` : (p?.type === 'file' ? `[${p.file?.filename || 'file'}]` : (p?.type === 'input_audio' ? `(audio:${p.input_audio?.format || ''})` : '')))).join('\n') : String(c || ''); if (Array.isArray(c)) {
if (Array.isArray(i)) t += i.map(x => `\n![](${x.image_url?.url})\n`).join(''); for (const p of c) {
return t; if (p?.type === 'text') {
if (p.text) out.push(p.text);
} else if (p?.type === 'image_url') {
const u = p.image_url?.url || '';
if (!stripData || !u.startsWith('data:')) out.push(`![](${u})`);
} else if (p?.type === 'file') {
out.push(`[${p.file?.filename || 'file'}]`);
} else if (p?.type === 'input_audio') {
out.push(`(audio:${p.input_audio?.format || ''})`);
}
}
} else if (c != null) {
out.push(String(c));
}
if (Array.isArray(i)) {
for (const x of i) {
const u = x.image_url?.url || '';
if (!stripData || !u.startsWith('data:')) out.push(`![](${u})`);
}
}
return out.join('\n');
} }
export function dl(name, obj) { export function dl(name, obj) {