Add attachment previews and data URLs for drops

This commit is contained in:
Shantur Rathore
2025-11-19 21:33:56 +00:00
parent d3ee15dcd7
commit 8fab34e356
4 changed files with 146 additions and 13 deletions

View File

@@ -722,7 +722,7 @@ export default function PromptInput(props: PromptInputProps) {
const createAndStoreAttachment = (previewUrl?: string) => {
const attachment = createFileAttachment(path, filename, mime, undefined, props.instanceFolder)
if (previewUrl && mime.startsWith("image/")) {
if (previewUrl && (mime.startsWith("image/") || mime.startsWith("text/"))) {
attachment.url = previewUrl
}
addAttachment(props.instanceId, props.sessionId, attachment)
@@ -735,6 +735,13 @@ export default function PromptInput(props: PromptInputProps) {
createAndStoreAttachment(result)
}
reader.readAsDataURL(file)
} else if (mime.startsWith("text/") && typeof FileReader !== "undefined") {
const reader = new FileReader()
reader.onload = () => {
const dataUrl = typeof reader.result === "string" ? reader.result : undefined
createAndStoreAttachment(dataUrl)
}
reader.readAsDataURL(file)
} else {
createAndStoreAttachment()
}