统一API Base URL保存与请求时去除末尾斜杠
This commit is contained in:
@@ -5,6 +5,7 @@ import { NextRequest, NextResponse } from 'next/server';
|
||||
import { getAuthInfoFromCookie } from '@/lib/auth';
|
||||
import { getConfig } from '@/lib/config';
|
||||
import { db } from '@/lib/db';
|
||||
import { normalizeApiBaseUrl } from '@/lib/url';
|
||||
|
||||
export const runtime = 'nodejs';
|
||||
|
||||
@@ -156,22 +157,22 @@ export async function POST(request: NextRequest) {
|
||||
Enabled,
|
||||
Provider,
|
||||
OpenAIApiKey,
|
||||
OpenAIBaseURL,
|
||||
OpenAIBaseURL: normalizeApiBaseUrl(OpenAIBaseURL),
|
||||
OpenAIModel,
|
||||
ClaudeApiKey,
|
||||
ClaudeModel,
|
||||
CustomApiKey,
|
||||
CustomBaseURL,
|
||||
CustomBaseURL: normalizeApiBaseUrl(CustomBaseURL),
|
||||
CustomModel,
|
||||
EnableDecisionModel,
|
||||
DecisionProvider,
|
||||
DecisionOpenAIApiKey,
|
||||
DecisionOpenAIBaseURL,
|
||||
DecisionOpenAIBaseURL: normalizeApiBaseUrl(DecisionOpenAIBaseURL),
|
||||
DecisionOpenAIModel,
|
||||
DecisionClaudeApiKey,
|
||||
DecisionClaudeModel,
|
||||
DecisionCustomApiKey,
|
||||
DecisionCustomBaseURL,
|
||||
DecisionCustomBaseURL: normalizeApiBaseUrl(DecisionCustomBaseURL),
|
||||
DecisionCustomModel,
|
||||
EnableWebSearch,
|
||||
WebSearchProvider,
|
||||
|
||||
@@ -5,6 +5,7 @@ import { NextRequest, NextResponse } from 'next/server';
|
||||
import { getAuthInfoFromCookie } from '@/lib/auth';
|
||||
import { getConfig, setCachedConfig } from '@/lib/config';
|
||||
import { db } from '@/lib/db';
|
||||
import { normalizeApiBaseUrl } from '@/lib/url';
|
||||
|
||||
export const runtime = 'nodejs';
|
||||
|
||||
@@ -63,7 +64,7 @@ export async function POST(request: NextRequest) {
|
||||
// 更新缓存中的音乐配置
|
||||
adminConfig.MusicConfig = {
|
||||
Enabled,
|
||||
BaseUrl,
|
||||
BaseUrl: normalizeApiBaseUrl(BaseUrl),
|
||||
Token,
|
||||
ProxyEnabled: ProxyEnabled ?? true,
|
||||
};
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
normalizePathMetaMap,
|
||||
type OpenListPathMetaMap,
|
||||
} from '@/lib/openlist-path-meta';
|
||||
import { normalizeApiBaseUrl } from '@/lib/url';
|
||||
|
||||
export const runtime = 'nodejs';
|
||||
|
||||
@@ -82,18 +83,20 @@ export async function POST(request: NextRequest) {
|
||||
|
||||
if (action === 'save') {
|
||||
const cleanedPathMeta = parsePathMeta(PathMeta);
|
||||
const normalizedURL = normalizeApiBaseUrl(URL);
|
||||
const normalizedOfflineDownloadURL = normalizeApiBaseUrl(OfflineDownloadURL);
|
||||
|
||||
// 如果功能未启用,允许保存空配置
|
||||
if (!Enabled) {
|
||||
adminConfig.OpenListConfig = {
|
||||
Enabled: false,
|
||||
URL: URL || '',
|
||||
URL: normalizedURL,
|
||||
Username: Username || '',
|
||||
Password: Password || '',
|
||||
RootPaths: RootPaths || ['/'],
|
||||
OfflineDownloadPath: OfflineDownloadPath || '/',
|
||||
OfflineDownloadUseCustomSource: OfflineDownloadUseCustomSource || false,
|
||||
OfflineDownloadURL: OfflineDownloadURL || '',
|
||||
OfflineDownloadURL: normalizedOfflineDownloadURL,
|
||||
OfflineDownloadUsername: OfflineDownloadUsername || '',
|
||||
OfflineDownloadPassword: OfflineDownloadPassword || '',
|
||||
LastRefreshTime: adminConfig.OpenListConfig?.LastRefreshTime,
|
||||
@@ -113,7 +116,7 @@ export async function POST(request: NextRequest) {
|
||||
}
|
||||
|
||||
// 功能启用时,验证必填字段
|
||||
if (!URL || !Username || !Password) {
|
||||
if (!normalizedURL || !Username || !Password) {
|
||||
return NextResponse.json(
|
||||
{ error: '请提供 URL、账号和密码' },
|
||||
{ status: 400 }
|
||||
@@ -122,7 +125,9 @@ export async function POST(request: NextRequest) {
|
||||
|
||||
if (
|
||||
OfflineDownloadUseCustomSource &&
|
||||
(!OfflineDownloadURL || !OfflineDownloadUsername || !OfflineDownloadPassword)
|
||||
(!normalizedOfflineDownloadURL ||
|
||||
!OfflineDownloadUsername ||
|
||||
!OfflineDownloadPassword)
|
||||
) {
|
||||
return NextResponse.json(
|
||||
{ error: '请提供离线下载 OpenList URL、账号和密码' },
|
||||
@@ -153,7 +158,7 @@ export async function POST(request: NextRequest) {
|
||||
// 验证账号密码是否正确
|
||||
try {
|
||||
console.log('[OpenList Config] 验证账号密码');
|
||||
await OpenListClient.login(URL, Username, Password);
|
||||
await OpenListClient.login(normalizedURL, Username, Password);
|
||||
console.log('[OpenList Config] 账号密码验证成功');
|
||||
} catch (error) {
|
||||
console.error('[OpenList Config] 账号密码验证失败:', error);
|
||||
@@ -167,7 +172,7 @@ export async function POST(request: NextRequest) {
|
||||
try {
|
||||
console.log('[OpenList Config] 验证离线下载 OpenList 账号密码');
|
||||
await OpenListClient.login(
|
||||
OfflineDownloadURL,
|
||||
normalizedOfflineDownloadURL,
|
||||
OfflineDownloadUsername,
|
||||
OfflineDownloadPassword
|
||||
);
|
||||
@@ -183,13 +188,13 @@ export async function POST(request: NextRequest) {
|
||||
|
||||
adminConfig.OpenListConfig = {
|
||||
Enabled: true,
|
||||
URL,
|
||||
URL: normalizedURL,
|
||||
Username,
|
||||
Password,
|
||||
RootPaths: cleanedRootPaths,
|
||||
OfflineDownloadPath: OfflineDownloadPath || '/',
|
||||
OfflineDownloadUseCustomSource: OfflineDownloadUseCustomSource || false,
|
||||
OfflineDownloadURL: OfflineDownloadURL || '',
|
||||
OfflineDownloadURL: normalizedOfflineDownloadURL,
|
||||
OfflineDownloadUsername: OfflineDownloadUsername || '',
|
||||
OfflineDownloadPassword: OfflineDownloadPassword || '',
|
||||
LastRefreshTime: adminConfig.OpenListConfig?.LastRefreshTime,
|
||||
|
||||
@@ -5,6 +5,7 @@ import { NextRequest, NextResponse } from 'next/server';
|
||||
import { getAuthInfoFromCookie } from '@/lib/auth';
|
||||
import { getConfig } from '@/lib/config';
|
||||
import { db } from '@/lib/db';
|
||||
import { normalizeApiBaseUrl } from '@/lib/url';
|
||||
|
||||
export const runtime = 'nodejs';
|
||||
|
||||
@@ -264,6 +265,7 @@ export async function POST(request: NextRequest) {
|
||||
}
|
||||
|
||||
// 更新缓存中的站点设置
|
||||
// API Base URL 统一去尾斜杠,避免运行时拼接路径出现 //
|
||||
adminConfig.SiteConfig = {
|
||||
SiteName,
|
||||
Announcement,
|
||||
@@ -271,33 +273,33 @@ export async function POST(request: NextRequest) {
|
||||
SearchDownstreamMaxPage,
|
||||
SiteInterfaceCacheTime,
|
||||
DoubanProxyType,
|
||||
DoubanProxy,
|
||||
DoubanProxy: normalizeApiBaseUrl(DoubanProxy),
|
||||
DoubanImageProxyType,
|
||||
DoubanImageProxy,
|
||||
DoubanImageProxy: normalizeApiBaseUrl(DoubanImageProxy),
|
||||
DisableYellowFilter,
|
||||
FluidSearch,
|
||||
DanmakuSourceType,
|
||||
DanmakuApiBase,
|
||||
DanmakuApiBase: normalizeApiBaseUrl(DanmakuApiBase),
|
||||
DanmakuApiToken,
|
||||
DanmakuAutoLoadDefault,
|
||||
TMDBApiKey,
|
||||
TMDBProxy,
|
||||
TMDBReverseProxy,
|
||||
TMDBProxy: normalizeApiBaseUrl(TMDBProxy),
|
||||
TMDBReverseProxy: normalizeApiBaseUrl(TMDBReverseProxy),
|
||||
BangumiDataSource,
|
||||
BangumiApiBaseUrl,
|
||||
BangumiImageBaseUrl,
|
||||
BangumiProxy,
|
||||
BangumiApiBaseUrl: normalizeApiBaseUrl(BangumiApiBaseUrl),
|
||||
BangumiImageBaseUrl: normalizeApiBaseUrl(BangumiImageBaseUrl),
|
||||
BangumiProxy: normalizeApiBaseUrl(BangumiProxy),
|
||||
BannerDataSource,
|
||||
RecommendationDataSource,
|
||||
PansouApiUrl,
|
||||
PansouApiUrl: normalizeApiBaseUrl(PansouApiUrl),
|
||||
PansouUsername,
|
||||
PansouPassword,
|
||||
PansouKeywordBlocklist,
|
||||
MagnetProxy,
|
||||
MagnetMikanReverseProxy,
|
||||
MagnetDmhyReverseProxy,
|
||||
MagnetAcgripReverseProxy,
|
||||
MagnetNyaaReverseProxy,
|
||||
MagnetProxy: normalizeApiBaseUrl(MagnetProxy),
|
||||
MagnetMikanReverseProxy: normalizeApiBaseUrl(MagnetMikanReverseProxy),
|
||||
MagnetDmhyReverseProxy: normalizeApiBaseUrl(MagnetDmhyReverseProxy),
|
||||
MagnetAcgripReverseProxy: normalizeApiBaseUrl(MagnetAcgripReverseProxy),
|
||||
MagnetNyaaReverseProxy: normalizeApiBaseUrl(MagnetNyaaReverseProxy),
|
||||
EnableComments,
|
||||
CustomAdFilterCode,
|
||||
CustomAdFilterVersion,
|
||||
@@ -311,7 +313,7 @@ export async function POST(request: NextRequest) {
|
||||
DefaultUserTags,
|
||||
EnableOIDCLogin,
|
||||
EnableOIDCRegistration,
|
||||
OIDCIssuer,
|
||||
OIDCIssuer: normalizeApiBaseUrl(OIDCIssuer),
|
||||
OIDCAuthorizationEndpoint,
|
||||
OIDCTokenEndpoint,
|
||||
OIDCUserInfoEndpoint,
|
||||
|
||||
@@ -5,6 +5,7 @@ import { NextRequest, NextResponse } from 'next/server';
|
||||
import { getAuthInfoFromCookie } from '@/lib/auth';
|
||||
import { getConfig } from '@/lib/config';
|
||||
import { db } from '@/lib/db';
|
||||
import { normalizeApiBaseUrl } from '@/lib/url';
|
||||
import { XiaoyaClient } from '@/lib/xiaoya.client';
|
||||
|
||||
export const runtime = 'nodejs';
|
||||
@@ -27,7 +28,7 @@ export async function POST(request: NextRequest) {
|
||||
// 测试连接
|
||||
try {
|
||||
const client = new XiaoyaClient(
|
||||
configData.ServerURL,
|
||||
normalizeApiBaseUrl(configData.ServerURL),
|
||||
configData.Username,
|
||||
configData.Password,
|
||||
configData.Token
|
||||
@@ -51,7 +52,7 @@ export async function POST(request: NextRequest) {
|
||||
|
||||
config.XiaoyaConfig = {
|
||||
Enabled: configData.Enabled || false,
|
||||
ServerURL: configData.ServerURL || '',
|
||||
ServerURL: normalizeApiBaseUrl(configData.ServerURL),
|
||||
Token: configData.Token,
|
||||
Username: configData.Username,
|
||||
Password: configData.Password,
|
||||
|
||||
Reference in New Issue
Block a user