pastedFiles.ts713 BView on GitHub
/**
 * Clipboard-paste helpers for chat attachments.
 *
 * Files pasted from the clipboard (e.g. a copied screenshot) usually arrive with
 * an empty `name`. Downstream (attachment chips, the file allowlist's extension
 * fallback) expects a real filename, so we synthesize one from the MIME subtype.
 */

/**
 * Returns the given files with a synthesized filename for any that arrive
 * nameless. Files that already have a name are returned unchanged.
 */
export function normalizePastedFiles(files: File[]): File[] {
  return files.map((file) => {
    if (file.name) return file;
    const ext = file.type.split('/')[1] || 'png';
    return new File([file], `pasted-image.${ext}`, { type: file.type });
  });
}