Spaces:
Sleeping
Sleeping
wuyiqunLu
commited on
Commit
•
a3b619b
1
Parent(s):
009c95b
feat: limit video to 30s and image to 2.5mb (#60)
Browse files<img width="902" alt="image"
src="https://github.com/landing-ai/vision-agent-ui/assets/132986242/a81e8509-09ce-41cb-86ec-6f09608c44fc">
<img width="773" alt="image"
src="https://github.com/landing-ai/vision-agent-ui/assets/132986242/ddd2abe5-3032-4371-8183-1a13a38fc108">
components/chat/ImageSelector.tsx
CHANGED
@@ -9,7 +9,7 @@ import Loading from '../ui/Loading';
|
|
9 |
import toast from 'react-hot-toast';
|
10 |
import {
|
11 |
generateVideoThumbnails,
|
12 |
-
|
13 |
} from '@rajesh896/video-thumbnails-generator';
|
14 |
import { ChatWithMessages } from '@/lib/db/types';
|
15 |
import { dbPostCreateChat } from '@/lib/db/functions';
|
@@ -69,6 +69,18 @@ const ImageSelector: React.FC<ImageSelectorProps> = () => {
|
|
69 |
reader.readAsDataURL(files[0]);
|
70 |
reader.onload = async () => {
|
71 |
const file = files[0];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
const resp = await upload(file);
|
73 |
if (!resp) {
|
74 |
return;
|
|
|
9 |
import toast from 'react-hot-toast';
|
10 |
import {
|
11 |
generateVideoThumbnails,
|
12 |
+
getVideoDurationFromVideoFile,
|
13 |
} from '@rajesh896/video-thumbnails-generator';
|
14 |
import { ChatWithMessages } from '@/lib/db/types';
|
15 |
import { dbPostCreateChat } from '@/lib/db/functions';
|
|
|
69 |
reader.readAsDataURL(files[0]);
|
70 |
reader.onload = async () => {
|
71 |
const file = files[0];
|
72 |
+
if (file.type === 'video/mp4') {
|
73 |
+
const duration = await getVideoDurationFromVideoFile(file);
|
74 |
+
if (duration > 30) {
|
75 |
+
setUploading(false);
|
76 |
+
toast.error('Video duration must be less than 30 seconds');
|
77 |
+
return;
|
78 |
+
}
|
79 |
+
} else if (file.size > 2.5 * 1024 * 1024) {
|
80 |
+
setUploading(false);
|
81 |
+
toast.error('Image size must be less than 2.5MB');
|
82 |
+
return;
|
83 |
+
}
|
84 |
const resp = await upload(file);
|
85 |
if (!resp) {
|
86 |
return;
|