import { Button } from '@heroui/button' import { Input } from '@heroui/input' import { Popover, PopoverContent, PopoverTrigger } from '@heroui/popover' import { Tooltip } from '@heroui/tooltip' import { useRef, useState } from 'react' import toast from 'react-hot-toast' import { FaFolder } from 'react-icons/fa6' import { LuFilePlus2 } from 'react-icons/lu' import { MdEdit, MdUpload } from 'react-icons/md' import useShowStructuredMessage from '@/hooks/use_show_strcuted_message' import { isURI } from '@/utils/url' import type { OB11Segment } from '@/types/onebot' const FileInsert = () => { const [fileUrl, setFileUrl] = useState('') const fileInputRef = useRef(null) const showStructuredMessage = useShowStructuredMessage() const showFileSegment = (file: string) => { const messages: OB11Segment[] = [ { type: 'file', data: { file: file } } ] showStructuredMessage(messages) } return ( <>
setFileUrl(e.target.value)} placeholder="请输入文件地址" />
{ const file = e.target.files?.[0] if (!file) { return } const reader = new FileReader() reader.readAsDataURL(file) reader.onload = (event) => { const dataURL = event.target?.result showFileSegment(dataURL as string) e.target.value = '' } }} /> ) } export default FileInsert