统一API Base URL保存与请求时去除末尾斜杠
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
* 文档: https://github.com/fish2018/pansou
|
||||
*/
|
||||
|
||||
import { normalizeApiBaseUrl } from '@/lib/url';
|
||||
|
||||
// Token 缓存
|
||||
let cachedToken: string | null = null;
|
||||
let tokenExpiry: number | null = null;
|
||||
@@ -40,7 +42,8 @@ export async function loginPansou(
|
||||
password: string
|
||||
): Promise<string> {
|
||||
try {
|
||||
const response = await fetch(`${apiUrl}/api/auth/login`, {
|
||||
const baseUrl = normalizeApiBaseUrl(apiUrl);
|
||||
const response = await fetch(`${baseUrl}/api/auth/login`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@@ -111,9 +114,10 @@ export async function searchPansou(
|
||||
}
|
||||
): Promise<PansouSearchResult> {
|
||||
try {
|
||||
const baseUrl = normalizeApiBaseUrl(apiUrl);
|
||||
// 获取 Token(如果需要认证)
|
||||
const token = await getValidToken(
|
||||
apiUrl,
|
||||
baseUrl,
|
||||
options?.username,
|
||||
options?.password
|
||||
);
|
||||
@@ -141,7 +145,7 @@ export async function searchPansou(
|
||||
body.cloud_types = options.cloudTypes;
|
||||
}
|
||||
|
||||
const response = await fetch(`${apiUrl}/api/search`, {
|
||||
const response = await fetch(`${baseUrl}/api/search`, {
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: JSON.stringify(body),
|
||||
@@ -201,7 +205,8 @@ export function clearPansouToken(): void {
|
||||
*/
|
||||
export async function checkPansouHealth(apiUrl: string): Promise<boolean> {
|
||||
try {
|
||||
const response = await fetch(`${apiUrl}/api/health`, {
|
||||
const baseUrl = normalizeApiBaseUrl(apiUrl);
|
||||
const response = await fetch(`${baseUrl}/api/health`, {
|
||||
method: 'GET',
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user