Commit 80a24453eaafde0d211395d973857c6f9a0ffd37
Merge branch 'main_dev' of http://git.yunteng.com/yunteng/thingskit-front into v1.4.0_dev
Showing
10 changed files
with
86 additions
and
28 deletions
| ... | ... | @@ -34,6 +34,9 @@ VITE_GLOB_LARGE_DESIGNER = /large-designer |
| 34 | 34 | # Content Security Policy |
| 35 | 35 | VITE_GLOB_CONTENT_SECURITY_POLICY = false |
| 36 | 36 | |
| 37 | +# Streaming media content security protocol | |
| 38 | +VITE_GLOB_STREAM_MEDIA_CONTENT_SECURITY_PROTOCOL = true | |
| 39 | + | |
| 37 | 40 | # Alarm Notify Polling Interval Time |
| 38 | 41 | VITE_GLOB_ALARM_NOTIFY_POLLING_INTERVAL_TIME = 500000 |
| 39 | 42 | ... | ... |
| ... | ... | @@ -46,6 +46,9 @@ VITE_GLOB_LARGE_DESIGNER = /large-designer |
| 46 | 46 | # Content Security Policy |
| 47 | 47 | VITE_GLOB_CONTENT_SECURITY_POLICY = false |
| 48 | 48 | |
| 49 | +# Streaming media content security protocol | |
| 50 | +VITE_GLOB_STREAM_MEDIA_CONTENT_SECURITY_PROTOCOL = false | |
| 51 | + | |
| 49 | 52 | # Alarm Notify Polling Interval Time |
| 50 | 53 | VITE_GLOB_ALARM_NOTIFY_POLLING_INTERVAL_TIME = 60000 |
| 51 | 54 | ... | ... |
| ... | ... | @@ -10,6 +10,30 @@ import { getConfigFileName } from '../getConfigFileName'; |
| 10 | 10 | |
| 11 | 11 | import pkg from '../../package.json'; |
| 12 | 12 | |
| 13 | +const stringToJSONParse = (string: string) => { | |
| 14 | + try { | |
| 15 | + return JSON.parse(string); | |
| 16 | + } catch (error) { | |
| 17 | + return string; | |
| 18 | + } | |
| 19 | +}; | |
| 20 | + | |
| 21 | +export function parseEnv(env: Record<string, string>) { | |
| 22 | + const res: Record<string, string> = {}; | |
| 23 | + | |
| 24 | + Object.keys(env).forEach((key) => { | |
| 25 | + try { | |
| 26 | + const value = env[key]; | |
| 27 | + res[key] = stringToJSONParse(value); | |
| 28 | + } catch (err) { | |
| 29 | + // eslint-disable-next-line no-console | |
| 30 | + console.log(`env variable ${key} can't serialization!`); | |
| 31 | + } | |
| 32 | + }); | |
| 33 | + | |
| 34 | + return res; | |
| 35 | +} | |
| 36 | + | |
| 13 | 37 | function createConfig( |
| 14 | 38 | { |
| 15 | 39 | configName, |
| ... | ... | @@ -20,7 +44,7 @@ function createConfig( |
| 20 | 44 | try { |
| 21 | 45 | const windowConf = `window.${configName}`; |
| 22 | 46 | // Ensure that the variable will not be modified |
| 23 | - const configStr = `${windowConf}=${JSON.stringify(config)}; | |
| 47 | + const configStr = `${windowConf}=${JSON.stringify(parseEnv(config))}; | |
| 24 | 48 | Object.freeze(${windowConf}); |
| 25 | 49 | Object.defineProperty(window, "${configName}", { |
| 26 | 50 | configurable: false, |
| ... | ... | @@ -30,9 +54,12 @@ function createConfig( |
| 30 | 54 | fs.mkdirp(getRootPath(OUTPUT_DIR)); |
| 31 | 55 | writeFileSync(getRootPath(`${OUTPUT_DIR}/${configFileName}`), configStr); |
| 32 | 56 | |
| 57 | + // eslint-disable-next-line no-console | |
| 33 | 58 | console.log(chalk.cyan(`✨ [${pkg.name}]`) + ` - configuration file is build successfully:`); |
| 59 | + // eslint-disable-next-line no-console | |
| 34 | 60 | console.log(chalk.gray(OUTPUT_DIR + '/' + chalk.green(configFileName)) + '\n'); |
| 35 | 61 | } catch (error) { |
| 62 | + // eslint-disable-next-line no-console | |
| 36 | 63 | console.log(chalk.red('configuration file configuration file failed to package:\n' + error)); |
| 37 | 64 | } |
| 38 | 65 | } | ... | ... |
| ... | ... | @@ -18,6 +18,7 @@ export const useGlobSetting = (): Readonly<GlobConfig> => { |
| 18 | 18 | VITE_GLOB_LARGE_DESIGNER, |
| 19 | 19 | VITE_GLOB_DISABLED_TASK_CENTER_EXECUTE_INTERVAL_UNIT_SECOND, |
| 20 | 20 | VITE_GLOB_SOFTWARE_VERSION_NUMBER, |
| 21 | + VITE_GLOB_STREAM_MEDIA_CONTENT_SECURITY_PROTOCOL, | |
| 21 | 22 | } = getAppEnvConfig(); |
| 22 | 23 | |
| 23 | 24 | if (!/[a-zA-Z\_]*/.test(VITE_GLOB_APP_SHORT_NAME)) { |
| ... | ... | @@ -36,12 +37,14 @@ export const useGlobSetting = (): Readonly<GlobConfig> => { |
| 36 | 37 | configurationPrefix: VITE_GLOB_CONFIGURATION, |
| 37 | 38 | largeDesignerPrefix: VITE_GLOB_LARGE_DESIGNER, |
| 38 | 39 | socketUrl: VITE_GLOB_WEB_SOCKET, |
| 39 | - securityPolicy: VITE_GLOB_CONTENT_SECURITY_POLICY, | |
| 40 | - alarmNotifyDuration: VITE_GLOB_ALARM_NOTIFY_DURATION, | |
| 41 | - alarmPollingInterval: VITE_GLOB_ALARM_NOTIFY_POLLING_INTERVAL_TIME, | |
| 40 | + securityPolicy: VITE_GLOB_CONTENT_SECURITY_POLICY as unknown as boolean, | |
| 41 | + alarmNotifyDuration: VITE_GLOB_ALARM_NOTIFY_DURATION as unknown as number, | |
| 42 | + alarmPollingInterval: VITE_GLOB_ALARM_NOTIFY_POLLING_INTERVAL_TIME as unknown as number, | |
| 42 | 43 | disabledTaskCenterExecuteIntervalUnitSecond: |
| 43 | - VITE_GLOB_DISABLED_TASK_CENTER_EXECUTE_INTERVAL_UNIT_SECOND, | |
| 44 | + VITE_GLOB_DISABLED_TASK_CENTER_EXECUTE_INTERVAL_UNIT_SECOND as unknown as boolean, | |
| 44 | 45 | softwareVersionNumber: VITE_GLOB_SOFTWARE_VERSION_NUMBER, |
| 46 | + streamMediaContentSecurityProtocol: | |
| 47 | + VITE_GLOB_STREAM_MEDIA_CONTENT_SECURITY_PROTOCOL as unknown as boolean, | |
| 45 | 48 | }; |
| 46 | 49 | return glob as Readonly<GlobConfig>; |
| 47 | 50 | }; | ... | ... |
| ... | ... | @@ -4,7 +4,7 @@ let initialFlag = false; |
| 4 | 4 | export function useWebSecurityPolicy() { |
| 5 | 5 | if (window && window.document && window.document.documentElement) { |
| 6 | 6 | const { securityPolicy } = useGlobSetting(); |
| 7 | - if (securityPolicy === 'true' && !initialFlag) { | |
| 7 | + if (securityPolicy && !initialFlag) { | |
| 8 | 8 | const meta = document.createElement('meta'); |
| 9 | 9 | meta.setAttribute('http-equiv', 'Content-Security-Policy'); |
| 10 | 10 | meta.setAttribute('content', 'upgrade-insecure-requests'); | ... | ... |
| ... | ... | @@ -14,13 +14,38 @@ export function getStorageShortName() { |
| 14 | 14 | return `${getCommonStoragePrefix()}${`__${pkg.version}`}__`.toUpperCase(); |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | +const stringToJSONParse = (string: string) => { | |
| 18 | + try { | |
| 19 | + return JSON.parse(string); | |
| 20 | + } catch (error) { | |
| 21 | + return string; | |
| 22 | + } | |
| 23 | +}; | |
| 24 | + | |
| 25 | +export function parseEnv(env: Record<string, string>) { | |
| 26 | + const res: Record<string, string> = {}; | |
| 27 | + | |
| 28 | + Object.keys(env).forEach((key) => { | |
| 29 | + try { | |
| 30 | + const value = env[key]; | |
| 31 | + res[key] = stringToJSONParse(value); | |
| 32 | + } catch (err) { | |
| 33 | + // eslint-disable-next-line no-console | |
| 34 | + console.log(`env variable ${key} can't serialization!`); | |
| 35 | + } | |
| 36 | + }); | |
| 37 | + | |
| 38 | + return res; | |
| 39 | +} | |
| 40 | + | |
| 17 | 41 | export function getAppEnvConfig() { |
| 18 | 42 | const ENV_NAME = getConfigFileName(import.meta.env); |
| 19 | 43 | |
| 20 | 44 | const ENV = (import.meta.env.DEV |
| 21 | 45 | ? // Get the global configuration (the configuration will be extracted independently when packaging) |
| 22 | - (import.meta.env as unknown as GlobEnvConfig) | |
| 46 | + (parseEnv(import.meta.env as Record<string, string>) as unknown as GlobEnvConfig) | |
| 23 | 47 | : window[ENV_NAME as any]) as unknown as GlobEnvConfig; |
| 48 | + | |
| 24 | 49 | const { |
| 25 | 50 | VITE_GLOB_APP_TITLE, |
| 26 | 51 | VITE_GLOB_API_URL, |
| ... | ... | @@ -35,6 +60,7 @@ export function getAppEnvConfig() { |
| 35 | 60 | VITE_GLOB_LARGE_DESIGNER, |
| 36 | 61 | VITE_GLOB_DISABLED_TASK_CENTER_EXECUTE_INTERVAL_UNIT_SECOND, |
| 37 | 62 | VITE_GLOB_SOFTWARE_VERSION_NUMBER, |
| 63 | + VITE_GLOB_STREAM_MEDIA_CONTENT_SECURITY_PROTOCOL, | |
| 38 | 64 | } = ENV; |
| 39 | 65 | |
| 40 | 66 | if (!/^[a-zA-Z\_]*$/.test(VITE_GLOB_APP_SHORT_NAME)) { |
| ... | ... | @@ -57,6 +83,7 @@ export function getAppEnvConfig() { |
| 57 | 83 | VITE_GLOB_LARGE_DESIGNER, |
| 58 | 84 | VITE_GLOB_DISABLED_TASK_CENTER_EXECUTE_INTERVAL_UNIT_SECOND, |
| 59 | 85 | VITE_GLOB_SOFTWARE_VERSION_NUMBER, |
| 86 | + VITE_GLOB_STREAM_MEDIA_CONTENT_SECURITY_PROTOCOL, | |
| 60 | 87 | }; |
| 61 | 88 | } |
| 62 | 89 | ... | ... |
| ... | ... | @@ -25,8 +25,6 @@ import { useFingerprint } from '/@/utils/useFingerprint'; |
| 25 | 25 | import { getVideoControlStart } from '/@/api/device/videoChannel'; |
| 26 | 26 | import { StreamType as PlayerStreamType } from '/@/components/Video/src/types'; |
| 27 | 27 | import { useGlobSetting } from '/@/hooks/setting'; |
| 28 | -import { BooleanStringEnum } from '/@/enums/toolEnum'; | |
| 29 | -import { isBoolean } from '/@/utils/is'; | |
| 30 | 28 | |
| 31 | 29 | interface FileItem { |
| 32 | 30 | uid: string; |
| ... | ... | @@ -645,11 +643,9 @@ export async function getPlayUrl( |
| 645 | 643 | } else if (accessMode === AccessMode.GBT28181) { |
| 646 | 644 | const { deviceId, channelNo } = params?.params || {}; |
| 647 | 645 | const result = await getVideoControlStart({ channelId: channelNo!, deviceId: deviceId! }); |
| 648 | - const { securityPolicy } = useGlobSetting(); | |
| 646 | + const { streamMediaContentSecurityProtocol } = useGlobSetting(); | |
| 649 | 647 | return { |
| 650 | - url: (isBoolean(securityPolicy) ? securityPolicy : securityPolicy === BooleanStringEnum.TRUE) | |
| 651 | - ? result.data.https_flv | |
| 652 | - : result.data.flv, | |
| 648 | + url: !!streamMediaContentSecurityProtocol ? result.data.https_flv : result.data.flv, | |
| 653 | 649 | type: 'flv', |
| 654 | 650 | }; |
| 655 | 651 | } else { | ... | ... |
| ... | ... | @@ -59,8 +59,6 @@ |
| 59 | 59 | import { Authority } from '/@/components/Authority'; |
| 60 | 60 | import { VideoChannelItemType } from '/@/api/device/model/videoChannelModel'; |
| 61 | 61 | import { useGlobSetting } from '/@/hooks/setting'; |
| 62 | - import { BooleanStringEnum } from '/@/enums/toolEnum'; | |
| 63 | - import { isBoolean } from '/@/utils/is'; | |
| 64 | 62 | |
| 65 | 63 | const props = defineProps<{ deviceDetail: DeviceRecord }>(); |
| 66 | 64 | |
| ... | ... | @@ -112,14 +110,10 @@ |
| 112 | 110 | getPlayUrl: async () => { |
| 113 | 111 | const { deviceId, channelId } = record; |
| 114 | 112 | const result = await getVideoControlStart({ deviceId, channelId }); |
| 115 | - const { securityPolicy } = useGlobSetting(); | |
| 113 | + const { streamMediaContentSecurityProtocol } = useGlobSetting(); | |
| 116 | 114 | return { |
| 117 | 115 | type: 'flv', |
| 118 | - url: ( | |
| 119 | - isBoolean(securityPolicy) ? securityPolicy : securityPolicy === BooleanStringEnum.TRUE | |
| 120 | - ) | |
| 121 | - ? result.data.https_flv | |
| 122 | - : result.data.flv, | |
| 116 | + url: !!streamMediaContentSecurityProtocol ? result.data.https_flv : result.data.flv, | |
| 123 | 117 | }; |
| 124 | 118 | }, |
| 125 | 119 | } as VideoCancelModalParamsType, | ... | ... |
| ... | ... | @@ -38,15 +38,16 @@ |
| 38 | 38 | const handleValidateHasSameIdentifier = (formValue?: StructJSON) => { |
| 39 | 39 | const { identifier } = formValue || {}; |
| 40 | 40 | const message = '存在一致的标识符'; |
| 41 | - | |
| 42 | 41 | if (unref(currentMode) === DataActionModeEnum.CREATE) { |
| 43 | 42 | if (props.value.filter((item) => item.identifier === identifier).length >= 1) { |
| 44 | 43 | createMessage.warn(message); |
| 45 | 44 | return Promise.reject(message); |
| 46 | 45 | } |
| 47 | 46 | } else { |
| 48 | - const index = props.value.findIndex((item) => item.identifier === formValue?.identifier); | |
| 49 | - if (index !== unref(currentEditIndex)) { | |
| 47 | + const list = [...props.value]; | |
| 48 | + list.splice(unref(currentEditIndex), 1, formValue!); | |
| 49 | + const existLength = list.filter((item) => item?.identifier === formValue?.identifier).length; | |
| 50 | + if (existLength > 1) { | |
| 50 | 51 | createMessage.warn(message); |
| 51 | 52 | return Promise.reject(message); |
| 52 | 53 | } | ... | ... |
| ... | ... | @@ -153,13 +153,15 @@ export interface GlobConfig { |
| 153 | 153 | // socket url |
| 154 | 154 | socketUrl: string; |
| 155 | 155 | // alarm notify alarm duration |
| 156 | - alarmNotifyDuration: string; | |
| 156 | + alarmNotifyDuration: number; | |
| 157 | 157 | // alarm notify polling interval |
| 158 | - alarmPollingInterval: string; | |
| 158 | + alarmPollingInterval: number; | |
| 159 | 159 | // upgrade your http policy to https |
| 160 | - securityPolicy: string; | |
| 160 | + securityPolicy: boolean; | |
| 161 | + // Streaming media content security protocol | |
| 162 | + streamMediaContentSecurityProtocol: boolean; | |
| 161 | 163 | // Should Disabled Task Center Execute Interval Unit (Second) |
| 162 | - disabledTaskCenterExecuteIntervalUnitSecond: string; | |
| 164 | + disabledTaskCenterExecuteIntervalUnitSecond: boolean; | |
| 163 | 165 | // Software version number |
| 164 | 166 | softwareVersionNumber: string; |
| 165 | 167 | } |
| ... | ... | @@ -182,6 +184,8 @@ export interface GlobEnvConfig { |
| 182 | 184 | VITE_GLOB_WEB_SOCKET: string; |
| 183 | 185 | // force transform http to https |
| 184 | 186 | VITE_GLOB_CONTENT_SECURITY_POLICY: string; |
| 187 | + // Streaming media content security protocol | |
| 188 | + VITE_GLOB_STREAM_MEDIA_CONTENT_SECURITY_PROTOCOL: string; | |
| 185 | 189 | // notify polling interval time |
| 186 | 190 | VITE_GLOB_ALARM_NOTIFY_POLLING_INTERVAL_TIME: string; |
| 187 | 191 | // notify duration | ... | ... |