fix(common): fix
This commit is contained in:
70
api/fetch.ts
70
api/fetch.ts
@@ -50,9 +50,11 @@ async function httpfetch<T>(options: OptionsProps): Promise<T> {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
const createSsrRequest: (options: OptionsProps, token?: string) => Request = (
|
const createSsrRequest: (
|
||||||
options
|
options: OptionsProps,
|
||||||
) => {
|
token?: string,
|
||||||
|
refreshToken?: string
|
||||||
|
) => Request = (options) => {
|
||||||
// 设置请求头
|
// 设置请求头
|
||||||
let myHeaders = new Headers()
|
let myHeaders = new Headers()
|
||||||
if (!options.isUpload && !options.isFormData && !options.notJson) {
|
if (!options.isUpload && !options.isFormData && !options.notJson) {
|
||||||
@@ -85,14 +87,17 @@ async function httpfetch<T>(options: OptionsProps): Promise<T> {
|
|||||||
return request
|
return request
|
||||||
}
|
}
|
||||||
|
|
||||||
const createCsrRequest: (options: OptionsProps, token?: string) => Request = (
|
const createCsrRequest: (
|
||||||
options,
|
options: OptionsProps,
|
||||||
token = ""
|
token?: string,
|
||||||
) => {
|
refreshToken?: string
|
||||||
|
) => Request = (options, token = "", refreshToken = "") => {
|
||||||
let request = new Request(options.url)
|
let request = new Request(options.url)
|
||||||
// 设置请求头
|
// 设置请求头
|
||||||
let myHeaders = new Headers()
|
let myHeaders = new Headers()
|
||||||
myHeaders.append("Authorization", `bearer ${token}`)
|
myHeaders.append("Authorization", `bearer ${token}`)
|
||||||
|
myHeaders.append("Token", token)
|
||||||
|
myHeaders.append("Refresh-Token", refreshToken)
|
||||||
if (!options.isUpload && !options.isFormData && !options.notJson) {
|
if (!options.isUpload && !options.isFormData && !options.notJson) {
|
||||||
myHeaders.append("Content-Type", "application/json")
|
myHeaders.append("Content-Type", "application/json")
|
||||||
}
|
}
|
||||||
@@ -139,7 +144,7 @@ async function httpfetch<T>(options: OptionsProps): Promise<T> {
|
|||||||
? createSsrRequest
|
? createSsrRequest
|
||||||
: createCsrRequest
|
: createCsrRequest
|
||||||
|
|
||||||
const request = createNewRequest(options, access_token)
|
const request = createNewRequest(options, access_token, refresh_token)
|
||||||
|
|
||||||
return new Promise((resolved, rejected) => {
|
return new Promise((resolved, rejected) => {
|
||||||
fetch(request)
|
fetch(request)
|
||||||
@@ -171,12 +176,9 @@ async function httpfetch<T>(options: OptionsProps): Promise<T> {
|
|||||||
}
|
}
|
||||||
} else if (status === 401) {
|
} else if (status === 401) {
|
||||||
try {
|
try {
|
||||||
const refreshResponse = await refreshKey({
|
const refreshResponse = await refreshKey()
|
||||||
token: refresh_token,
|
let access_token = refreshResponse?.access || ""
|
||||||
})
|
let refresh_token = refreshResponse?.refresh || ""
|
||||||
if (refreshResponse.code === 200) {
|
|
||||||
let access_token = refreshResponse.message?.access || ""
|
|
||||||
let refresh_token = refreshResponse.message?.refresh || ""
|
|
||||||
refreshToken({
|
refreshToken({
|
||||||
refresh_token,
|
refresh_token,
|
||||||
access_token,
|
access_token,
|
||||||
@@ -186,7 +188,6 @@ async function httpfetch<T>(options: OptionsProps): Promise<T> {
|
|||||||
return options.isDownload
|
return options.isDownload
|
||||||
? retry_response.blob()
|
? retry_response.blob()
|
||||||
: retry_response.json()
|
: retry_response.json()
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
rejected(error)
|
rejected(error)
|
||||||
try {
|
try {
|
||||||
@@ -231,7 +232,17 @@ async function httpfetch<T>(options: OptionsProps): Promise<T> {
|
|||||||
const data = await response.json()
|
const data = await response.json()
|
||||||
const { message: errInfo } = data
|
const { message: errInfo } = data
|
||||||
Message.error({ content: errInfo || "" })
|
Message.error({ content: errInfo || "" })
|
||||||
throw new Error(errInfo)
|
// throw new Error(errInfo)
|
||||||
|
rejected(errInfo)
|
||||||
|
try {
|
||||||
|
await deleteCookie()
|
||||||
|
} catch (error) {
|
||||||
|
rejected(error)
|
||||||
|
} finally {
|
||||||
|
// 清空身份信息并跳转至登录页面
|
||||||
|
removeUserInfo()
|
||||||
|
window.location.href = "/login"
|
||||||
|
}
|
||||||
} else if (status >= 510) {
|
} else if (status >= 510) {
|
||||||
Message.error({ content: "申请资源不足!" })
|
Message.error({ content: "申请资源不足!" })
|
||||||
throw new Error("申请资源不足!")
|
throw new Error("申请资源不足!")
|
||||||
@@ -242,19 +253,17 @@ async function httpfetch<T>(options: OptionsProps): Promise<T> {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then(async (response) => {
|
.then(async (response) => {
|
||||||
const { code, message: errInfo } = response
|
const code = response?.code
|
||||||
|
const errInfo = response?.message || ""
|
||||||
if (response) {
|
if (response) {
|
||||||
if (isNumber(code)) {
|
if (isNumber(code)) {
|
||||||
let status = code
|
let status = code
|
||||||
// 日后做相关处理
|
// 日后做相关处理
|
||||||
if (status === 401) {
|
if (status === 401) {
|
||||||
try {
|
try {
|
||||||
const refreshResponse = await refreshKey({
|
const refreshResponse = await refreshKey()
|
||||||
token: refresh_token,
|
let access_token = refreshResponse?.access || ""
|
||||||
})
|
let refresh_token = refreshResponse?.refresh || ""
|
||||||
if (refreshResponse.code === 200) {
|
|
||||||
let access_token = refreshResponse.message?.access || ""
|
|
||||||
let refresh_token = refreshResponse.message?.refresh || ""
|
|
||||||
refreshToken({
|
refreshToken({
|
||||||
refresh_token,
|
refresh_token,
|
||||||
access_token,
|
access_token,
|
||||||
@@ -264,21 +273,6 @@ async function httpfetch<T>(options: OptionsProps): Promise<T> {
|
|||||||
return options.isDownload
|
return options.isDownload
|
||||||
? retry_response.blob()
|
? retry_response.blob()
|
||||||
: retry_response.json()
|
: retry_response.json()
|
||||||
} else {
|
|
||||||
if (refreshResponse.code === 406) {
|
|
||||||
try {
|
|
||||||
await deleteCookie()
|
|
||||||
} catch (error) {
|
|
||||||
rejected(error)
|
|
||||||
} finally {
|
|
||||||
// 清空身份信息并跳转至登录页面
|
|
||||||
removeUserInfo()
|
|
||||||
window.location.href = "/login"
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new Error("重新获取token失败!")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
rejected(error)
|
rejected(error)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,21 +61,24 @@ export async function POST(req: any) {
|
|||||||
method,
|
method,
|
||||||
headers: {
|
headers: {
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
|
["Token"]: userData?.refresh_token,
|
||||||
|
["Refresh-Token"]: userData?.refresh_token,
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
// body: JSON.stringify({
|
||||||
token: userData?.refresh_token,
|
// token: userData?.refresh_token,
|
||||||
}),
|
// }),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const authorization = `bearer ${userData?.access_token}`
|
const access_token = `${userData?.access_token}`
|
||||||
fetchOptions = {
|
fetchOptions = {
|
||||||
method,
|
method,
|
||||||
headers: {
|
headers: {
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
authorization: authorization,
|
["Token"]: access_token,
|
||||||
|
["Refresh-Token"]: userData?.refresh_token,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if (method === "POST" || method === "PUT") {
|
if (method === "POST" || method === "PUT" || method === "DELETE") {
|
||||||
fetchOptions.body = data
|
fetchOptions.body = data
|
||||||
} else {
|
} else {
|
||||||
if (isParamsValid(data)) {
|
if (isParamsValid(data)) {
|
||||||
|
|||||||
12
build.sh
12
build.sh
@@ -71,23 +71,23 @@ pnpm run $BUILD_FLAG
|
|||||||
if [[ $? != 0 ]]; then echo -e "${RED}build error${NC}"; exit 100; fi
|
if [[ $? != 0 ]]; then echo -e "${RED}build error${NC}"; exit 100; fi
|
||||||
|
|
||||||
# Docker构建和推送
|
# Docker构建和推送
|
||||||
MAIN_NAME=digitalspace_labelui
|
MAIN_NAME=digitalspace_labelmain
|
||||||
DOCKER_FILE=$SHELL_FOLDER/Dockerfile
|
DOCKER_FILE=$SHELL_FOLDER/Dockerfile
|
||||||
|
|
||||||
if [[ $OUTPUT_TYPE == export ]]; then
|
if [[ $OUTPUT_TYPE == export ]]; then
|
||||||
DOCKER_FILE=$SHELL_FOLDER/docker/nginx.dockerfile
|
DOCKER_FILE=$SHELL_FOLDER/docker/nginx.dockerfile
|
||||||
MAIN_NAME=digitalspace_labelui_static
|
MAIN_NAME=digitalspace_labelmain_static
|
||||||
elif [[ $OUTPUT_TYPE == standalone ]]; then
|
elif [[ $OUTPUT_TYPE == standalone ]]; then
|
||||||
DOCKER_FILE=$SHELL_FOLDER/docker/node.dockerfile
|
DOCKER_FILE=$SHELL_FOLDER/docker/node.dockerfile
|
||||||
MAIN_NAME=digitalspace_labelui_ssr
|
MAIN_NAME=digitalspace_labelmain_ssr
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo -e "${GREEN}Building docker image...${NC}"
|
echo -e "${GREEN}Building docker image...${NC}"
|
||||||
docker build -f $DOCKER_FILE -t $MAIN_NAME $SHELL_FOLDER
|
sudo docker build -f $DOCKER_FILE -t $MAIN_NAME $SHELL_FOLDER
|
||||||
if [[ $? != 0 ]]; then echo -e "${RED}build docker with error${NC}"; exit 100; fi
|
if [[ $? != 0 ]]; then echo -e "${RED}build docker with error${NC}"; exit 100; fi
|
||||||
|
|
||||||
echo -e "${GREEN}Tagging and pushing docker image...${NC}"
|
echo -e "${GREEN}Tagging and pushing docker image...${NC}"
|
||||||
docker tag $MAIN_NAME harbor.cowarobot.cn/gopro/$MAIN_NAME:$FLAG_PROD
|
sudo docker tag $MAIN_NAME harbor.cowarobot.cn/gopro/$MAIN_NAME:$FLAG_PROD
|
||||||
docker push harbor.cowarobot.cn/gopro/$MAIN_NAME:$FLAG_PROD
|
# docker push harbor.cowarobot.cn/gopro/$MAIN_NAME:$FLAG_PROD
|
||||||
|
|
||||||
echo -e "${GREEN}Build completed successfully${NC}"
|
echo -e "${GREEN}Build completed successfully${NC}"
|
||||||
|
|||||||
@@ -28,8 +28,25 @@ export const subConfigList: { source: string; url: string }[] =
|
|||||||
url: "http://localhost:5535",
|
url: "http://localhost:5535",
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
: process.env.NEXT_PUBLIC_ENV === "standalone"
|
: process.env.NEXT_PUBLIC_ENV === "staging"
|
||||||
? []
|
? [
|
||||||
|
{
|
||||||
|
source: "/image",
|
||||||
|
url: "http://172.30.21.213:5532",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
source: "/video",
|
||||||
|
url: "http://172.30.21.213:5533",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
source: "/lidar",
|
||||||
|
url: "http://172.30.21.213:5534",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
source: "/mgt",
|
||||||
|
url: "http://172.30.21.213:5535",
|
||||||
|
},
|
||||||
|
]
|
||||||
: []
|
: []
|
||||||
|
|
||||||
const currentComponentList: MenuItem[] = [
|
const currentComponentList: MenuItem[] = [
|
||||||
|
|||||||
@@ -47,11 +47,18 @@ export const fetchFeishuLogin = (params: Login.ReqFeishuLogin) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 刷新token
|
// 刷新token
|
||||||
export const refreshKey = (params: { token: string }) => {
|
// export const refreshKey = (params: { token: string }) => {
|
||||||
return httpFetch<ResultData<Login.ResRefreshKey>>({
|
// return httpFetch<ResultData<Login.ResRefreshKey>>({
|
||||||
|
// url: BASE_PATH + `/api/v1/label_server/user/refresh_token`,
|
||||||
|
// method: "POST",
|
||||||
|
// data: params,
|
||||||
|
// isRefresh: true,
|
||||||
|
// })
|
||||||
|
// }
|
||||||
|
export const refreshKey = () => {
|
||||||
|
return httpFetch<Login.ResRefreshKey>({
|
||||||
url: BASE_PATH + `/api/v1/label_server/user/refresh_token`,
|
url: BASE_PATH + `/api/v1/label_server/user/refresh_token`,
|
||||||
method: "POST",
|
method: "GET",
|
||||||
body: JSON.stringify(params),
|
|
||||||
isRefresh: true,
|
isRefresh: true,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
version: "3"
|
version: "3"
|
||||||
|
|
||||||
services:
|
services:
|
||||||
digitalspace_labelui_ssr:
|
digitalspace_labelmain_ssr:
|
||||||
container_name: digitalspace_labelui_ssr
|
container_name: digitalspace_labelmain_ssr
|
||||||
image: harbor.cowarobot.cn/gopro/digitalspace_labelui_ssr:stage_latest
|
image: harbor.cowarobot.cn/gopro/digitalspace_labelmain_ssr:stage_latest
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
ports:
|
ports:
|
||||||
- 5531:5531
|
- 5531:5531
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "labelui",
|
"name": "labelmain",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Reference in New Issue
Block a user