feat: add base url utility and update api endpoints
This commit is contained in:
4
.env
4
.env
@@ -1,6 +1,6 @@
|
|||||||
# VITE_API_BASE_URL
|
# VITE_API_BASE_URL
|
||||||
# VITE_API_BASE_URL = http://154.9.253.114:9380
|
VITE_API_BASE_URL = http://154.9.253.114:9380
|
||||||
VITE_API_BASE_URL = http://150.158.121.95
|
# VITE_API_BASE_URL = http://150.158.121.95
|
||||||
# VITE_FLASK_API_BASE_URL
|
# VITE_FLASK_API_BASE_URL
|
||||||
VITE_FLASK_API_BASE_URL = http://150.158.121.95
|
VITE_FLASK_API_BASE_URL = http://150.158.121.95
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
# 生产环境 FastAPI 后台服务配置
|
# 生产环境 FastAPI 后台服务配置
|
||||||
VITE_API_BASE_URL = http://150.158.121.95
|
# VITE_API_BASE_URL = http://150.158.121.95
|
||||||
# FastAPI 后台服务配置 154 内存不够,使用 150 作为后台
|
# FastAPI 后台服务配置 154 内存不够,使用 150 作为后台
|
||||||
# VITE_API_BASE_URL = http://154.9.253.114:9380
|
VITE_API_BASE_URL = http://154.9.253.114:9380
|
||||||
|
|
||||||
VITE_RSA_PUBLIC_KEY="-----BEGIN PUBLIC KEY-----
|
VITE_RSA_PUBLIC_KEY="-----BEGIN PUBLIC KEY-----
|
||||||
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArq9XTUSeYr2+N1h3Afl/z8Dse/2yD0ZGrKwx+EEEcdsBLca9Ynmx3nIB5obmLlSfmskLpBo0UACBmB5rEjBp2Q2f3AG3Hjd4B+gNCG6BDaawuDlgANIhGnaTLrIqWrrcm4EMzJOnAOI1fgzJRsOOUEfaS318Eq9OVO3apEyCCt0lOQK6PuksduOjVxtltDav+guVAA068NrPYmRNabVKRNLJpL8w4D44sfth5RvZ3q9t+6RTArpEtc5sh5ChzvqPOzKGMXW83C95TxmXqpbK6olN4RevSfVjEAgCydH6HN6OhtOQEcnrU97r9H0iZOWwbw3pVrZiUkuRD1R56Wzs2wIDAQAB
|
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArq9XTUSeYr2+N1h3Afl/z8Dse/2yD0ZGrKwx+EEEcdsBLca9Ynmx3nIB5obmLlSfmskLpBo0UACBmB5rEjBp2Q2f3AG3Hjd4B+gNCG6BDaawuDlgANIhGnaTLrIqWrrcm4EMzJOnAOI1fgzJRsOOUEfaS318Eq9OVO3apEyCCt0lOQK6PuksduOjVxtltDav+guVAA068NrPYmRNabVKRNLJpL8w4D44sfth5RvZ3q9t+6RTArpEtc5sh5ChzvqPOzKGMXW83C95TxmXqpbK6olN4RevSfVjEAgCydH6HN6OhtOQEcnrU97r9H0iZOWwbw3pVrZiUkuRD1R56Wzs2wIDAQAB
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
PORT=9222
|
PORT=9222
|
||||||
RAGFLOW_BASE=/ragflow/
|
RAGFLOW_BASE=/ragflow/
|
||||||
UMI_APP_API_BASE_URL=http://150.158.121.95
|
# UMI_APP_API_BASE_URL=http://150.158.121.95
|
||||||
|
UMI_APP_API_BASE_URL=http://154.9.253.114:9380
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
PORT=9222
|
PORT=9222
|
||||||
RAGFLOW_BASE=/ragflow/
|
RAGFLOW_BASE=/ragflow/
|
||||||
UMI_APP_API_BASE_URL=http://150.158.121.95
|
# UMI_APP_API_BASE_URL=http://150.158.121.95
|
||||||
|
UMI_APP_API_BASE_URL=http://154.9.253.114:9380
|
||||||
|
|||||||
@@ -143,7 +143,6 @@
|
|||||||
"@types/react-copy-to-clipboard": "^5.0.7",
|
"@types/react-copy-to-clipboard": "^5.0.7",
|
||||||
"@types/react-dom": "^18.0.11",
|
"@types/react-dom": "^18.0.11",
|
||||||
"@types/react-syntax-highlighter": "^15.5.11",
|
"@types/react-syntax-highlighter": "^15.5.11",
|
||||||
"@types/testing-library__jest-dom": "^6.0.0",
|
|
||||||
"@types/uuid": "^9.0.8",
|
"@types/uuid": "^9.0.8",
|
||||||
"@types/webpack-env": "^1.18.4",
|
"@types/webpack-env": "^1.18.4",
|
||||||
"@umijs/lint": "^4.1.1",
|
"@umijs/lint": "^4.1.1",
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { IAnswer, Message } from '@/interfaces/database/chat';
|
|||||||
import { IKnowledgeFile } from '@/interfaces/database/knowledge';
|
import { IKnowledgeFile } from '@/interfaces/database/knowledge';
|
||||||
import { IClientConversation, IMessage } from '@/pages/chat/interface';
|
import { IClientConversation, IMessage } from '@/pages/chat/interface';
|
||||||
import api from '@/utils/api';
|
import api from '@/utils/api';
|
||||||
|
import { withBaseUrl } from '@/utils/url';
|
||||||
import { getAuthorization } from '@/utils/authorization-util';
|
import { getAuthorization } from '@/utils/authorization-util';
|
||||||
import { buildMessageUuid } from '@/utils/chat';
|
import { buildMessageUuid } from '@/utils/chat';
|
||||||
import { PaginationProps, message } from 'antd';
|
import { PaginationProps, message } from 'antd';
|
||||||
@@ -239,7 +240,7 @@ export const useSendMessageWithSse = (
|
|||||||
initializeSseRef();
|
initializeSseRef();
|
||||||
try {
|
try {
|
||||||
setDoneValue(body, false);
|
setDoneValue(body, false);
|
||||||
const response = await fetch(url, {
|
const response = await fetch(withBaseUrl(url), {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
[Authorization]: getAuthorization(),
|
[Authorization]: getAuthorization(),
|
||||||
@@ -319,7 +320,7 @@ export const useSendMessageWithSse = (
|
|||||||
export const useSpeechWithSse = (url: string = api.tts) => {
|
export const useSpeechWithSse = (url: string = api.tts) => {
|
||||||
const read = useCallback(
|
const read = useCallback(
|
||||||
async (body: any) => {
|
async (body: any) => {
|
||||||
const response = await fetch(url, {
|
const response = await fetch(withBaseUrl(url), {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
[Authorization]: getAuthorization(),
|
[Authorization]: getAuthorization(),
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { Authorization } from '@/constants/authorization';
|
|||||||
import { IReferenceObject } from '@/interfaces/database/chat';
|
import { IReferenceObject } from '@/interfaces/database/chat';
|
||||||
import { BeginQuery } from '@/pages/agent/interface';
|
import { BeginQuery } from '@/pages/agent/interface';
|
||||||
import api from '@/utils/api';
|
import api from '@/utils/api';
|
||||||
|
import { withBaseUrl } from '@/utils/url';
|
||||||
import { getAuthorization } from '@/utils/authorization-util';
|
import { getAuthorization } from '@/utils/authorization-util';
|
||||||
import { EventSourceParserStream } from 'eventsource-parser/stream';
|
import { EventSourceParserStream } from 'eventsource-parser/stream';
|
||||||
import { useCallback, useRef, useState } from 'react';
|
import { useCallback, useRef, useState } from 'react';
|
||||||
@@ -108,7 +109,7 @@ export const useSendMessageBySSE = (url: string = api.completeConversation) => {
|
|||||||
initializeSseRef();
|
initializeSseRef();
|
||||||
try {
|
try {
|
||||||
setDone(false);
|
setDone(false);
|
||||||
const response = await fetch(url, {
|
const response = await fetch(withBaseUrl(url), {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
[Authorization]: getAuthorization(),
|
[Authorization]: getAuthorization(),
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { useEffect, useState } from 'react';
|
|||||||
|
|
||||||
import { Authorization } from '@/constants/authorization';
|
import { Authorization } from '@/constants/authorization';
|
||||||
import { getAuthorization } from '@/utils/authorization-util';
|
import { getAuthorization } from '@/utils/authorization-util';
|
||||||
|
import { withBaseUrl } from '@/utils/url';
|
||||||
|
|
||||||
interface ImageProps {
|
interface ImageProps {
|
||||||
src: string;
|
src: string;
|
||||||
@@ -15,7 +16,7 @@ const Image = ({ src, preview = false }: ImageProps) => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const loadImage = async () => {
|
const loadImage = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(src, {
|
const response = await fetch(withBaseUrl(src), {
|
||||||
headers: {
|
headers: {
|
||||||
[Authorization]: getAuthorization(),
|
[Authorization]: getAuthorization(),
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import {
|
|||||||
} from '@/hooks/logic-hooks';
|
} from '@/hooks/logic-hooks';
|
||||||
import { IAnswer } from '@/interfaces/database/chat';
|
import { IAnswer } from '@/interfaces/database/chat';
|
||||||
import api from '@/utils/api';
|
import api from '@/utils/api';
|
||||||
|
import { withBaseUrl } from '@/utils/url';
|
||||||
import { get, isEmpty, isEqual, trim } from 'lodash';
|
import { get, isEmpty, isEqual, trim } from 'lodash';
|
||||||
import {
|
import {
|
||||||
ChangeEventHandler,
|
ChangeEventHandler,
|
||||||
@@ -156,7 +157,7 @@ export const useFetchBackgroundImage = () => {
|
|||||||
const fetchImage = useCallback(async () => {
|
const fetchImage = useCallback(async () => {
|
||||||
try {
|
try {
|
||||||
const res = await fetch(
|
const res = await fetch(
|
||||||
'/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=zh-CN',
|
withBaseUrl('/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=zh-CN'),
|
||||||
);
|
);
|
||||||
const ret = await res.json();
|
const ret = await res.json();
|
||||||
const url = get(ret, 'images.0.url');
|
const url = get(ret, 'images.0.url');
|
||||||
|
|||||||
24
ragflow_web/src/utils/url.ts
Normal file
24
ragflow_web/src/utils/url.ts
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
export const getBaseUrl = (): string => {
|
||||||
|
const url = process.env.UMI_APP_API_BASE_URL || '';
|
||||||
|
return url.replace(/\/+$/, '');
|
||||||
|
};
|
||||||
|
|
||||||
|
const isAbsoluteUrl = (u: string): boolean => {
|
||||||
|
if (!u) return false;
|
||||||
|
const lower = u.toLowerCase();
|
||||||
|
return (
|
||||||
|
lower.startsWith('http://') ||
|
||||||
|
lower.startsWith('https://') ||
|
||||||
|
lower.startsWith('data:') ||
|
||||||
|
lower.startsWith('blob:')
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const withBaseUrl = (input: string): string => {
|
||||||
|
if (!input) return input;
|
||||||
|
if (isAbsoluteUrl(input)) return input;
|
||||||
|
const base = getBaseUrl();
|
||||||
|
if (!base) return input;
|
||||||
|
if (input.startsWith('/')) return `${base}${input}`;
|
||||||
|
return `${base}/${input}`;
|
||||||
|
};
|
||||||
@@ -47,9 +47,9 @@ export const useAgentList = (initialParams?: IAgentPaginationParams) => {
|
|||||||
const envMode = import.meta.env.MODE;
|
const envMode = import.meta.env.MODE;
|
||||||
let response: any = null;
|
let response: any = null;
|
||||||
// if (envMode === 'flask') {
|
// if (envMode === 'flask') {
|
||||||
response = await agentService.teamlistCanvas(params);
|
// response = await agentService.teamlistCanvas(params);
|
||||||
// } else {
|
// } else {
|
||||||
// response = await agentService.listCanvas(params);
|
response = await agentService.listCanvas(params);
|
||||||
// }
|
// }
|
||||||
const res = response.data || {};
|
const res = response.data || {};
|
||||||
logger.info('useAgentList fetchAgentList', res);
|
logger.info('useAgentList fetchAgentList', res);
|
||||||
|
|||||||
@@ -351,7 +351,7 @@ export function PipelineSelectorItem() {
|
|||||||
try {
|
try {
|
||||||
const envMode = import.meta.env.MODE;
|
const envMode = import.meta.env.MODE;
|
||||||
// const service = envMode === 'flask' ? agentService.teamlistCanvas : agentService.listCanvas;
|
// const service = envMode === 'flask' ? agentService.teamlistCanvas : agentService.listCanvas;
|
||||||
const service = agentService.teamlistCanvas;
|
const service = agentService.listCanvas;
|
||||||
const res = await service({ canvas_category: AgentCategory.DataflowCanvas, page_size: 100 });
|
const res = await service({ canvas_category: AgentCategory.DataflowCanvas, page_size: 100 });
|
||||||
const data = res?.data?.data || {};
|
const data = res?.data?.data || {};
|
||||||
const list = data.canvas || [];
|
const list = data.canvas || [];
|
||||||
|
|||||||
Reference in New Issue
Block a user