From f06325c11c62f5904324426f821201861ea17d10 Mon Sep 17 00:00:00 2001 From: dorj222 Date: Wed, 1 Mar 2023 13:58:07 +0100 Subject: [PATCH] fix a merge conflict --- .../admin/config/server/StreamKeys.tsx | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/web/components/admin/config/server/StreamKeys.tsx b/web/components/admin/config/server/StreamKeys.tsx index 7532b5494..2ca850215 100644 --- a/web/components/admin/config/server/StreamKeys.tsx +++ b/web/components/admin/config/server/StreamKeys.tsx @@ -35,8 +35,26 @@ const saveKeys = async (keys, setError) => { } }; +const generateRndKey = () => { + let defaultKey = ''; + let isValidStreamKey = false; + const streamKeyRegex = /^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[!@#$%^&*]).{8,192}$/; + const s = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*'; + + while (!isValidStreamKey) { + const temp = Array.apply(20, Array(30)) + .map(() => s.charAt(Math.floor(Math.random() * s.length))) + .join(''); + if (streamKeyRegex.test(temp)) { + isValidStreamKey = true; + defaultKey = temp; + } + } + return defaultKey; +}; + const AddKeyForm = ({ setShowAddKeyForm, setFieldInConfigState, streamKeys, setError }) => { - const [hasChanged, setHasChanged] = useState(false); + const [hasChanged, setHasChanged] = useState(true); const [form] = Form.useForm(); const { Item } = Form; // Password Complexity rules @@ -70,6 +88,9 @@ const AddKeyForm = ({ setShowAddKeyForm, setFieldInConfigState, streamKeys, setE } }; + // Default auto-generated key + const defaultKey = generateRndKey(); + return (
- +