-
-
Notifications
You must be signed in to change notification settings - Fork 268
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
287 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,53 @@ | ||
import axios from 'axios'; | ||
import { getToken } from './cookie'; | ||
import axios from "axios"; | ||
import { getToken } from "./cookie"; | ||
|
||
export const baseURL = import.meta.env.VITE_API_URL || '/api/v1'; | ||
export const baseURL = import.meta.env.VITE_API_URL || "/api/v1"; | ||
|
||
const instance = axios.create({ | ||
baseURL, | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
baseURL, | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
}); | ||
|
||
instance.interceptors.request.use( | ||
(config) => { | ||
const token = getToken() | ||
if (token) { | ||
config.headers!.Authorization = `Bearer ${token}`; | ||
} | ||
return config; | ||
}, | ||
(error) => { | ||
return Promise.reject(error); | ||
(config) => { | ||
const token = getToken(); | ||
if (token) { | ||
config.headers!.Authorization = `Bearer ${token}`; | ||
} | ||
return config; | ||
}, | ||
(error) => { | ||
return Promise.reject(error); | ||
}, | ||
); | ||
|
||
instance.interceptors.response.use( | ||
(res) => { | ||
return res; | ||
}, | ||
async (err) => { | ||
const originalConfig = err.config; | ||
if (err.response) { | ||
if (err.response.status === 401 && !originalConfig._retry) { | ||
originalConfig._retry = true; | ||
try { | ||
return instance(originalConfig); | ||
} catch (_error) { | ||
|
||
return Promise.reject(_error); | ||
} | ||
} | ||
|
||
if (err.response.status === 403 && err.response.data) { | ||
return Promise.reject(err.response.data); | ||
} | ||
(res) => { | ||
return res; | ||
}, | ||
async (err) => { | ||
const originalConfig = err.config; | ||
if (err.response) { | ||
if (err.response.status === 401 && !originalConfig._retry) { | ||
originalConfig._retry = true; | ||
try { | ||
return instance(originalConfig); | ||
} catch (_error) { | ||
return Promise.reject(_error); | ||
} | ||
} else if (err.response.status === 401 && originalConfig._retry) { | ||
window.location.href = "/#/login"; | ||
} | ||
|
||
return Promise.reject(err); | ||
if (err.response.status === 403 && err.response.data) { | ||
return Promise.reject(err.response.data); | ||
} | ||
} | ||
|
||
return Promise.reject(err); | ||
}, | ||
); | ||
|
||
export default instance; | ||
export default instance; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
-- AlterTable | ||
ALTER TABLE "Bot" ADD COLUMN "options" JSON DEFAULT '{}', | ||
ADD COLUMN "use_rag" BOOLEAN NOT NULL DEFAULT false; | ||
|
||
ALTER TABLE "Bot" ADD COLUMN "bot_protect" BOOLEAN NOT NULL DEFAULT false; | ||
|
||
|
||
ALTER TABLE "Bot" ADD COLUMN "bot_api_key" TEXT NULL DEFAULT NULL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.