浏览代码

增加首页上传视频音频限制

黎海 2 月之前
父节点
当前提交
e04e1a6774
共有 3 个文件被更改,包括 28 次插入4 次删除
  1. 2 2
      src/App.js
  2. 13 1
      src/components/audioUpload/index.js
  3. 13 1
      src/components/videoUpload/index.js

+ 2 - 2
src/App.js

@@ -59,11 +59,11 @@ function App () {
59
           视频对口型
59
           视频对口型
60
           </Navbar.Brand>
60
           </Navbar.Brand>
61
           <Navbar.Toggle aria-controls="basic-navbar-nav" className="custom-toggler" />
61
           <Navbar.Toggle aria-controls="basic-navbar-nav" className="custom-toggler" />
62
-          <Navbar.Collapse id="basic-navbar-nav" >
62
+          {/* <Navbar.Collapse id="basic-navbar-nav" >
63
             <Nav className="navigation-tab" >
63
             <Nav className="navigation-tab" >
64
               <NavLink className='tab-info' to='/histList' activeClassName="active-link">历史记录</NavLink>
64
               <NavLink className='tab-info' to='/histList' activeClassName="active-link">历史记录</NavLink>
65
             </Nav>
65
             </Nav>
66
-          </Navbar.Collapse>
66
+          </Navbar.Collapse> */}
67
         </Navbar>
67
         </Navbar>
68
         <div className='content'>
68
         <div className='content'>
69
           <Routes userProfileRef={userProfileRef} /> {/* 使用Routes组件 */}
69
           <Routes userProfileRef={userProfileRef} /> {/* 使用Routes组件 */}

+ 13 - 1
src/components/audioUpload/index.js

@@ -15,6 +15,15 @@ const AudioUpload = ({ onAudioSelected }) => {
15
       // 检查文件类型
15
       // 检查文件类型
16
       if (!selectedFile.type.startsWith('audio/')) {
16
       if (!selectedFile.type.startsWith('audio/')) {
17
         toast.error('请选择有效的音频文件');
17
         toast.error('请选择有效的音频文件');
18
+        e.target.value = '';
19
+        return;
20
+      }
21
+      
22
+      // 检查文件大小
23
+      const maxSize = 512 * 1024 * 1024; // 512MB
24
+      if (selectedFile.size > maxSize) {
25
+        toast.error(`音频文件大小(${(selectedFile.size / (1024 * 1024)).toFixed(2)}MB)超过了512MB的限制,请选择较小的文件`);
26
+        e.target.value = '';
18
         return;
27
         return;
19
       }
28
       }
20
       
29
       
@@ -26,7 +35,7 @@ const AudioUpload = ({ onAudioSelected }) => {
26
         onAudioSelected(selectedFile);
35
         onAudioSelected(selectedFile);
27
       }
36
       }
28
       
37
       
29
-      toast.success('音频文件已选择');
38
+      toast.success(`音频文件已选择,大小: ${(selectedFile.size / (1024 * 1024)).toFixed(2)}MB`);
30
     }
39
     }
31
   };
40
   };
32
 
41
 
@@ -70,6 +79,9 @@ const AudioUpload = ({ onAudioSelected }) => {
70
                   音频文件已选择 ✓
79
                   音频文件已选择 ✓
71
                 </Form.Text>
80
                 </Form.Text>
72
               )}
81
               )}
82
+              <Form.Text className="text-muted">
83
+                支持的格式: MP3, WAV, OGG等常见音频格式,文件大小不能超过512MB
84
+              </Form.Text>
73
             </Form.Group>
85
             </Form.Group>
74
           </Form>
86
           </Form>
75
         </Card.Body>
87
         </Card.Body>

+ 13 - 1
src/components/videoUpload/index.js

@@ -15,6 +15,15 @@ const VideoUpload = ({ onVideoSelected }) => {
15
       // 检查文件类型
15
       // 检查文件类型
16
       if (!selectedFile.type.startsWith('video/')) {
16
       if (!selectedFile.type.startsWith('video/')) {
17
         toast.error('请选择有效的视频文件');
17
         toast.error('请选择有效的视频文件');
18
+        e.target.value = '';
19
+        return;
20
+      }
21
+      
22
+      // 检查文件大小
23
+      const maxSize = 512 * 1024 * 1024; // 512MB
24
+      if (selectedFile.size > maxSize) {
25
+        toast.error(`视频文件大小(${(selectedFile.size / (1024 * 1024)).toFixed(2)}MB)超过了512MB的限制,请选择较小的文件`);
26
+        e.target.value = '';
18
         return;
27
         return;
19
       }
28
       }
20
       
29
       
@@ -26,7 +35,7 @@ const VideoUpload = ({ onVideoSelected }) => {
26
         onVideoSelected(selectedFile);
35
         onVideoSelected(selectedFile);
27
       }
36
       }
28
       
37
       
29
-      toast.success('视频文件已选择');
38
+      toast.success(`视频文件已选择,大小: ${(selectedFile.size / (1024 * 1024)).toFixed(2)}MB`);
30
     }
39
     }
31
   };
40
   };
32
 
41
 
@@ -70,6 +79,9 @@ const VideoUpload = ({ onVideoSelected }) => {
70
                   视频文件已选择 ✓
79
                   视频文件已选择 ✓
71
                 </Form.Text>
80
                 </Form.Text>
72
               )}
81
               )}
82
+              <Form.Text className="text-muted">
83
+                支持的格式: MP4, WebM, AVI等常见视频格式,文件大小不能超过512MB
84
+              </Form.Text>
73
             </Form.Group>
85
             </Form.Group>
74
           </Form>
86
           </Form>
75
         </Card.Body>
87
         </Card.Body>