|
@@ -1,144 +1,147 @@
|
|
|
-import { httpNoAuth } from "@/plugins/axiosNoAuth";
|
|
|
-import { VITE_CONFIG_FILE_SEVER_URL } from "@/constants/constants";
|
|
|
-import { VCAM_LIST, REMOTE_APP_NAME } from "@/constants/constant-namelist";
|
|
|
-import { decryptB } from "@/utils/utils";
|
|
|
-
|
|
|
-interface ParsedBlackAppConfig {
|
|
|
- vCamList: string[];
|
|
|
- remoteApp: string[];
|
|
|
- nameMap?: any;
|
|
|
-}
|
|
|
-
|
|
|
-interface RawBlackAppConfig {
|
|
|
- vCamList: string;
|
|
|
- remoteApp: string;
|
|
|
- nameMap?: any;
|
|
|
-}
|
|
|
-
|
|
|
-interface MergedBlackAppConfig {
|
|
|
- vCamList: string[];
|
|
|
- remoteApp: string;
|
|
|
- nameMap?: any;
|
|
|
-}
|
|
|
-
|
|
|
-interface GetBlackAppConfig {
|
|
|
- (): Promise<MergedBlackAppConfig>;
|
|
|
- fetch?: Promise<MergedBlackAppConfig>;
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- * @description 获取配置的虚拟摄像头和远程软件黑名单
|
|
|
- */
|
|
|
-export let getBlackAppConfig: GetBlackAppConfig = () => {
|
|
|
- if (getBlackAppConfig.fetch) {
|
|
|
- return getBlackAppConfig.fetch;
|
|
|
- }
|
|
|
- const fetch = httpNoAuth
|
|
|
- .get<string>(`${VITE_CONFIG_FILE_SEVER_URL}/oe_client/software.json`, {
|
|
|
- "axios-retry": { retries: 3 },
|
|
|
- noErrorMessage: true,
|
|
|
- })
|
|
|
- .then((response) => response.data)
|
|
|
- .catch(() => {
|
|
|
- getBlackAppConfig.fetch = void 0;
|
|
|
- return "";
|
|
|
- })
|
|
|
- .then(parseBlackAppConfig)
|
|
|
- .then(mergeBlackAppConfig)
|
|
|
- .then((result) => {
|
|
|
- console.log("result:", result);
|
|
|
- if (getBlackAppConfig.fetch) {
|
|
|
- getBlackAppConfig = () => Promise.resolve(result);
|
|
|
- }
|
|
|
- return result;
|
|
|
- });
|
|
|
- getBlackAppConfig.fetch = fetch;
|
|
|
- return fetch;
|
|
|
-};
|
|
|
-
|
|
|
-function parseBlackAppConfig(str: string): ParsedBlackAppConfig {
|
|
|
- const result: ParsedBlackAppConfig = {
|
|
|
- vCamList: [],
|
|
|
- remoteApp: [],
|
|
|
- };
|
|
|
- try {
|
|
|
- if (typeof str === "string") {
|
|
|
- const s = str.slice(0, -32).split("").reverse().join("");
|
|
|
- if (s.length) {
|
|
|
- try {
|
|
|
- const ret = decryptB(s);
|
|
|
- if (ret) {
|
|
|
- try {
|
|
|
- const parsed: RawBlackAppConfig = JSON.parse(ret);
|
|
|
- console.log("parsed::::", parsed);
|
|
|
- const nameMap: any = {};
|
|
|
- result.vCamList = processEditText(parsed.vCamList);
|
|
|
- result.remoteApp = processEditText(parsed.remoteApp).map(
|
|
|
- (item: string) => {
|
|
|
- if (item.includes("@@@")) {
|
|
|
- const arr = item.split("@@@");
|
|
|
- nameMap[arr[0]] = arr[1];
|
|
|
- return arr[0];
|
|
|
- } else {
|
|
|
- return item;
|
|
|
- }
|
|
|
- }
|
|
|
- );
|
|
|
- result.nameMap = nameMap;
|
|
|
- } catch (error) {
|
|
|
- console.warn("config json parse error!", error);
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (error) {
|
|
|
- console.warn("base64 decode error!", error);
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- console.warn("参数类型错误!");
|
|
|
- }
|
|
|
- } catch (error) {
|
|
|
- console.warn("parseBlackAppConfig error", error);
|
|
|
- }
|
|
|
- return result;
|
|
|
-}
|
|
|
-
|
|
|
-function isString(s: any): s is string {
|
|
|
- return typeof s === "string";
|
|
|
-}
|
|
|
-
|
|
|
-/** 换行符分割 */
|
|
|
-function processEditText(text: string) {
|
|
|
- return isString(text)
|
|
|
- ? text
|
|
|
- .split(/\r|\n/g)
|
|
|
- .map((s) => s.trim())
|
|
|
- .filter(Boolean)
|
|
|
- : [];
|
|
|
-}
|
|
|
-
|
|
|
-function mergeBlackAppConfig(
|
|
|
- remoteConfig: ParsedBlackAppConfig
|
|
|
-): MergedBlackAppConfig {
|
|
|
- const result: MergedBlackAppConfig = {
|
|
|
- vCamList: [],
|
|
|
- remoteApp: "",
|
|
|
- nameMap: {},
|
|
|
- };
|
|
|
- try {
|
|
|
- if (
|
|
|
- remoteConfig &&
|
|
|
- typeof remoteConfig === "object" &&
|
|
|
- remoteConfig.vCamList
|
|
|
- ) {
|
|
|
- const { vCamList, remoteApp, nameMap } = remoteConfig;
|
|
|
- result.vCamList = [...new Set([...vCamList, ...VCAM_LIST])];
|
|
|
- result.remoteApp = [
|
|
|
- ...new Set(REMOTE_APP_NAME.split(";").concat(...remoteApp)),
|
|
|
- ].join(";");
|
|
|
- result.nameMap = nameMap;
|
|
|
- }
|
|
|
- } catch (error) {
|
|
|
- console.warn("processBlackAppConfig error", error);
|
|
|
- }
|
|
|
- return result;
|
|
|
-}
|
|
|
+import { httpNoAuth } from "@/plugins/axiosNoAuth";
|
|
|
+import { VITE_CONFIG_FILE_SEVER_URL } from "@/constants/constants";
|
|
|
+import { VCAM_LIST, REMOTE_APP_NAME } from "@/constants/constant-namelist";
|
|
|
+import { decryptB } from "@/utils/utils";
|
|
|
+
|
|
|
+interface ParsedBlackAppConfig {
|
|
|
+ vCamList: string[];
|
|
|
+ remoteApp: string[];
|
|
|
+ nameMap?: any;
|
|
|
+}
|
|
|
+
|
|
|
+interface RawBlackAppConfig {
|
|
|
+ vCamList: string;
|
|
|
+ remoteApp: string;
|
|
|
+ nameMap?: any;
|
|
|
+}
|
|
|
+
|
|
|
+interface MergedBlackAppConfig {
|
|
|
+ vCamList: string[];
|
|
|
+ remoteApp: string;
|
|
|
+ nameMap?: any;
|
|
|
+}
|
|
|
+
|
|
|
+interface GetBlackAppConfig {
|
|
|
+ (): Promise<MergedBlackAppConfig>;
|
|
|
+ fetch?: Promise<MergedBlackAppConfig>;
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * @description 获取配置的虚拟摄像头和远程软件黑名单
|
|
|
+ */
|
|
|
+export let getBlackAppConfig: GetBlackAppConfig = () => {
|
|
|
+ if (getBlackAppConfig.fetch) {
|
|
|
+ return getBlackAppConfig.fetch;
|
|
|
+ }
|
|
|
+ const fetch = httpNoAuth
|
|
|
+ .get<string>(
|
|
|
+ `${VITE_CONFIG_FILE_SEVER_URL}/oe_client/software.json?v=${Date.now()}`,
|
|
|
+ {
|
|
|
+ "axios-retry": { retries: 3 },
|
|
|
+ noErrorMessage: true,
|
|
|
+ }
|
|
|
+ )
|
|
|
+ .then((response) => response.data)
|
|
|
+ .catch(() => {
|
|
|
+ getBlackAppConfig.fetch = void 0;
|
|
|
+ return "";
|
|
|
+ })
|
|
|
+ .then(parseBlackAppConfig)
|
|
|
+ .then(mergeBlackAppConfig)
|
|
|
+ .then((result) => {
|
|
|
+ console.log("result:", result);
|
|
|
+ if (getBlackAppConfig.fetch) {
|
|
|
+ getBlackAppConfig = () => Promise.resolve(result);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ });
|
|
|
+ getBlackAppConfig.fetch = fetch;
|
|
|
+ return fetch;
|
|
|
+};
|
|
|
+
|
|
|
+function parseBlackAppConfig(str: string): ParsedBlackAppConfig {
|
|
|
+ const result: ParsedBlackAppConfig = {
|
|
|
+ vCamList: [],
|
|
|
+ remoteApp: [],
|
|
|
+ };
|
|
|
+ try {
|
|
|
+ if (typeof str === "string") {
|
|
|
+ const s = str.slice(0, -32).split("").reverse().join("");
|
|
|
+ if (s.length) {
|
|
|
+ try {
|
|
|
+ const ret = decryptB(s);
|
|
|
+ if (ret) {
|
|
|
+ try {
|
|
|
+ const parsed: RawBlackAppConfig = JSON.parse(ret);
|
|
|
+ console.log("parsed::::", parsed);
|
|
|
+ const nameMap: any = {};
|
|
|
+ result.vCamList = processEditText(parsed.vCamList);
|
|
|
+ result.remoteApp = processEditText(parsed.remoteApp).map(
|
|
|
+ (item: string) => {
|
|
|
+ if (item.includes("@@@")) {
|
|
|
+ const arr = item.split("@@@");
|
|
|
+ nameMap[arr[0]] = arr[1];
|
|
|
+ return arr[0];
|
|
|
+ } else {
|
|
|
+ return item;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ );
|
|
|
+ result.nameMap = nameMap;
|
|
|
+ } catch (error) {
|
|
|
+ console.warn("config json parse error!", error);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.warn("base64 decode error!", error);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ console.warn("参数类型错误!");
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.warn("parseBlackAppConfig error", error);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
+function isString(s: any): s is string {
|
|
|
+ return typeof s === "string";
|
|
|
+}
|
|
|
+
|
|
|
+/** 换行符分割 */
|
|
|
+function processEditText(text: string) {
|
|
|
+ return isString(text)
|
|
|
+ ? text
|
|
|
+ .split(/\r|\n/g)
|
|
|
+ .map((s) => s.trim())
|
|
|
+ .filter(Boolean)
|
|
|
+ : [];
|
|
|
+}
|
|
|
+
|
|
|
+function mergeBlackAppConfig(
|
|
|
+ remoteConfig: ParsedBlackAppConfig
|
|
|
+): MergedBlackAppConfig {
|
|
|
+ const result: MergedBlackAppConfig = {
|
|
|
+ vCamList: [],
|
|
|
+ remoteApp: "",
|
|
|
+ nameMap: {},
|
|
|
+ };
|
|
|
+ try {
|
|
|
+ if (
|
|
|
+ remoteConfig &&
|
|
|
+ typeof remoteConfig === "object" &&
|
|
|
+ remoteConfig.vCamList
|
|
|
+ ) {
|
|
|
+ const { vCamList, remoteApp, nameMap } = remoteConfig;
|
|
|
+ result.vCamList = [...new Set([...vCamList, ...VCAM_LIST])];
|
|
|
+ result.remoteApp = [
|
|
|
+ ...new Set(REMOTE_APP_NAME.split(";").concat(...remoteApp)),
|
|
|
+ ].join(";");
|
|
|
+ result.nameMap = nameMap;
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.warn("processBlackAppConfig error", error);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+}
|