Refine and clean files and variables (#10)

This commit is contained in:
AceDataCloud committed 2024-01-02 01:27:14 +08:00
1 parent 0e6018e9b2
commit 6e980c7c34
45 files changed
+98 -522

No files matched your search

+20 -22
View File
@@ -1,36 +1,34 @@
import { ENV_LOCAL, ENV_TEST } from '@/constants';
import { getEnv } from './env';
import { BASE_URL_AUTH, BASE_URL_DATA, BASE_URL_HUB } from '@/constants';
/**
* Get base url of app
* Get base url of data app
* @returns
*/
export const getDataBaseUrl = () => {
const env = getEnv();
if (env === ENV_LOCAL) {
return 'https://data.local.zhishuyun.com';
} else if (env === ENV_TEST) {
return 'https://data.test.zhishuyun.com';
} else {
return 'https://data.zhishuyun.com';
export const getBaseUrlData = () => {
if (import.meta.env.VITE_BASE_URL_DATA) {
return import.meta.env.VITE_BASE_URL_DATA;
}
return BASE_URL_DATA;
};
/**
* Get base url of app
* Get base url of hub app
* @returns
*/
export const getHubBaseUrl = () => {
return window.location.origin;
export const getBaseUrlHub = () => {
if (import.meta.env.VITE_BASE_URL_HUB) {
return import.meta.env.VITE_BASE_URL_HUB;
}
return BASE_URL_HUB;
};
export const getAuthBaseUrl = () => {
const env = getEnv();
if (env === ENV_LOCAL) {
return 'https://auth.test.zhishuyun.com';
} else if (env === ENV_TEST) {
return 'https://auth.test.zhishuyun.com';
} else {
return 'https://auth.zhishuyun.com';
/**
* Get base url of auth app
* @returns
*/
export const getBaseUrlAuth = () => {
if (import.meta.env.VITE_BASE_URL_AUTH) {
return import.meta.env.VITE_BASE_URL_AUTH;
}
return BASE_URL_AUTH;
};
-13
View File
@@ -1,13 +0,0 @@
import { removeCookie } from 'typescript-cookie';
export const removeCookies = () => {
const host = window.location.host;
// process test env and prod env, for example:
// auth.zhishuyun.com -> .zhishuyun.com
// auth.test.zhishuyun.com -> .zhishuyun.com
const domain = host.replace(/^\S+?\.(test\.|local\.)?/, '.');
const path = '/';
// remove tokens from cookies
removeCookie('ACCESS_TOKEN', { domain, path });
removeCookie('REFRESH_TOKEN', { domain, path });
};
-19
View File
@@ -1,19 +0,0 @@
import { ENV_LOCAL, ENV_PRODUCTION, ENV_TEST } from '@/constants';
const PATTERN_TEST_ENV = '.test.zhishuyun.com';
const PATTERN_LOCAL_ENV = '.local.zhishuyun.com';
/**
* Get env of App, return local, test, production
* @returns
*/
export const getEnv = () => {
const host = window.location.host;
if (host.indexOf(PATTERN_LOCAL_ENV) > 0) {
return ENV_LOCAL;
}
if (host.indexOf(PATTERN_TEST_ENV) > 0) {
return ENV_TEST;
}
return ENV_PRODUCTION;
};
+1 -2
View File
@@ -1,4 +1,3 @@
export * from './baseUrl';
export * from './env';
export * from './mode';
export * from './verification';
export * from './log';
+5
View File
@@ -1,3 +1,8 @@
/**
* Log function name and arguments
* @param func
* @param arg
*/
export const log = (func: Function, ...arg: any) => {
console.debug(`${func.name}`, ...arg);
};
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Get mode of App, return development or production
* Get mode of app, return development or production
* @returns
*/
export const getMode = () => {
-12
View File
@@ -1,12 +0,0 @@
/**
* Get verification url
* @returns
*/
import { getAuthBaseUrl } from './baseUrl';
export const getVerificationUrl = () => {
const baseUrl = getAuthBaseUrl();
const targetUrl = `${baseUrl}/user/verify?redirect=` + window.location.href;
return targetUrl;
};