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