mirror of
https://github.com/multipleof4/sune.git
synced 2026-09-18 11:35:43 +00:00
Fix: Omit attached base64 images on copy
Co-authored-by: gemini-3.7-flash <noreply@google.com>
This commit is contained in:
50
src/utils.js
50
src/utils.js
@@ -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?.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\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(``);
|
||||||
|
} 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(``);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out.join('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function dl(name, obj) {
|
export function dl(name, obj) {
|
||||||
|
|||||||
Reference in New Issue
Block a user