mirror of
https://github.com/coaidev/coai.git
synced 2025-05-21 05:50:14 +09:00
feat: support paste file in file input
This commit is contained in:
parent
ce5a165c1f
commit
4fa85b1f12
@ -1,4 +1,4 @@
|
|||||||
import {getUniqueList} from "@/utils/base.ts";
|
import { getUniqueList } from "@/utils/base.ts";
|
||||||
|
|
||||||
export type Channel = {
|
export type Channel = {
|
||||||
id: number;
|
id: number;
|
||||||
@ -208,9 +208,9 @@ export const ChannelInfos: Record<string, ChannelInfo> = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const channelModels: string[] = getUniqueList(Object.values(ChannelInfos).flatMap(
|
export const channelModels: string[] = getUniqueList(
|
||||||
(info) => info.models,
|
Object.values(ChannelInfos).flatMap((info) => info.models),
|
||||||
));
|
);
|
||||||
|
|
||||||
export const channelGroups: string[] = [
|
export const channelGroups: string[] = [
|
||||||
"anonymous",
|
"anonymous",
|
||||||
|
@ -54,9 +54,10 @@ function FileProvider({ value, onChange }: FileProviderProps) {
|
|||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const triggerFile = async (files: File[]) => {
|
const triggerFile = async (files: (File | null)[]) => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
|
if (!file) continue;
|
||||||
if (file.size > MaxFileSize) {
|
if (file.size > MaxFileSize) {
|
||||||
toast({
|
toast({
|
||||||
title: t("file.over-size"),
|
title: t("file.over-size"),
|
||||||
@ -243,7 +244,7 @@ type FileInputProps = {
|
|||||||
id: string;
|
id: string;
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
className?: string;
|
className?: string;
|
||||||
handleEvent: (files: File[]) => void;
|
handleEvent: (files: (File | null)[]) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
function FileInput({ id, loading, className, handleEvent }: FileInputProps) {
|
function FileInput({ id, loading, className, handleEvent }: FileInputProps) {
|
||||||
@ -273,6 +274,14 @@ function FileInput({ id, loading, className, handleEvent }: FileInputProps) {
|
|||||||
onChange={(e) => handleEvent(Array.from(e.target?.files || []))}
|
onChange={(e) => handleEvent(Array.from(e.target?.files || []))}
|
||||||
accept="*"
|
accept="*"
|
||||||
style={{ display: "none" }}
|
style={{ display: "none" }}
|
||||||
|
// on transfer file
|
||||||
|
onPaste={(e) => {
|
||||||
|
const items = e.clipboardData.items;
|
||||||
|
const files = Array.from(items).filter(
|
||||||
|
(item) => item.kind === "file",
|
||||||
|
);
|
||||||
|
handleEvent(files.map((file) => file.getAsFile()));
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user