统一端口设置,可以设置自义定端口

This commit is contained in:
2025-08-24 20:38:28 +08:00
parent a35e82731d
commit 275a3672d2
12 changed files with 284 additions and 291 deletions
+19 -3
View File
@@ -1,15 +1,31 @@
import axios, { type AxiosInstance, type AxiosRequestConfig, type AxiosResponse } from 'axios';
import type { ApiResponse } from '@/types';
// API配置
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || 'http://localhost:3000';
// API配置 - 使用相对路径,这样就不需要硬编码端口
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || '';
// 导出API基础URL,供其他组件使用
export const getApiBaseUrl = () => API_BASE_URL || window.location.origin;
// 获取图片代理URL的工具函数
export const getImageProxyUrl = (originalUrl: string) => {
if (!originalUrl) return '';
// 如果是Pixiv的图片URL,通过后端代理
if (originalUrl.includes('i.pximg.net')) {
const encodedUrl = encodeURIComponent(originalUrl);
return `${getApiBaseUrl()}/api/proxy/image?url=${encodedUrl}`;
}
return originalUrl;
};
class ApiService {
private client: AxiosInstance;
constructor() {
this.client = axios.create({
baseURL: API_BASE_URL,
baseURL: API_BASE_URL || window.location.origin,
timeout: 60000, // 增加到60秒
headers: {
'Content-Type': 'application/json',
+2 -2
View File
@@ -1,4 +1,4 @@
import apiService from './api';
import apiService, { getApiBaseUrl } from './api';
import type { DownloadTask } from '@/types';
class DownloadService {
@@ -132,7 +132,7 @@ class DownloadService {
* 使用SSE监听下载进度
*/
streamTaskProgress(taskId: string, onProgress: (task: DownloadTask) => void, onComplete?: () => void) {
const eventSource = new EventSource(`http://localhost:3000/api/download/stream/${taskId}`);
const eventSource = new EventSource(`${getApiBaseUrl()}/api/download/stream/${taskId}`);
eventSource.onmessage = (event) => {
try {