Przeglądaj źródła

fix(EditChannelModal): enhance clipboard handling with error checks

Added checks to ensure clipboard functionality is available before attempting to read from it. Improved error handling during clipboard read operations to prevent unhandled exceptions.
CaIon 1 miesiąc temu
rodzic
commit
670abee2f0

+ 1 - 1
controller/pricing.go

@@ -46,7 +46,7 @@ func GetPricing(c *gin.Context) {
 		"usable_group":       usableGroup,
 		"supported_endpoint": model.GetSupportedEndpointMap(),
 		"auto_groups":        service.GetUserAutoGroup(group),
-		"_":                  "a42d372ccf0b5dd13ecf71203521f9d2",
+		"pricing_version":    "a42d372ccf0b5dd13ecf71203521f9d2",
 	})
 }
 

+ 12 - 7
web/src/components/table/channels/modals/EditChannelModal.jsx

@@ -558,6 +558,10 @@ const EditChannelModal = (props) => {
   };
 
   const pasteFromClipboard = async () => {
+    if (!navigator?.clipboard?.readText) {
+      showError(t('无法读取剪贴板'));
+      return;
+    }
     try {
       const text = await navigator.clipboard.readText();
       const parsed = parseChannelConnectionString(text);
@@ -1302,13 +1306,14 @@ const EditChannelModal = (props) => {
         loadChannel();
       } else {
         formApiRef.current?.setValues(getInitValues());
-        // best-effort clipboard auto-detect for new channels
-        navigator.clipboard.readText().then((text) => {
-          const parsed = parseChannelConnectionString(text);
-          if (parsed) {
-            setClipboardConfig(parsed);
-          }
-        }).catch(() => {});
+        try {
+          navigator?.clipboard?.readText()?.then((text) => {
+            const parsed = parseChannelConnectionString(text);
+            if (parsed) {
+              setClipboardConfig(parsed);
+            }
+          }).catch(() => {});
+        } catch {}
       }
       fetchModelGroups();
       // 重置手动输入模式状态