pansou增加关键词过滤
This commit is contained in:
@@ -336,6 +336,7 @@ interface SiteConfig {
|
|||||||
PansouApiUrl?: string;
|
PansouApiUrl?: string;
|
||||||
PansouUsername?: string;
|
PansouUsername?: string;
|
||||||
PansouPassword?: string;
|
PansouPassword?: string;
|
||||||
|
PansouKeywordBlocklist?: string;
|
||||||
EnableComments: boolean;
|
EnableComments: boolean;
|
||||||
EnableRegistration?: boolean;
|
EnableRegistration?: boolean;
|
||||||
RegistrationRequireTurnstile?: boolean;
|
RegistrationRequireTurnstile?: boolean;
|
||||||
@@ -6679,6 +6680,7 @@ const SiteConfigComponent = ({
|
|||||||
PansouApiUrl: '',
|
PansouApiUrl: '',
|
||||||
PansouUsername: '',
|
PansouUsername: '',
|
||||||
PansouPassword: '',
|
PansouPassword: '',
|
||||||
|
PansouKeywordBlocklist: '',
|
||||||
EnableComments: false,
|
EnableComments: false,
|
||||||
EnableRegistration: false,
|
EnableRegistration: false,
|
||||||
RegistrationRequireTurnstile: false,
|
RegistrationRequireTurnstile: false,
|
||||||
@@ -6769,6 +6771,7 @@ const SiteConfigComponent = ({
|
|||||||
PansouApiUrl: config.SiteConfig.PansouApiUrl || '',
|
PansouApiUrl: config.SiteConfig.PansouApiUrl || '',
|
||||||
PansouUsername: config.SiteConfig.PansouUsername || '',
|
PansouUsername: config.SiteConfig.PansouUsername || '',
|
||||||
PansouPassword: config.SiteConfig.PansouPassword || '',
|
PansouPassword: config.SiteConfig.PansouPassword || '',
|
||||||
|
PansouKeywordBlocklist: config.SiteConfig.PansouKeywordBlocklist || '',
|
||||||
EnableComments: config.SiteConfig.EnableComments || false,
|
EnableComments: config.SiteConfig.EnableComments || false,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -7508,6 +7511,28 @@ const SiteConfigComponent = ({
|
|||||||
配置账号密码后,系统会自动登录并缓存 Token
|
配置账号密码后,系统会自动登录并缓存 Token
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* 关键词屏蔽 */}
|
||||||
|
<div>
|
||||||
|
<label className='block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2'>
|
||||||
|
关键词屏蔽(可选)
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type='text'
|
||||||
|
placeholder='多个关键词用中文或英文逗号分隔'
|
||||||
|
value={siteSettings.PansouKeywordBlocklist}
|
||||||
|
onChange={(e) =>
|
||||||
|
setSiteSettings((prev) => ({
|
||||||
|
...prev,
|
||||||
|
PansouKeywordBlocklist: e.target.value,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
className='w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 focus:ring-2 focus:ring-green-500 focus:border-transparent'
|
||||||
|
/>
|
||||||
|
<p className='mt-1 text-xs text-gray-500 dark:text-gray-400'>
|
||||||
|
设置后会过滤包含这些关键词的搜索结果
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* 评论功能配置 */}
|
{/* 评论功能配置 */}
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ export async function POST(request: NextRequest) {
|
|||||||
PansouApiUrl,
|
PansouApiUrl,
|
||||||
PansouUsername,
|
PansouUsername,
|
||||||
PansouPassword,
|
PansouPassword,
|
||||||
|
PansouKeywordBlocklist,
|
||||||
EnableComments,
|
EnableComments,
|
||||||
CustomAdFilterCode,
|
CustomAdFilterCode,
|
||||||
CustomAdFilterVersion,
|
CustomAdFilterVersion,
|
||||||
@@ -89,6 +90,7 @@ export async function POST(request: NextRequest) {
|
|||||||
PansouApiUrl?: string;
|
PansouApiUrl?: string;
|
||||||
PansouUsername?: string;
|
PansouUsername?: string;
|
||||||
PansouPassword?: string;
|
PansouPassword?: string;
|
||||||
|
PansouKeywordBlocklist?: string;
|
||||||
EnableComments: boolean;
|
EnableComments: boolean;
|
||||||
CustomAdFilterCode?: string;
|
CustomAdFilterCode?: string;
|
||||||
CustomAdFilterVersion?: number;
|
CustomAdFilterVersion?: number;
|
||||||
@@ -129,6 +131,7 @@ export async function POST(request: NextRequest) {
|
|||||||
(TMDBReverseProxy !== undefined && typeof TMDBReverseProxy !== 'string') ||
|
(TMDBReverseProxy !== undefined && typeof TMDBReverseProxy !== 'string') ||
|
||||||
(BannerDataSource !== undefined && typeof BannerDataSource !== 'string') ||
|
(BannerDataSource !== undefined && typeof BannerDataSource !== 'string') ||
|
||||||
(RecommendationDataSource !== undefined && typeof RecommendationDataSource !== 'string') ||
|
(RecommendationDataSource !== undefined && typeof RecommendationDataSource !== 'string') ||
|
||||||
|
(PansouKeywordBlocklist !== undefined && typeof PansouKeywordBlocklist !== 'string') ||
|
||||||
typeof EnableComments !== 'boolean' ||
|
typeof EnableComments !== 'boolean' ||
|
||||||
(CustomAdFilterCode !== undefined && typeof CustomAdFilterCode !== 'string') ||
|
(CustomAdFilterCode !== undefined && typeof CustomAdFilterCode !== 'string') ||
|
||||||
(CustomAdFilterVersion !== undefined && typeof CustomAdFilterVersion !== 'number') ||
|
(CustomAdFilterVersion !== undefined && typeof CustomAdFilterVersion !== 'number') ||
|
||||||
@@ -184,6 +187,7 @@ export async function POST(request: NextRequest) {
|
|||||||
PansouApiUrl,
|
PansouApiUrl,
|
||||||
PansouUsername,
|
PansouUsername,
|
||||||
PansouPassword,
|
PansouPassword,
|
||||||
|
PansouKeywordBlocklist,
|
||||||
EnableComments,
|
EnableComments,
|
||||||
CustomAdFilterCode,
|
CustomAdFilterCode,
|
||||||
CustomAdFilterVersion,
|
CustomAdFilterVersion,
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
import { NextRequest, NextResponse } from 'next/server';
|
import { NextRequest, NextResponse } from 'next/server';
|
||||||
|
|
||||||
import { getConfig } from '@/lib/config';
|
import { getConfig } from '@/lib/config';
|
||||||
import { searchPansou } from '@/lib/pansou.client';
|
import { PansouLink, searchPansou } from '@/lib/pansou.client';
|
||||||
|
|
||||||
export const runtime = 'nodejs';
|
export const runtime = 'nodejs';
|
||||||
|
|
||||||
@@ -44,13 +44,50 @@ export async function POST(request: NextRequest) {
|
|||||||
password,
|
password,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const rawBlocklist = config.SiteConfig.PansouKeywordBlocklist || '';
|
||||||
|
const normalizedBlocklist = rawBlocklist.replace(/,/g, ',');
|
||||||
|
const blockedKeywords = normalizedBlocklist
|
||||||
|
.split(',')
|
||||||
|
.map((item) => item.trim())
|
||||||
|
.filter(Boolean);
|
||||||
|
|
||||||
|
let filteredResults = results;
|
||||||
|
|
||||||
|
if (blockedKeywords.length > 0 && results.merged_by_type) {
|
||||||
|
const mergedByType: Record<string, PansouLink[]> = {};
|
||||||
|
let total = 0;
|
||||||
|
|
||||||
|
const shouldBlock = (link: PansouLink) => {
|
||||||
|
const content = `${link.note || ''} ${link.url || ''} ${link.source || ''}`.toLowerCase();
|
||||||
|
return blockedKeywords.some((item) =>
|
||||||
|
content.includes(item.toLowerCase())
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
Object.entries(results.merged_by_type).forEach(([type, links]) => {
|
||||||
|
const filteredLinks = links.filter((link) => !shouldBlock(link));
|
||||||
|
if (filteredLinks.length > 0) {
|
||||||
|
mergedByType[type] = filteredLinks;
|
||||||
|
total += filteredLinks.length;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
filteredResults = {
|
||||||
|
...results,
|
||||||
|
merged_by_type: mergedByType,
|
||||||
|
total,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
console.log('Pansou 搜索结果:', {
|
console.log('Pansou 搜索结果:', {
|
||||||
total: results.total,
|
total: filteredResults.total,
|
||||||
hasData: !!results.merged_by_type,
|
hasData: !!filteredResults.merged_by_type,
|
||||||
types: results.merged_by_type ? Object.keys(results.merged_by_type) : [],
|
types: filteredResults.merged_by_type
|
||||||
|
? Object.keys(filteredResults.merged_by_type)
|
||||||
|
: [],
|
||||||
});
|
});
|
||||||
|
|
||||||
return NextResponse.json(results);
|
return NextResponse.json(filteredResults);
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error('Pansou 搜索失败:', error);
|
console.error('Pansou 搜索失败:', error);
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ export interface AdminConfig {
|
|||||||
PansouApiUrl?: string;
|
PansouApiUrl?: string;
|
||||||
PansouUsername?: string;
|
PansouUsername?: string;
|
||||||
PansouPassword?: string;
|
PansouPassword?: string;
|
||||||
|
PansouKeywordBlocklist?: string;
|
||||||
// 评论功能开关
|
// 评论功能开关
|
||||||
EnableComments: boolean;
|
EnableComments: boolean;
|
||||||
// 自定义去广告代码
|
// 自定义去广告代码
|
||||||
|
|||||||
+13
-1
@@ -251,6 +251,11 @@ async function getInitConfig(configFile: string, subConfig: {
|
|||||||
TMDBApiKey: process.env.TMDB_API_KEY || '',
|
TMDBApiKey: process.env.TMDB_API_KEY || '',
|
||||||
TMDBProxy: process.env.TMDB_PROXY || '',
|
TMDBProxy: process.env.TMDB_PROXY || '',
|
||||||
TMDBReverseProxy: process.env.TMDB_REVERSE_PROXY || '',
|
TMDBReverseProxy: process.env.TMDB_REVERSE_PROXY || '',
|
||||||
|
// Pansou配置
|
||||||
|
PansouApiUrl: '',
|
||||||
|
PansouUsername: '',
|
||||||
|
PansouPassword: '',
|
||||||
|
PansouKeywordBlocklist: '',
|
||||||
// 评论功能开关
|
// 评论功能开关
|
||||||
EnableComments: false,
|
EnableComments: false,
|
||||||
},
|
},
|
||||||
@@ -446,6 +451,10 @@ export function configSelfCheck(adminConfig: AdminConfig): AdminConfig {
|
|||||||
FluidSearch: true,
|
FluidSearch: true,
|
||||||
DanmakuApiBase: 'http://localhost:9321',
|
DanmakuApiBase: 'http://localhost:9321',
|
||||||
DanmakuApiToken: '87654321',
|
DanmakuApiToken: '87654321',
|
||||||
|
PansouApiUrl: '',
|
||||||
|
PansouUsername: '',
|
||||||
|
PansouPassword: '',
|
||||||
|
PansouKeywordBlocklist: '',
|
||||||
EnableComments: false,
|
EnableComments: false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -460,6 +469,9 @@ export function configSelfCheck(adminConfig: AdminConfig): AdminConfig {
|
|||||||
if (adminConfig.SiteConfig.EnableComments === undefined) {
|
if (adminConfig.SiteConfig.EnableComments === undefined) {
|
||||||
adminConfig.SiteConfig.EnableComments = false;
|
adminConfig.SiteConfig.EnableComments = false;
|
||||||
}
|
}
|
||||||
|
if (adminConfig.SiteConfig.PansouKeywordBlocklist === undefined) {
|
||||||
|
adminConfig.SiteConfig.PansouKeywordBlocklist = '';
|
||||||
|
}
|
||||||
if (!adminConfig.UserConfig) {
|
if (!adminConfig.UserConfig) {
|
||||||
adminConfig.UserConfig = { Users: [] };
|
adminConfig.UserConfig = { Users: [] };
|
||||||
}
|
}
|
||||||
@@ -665,4 +677,4 @@ export async function setCachedConfig(config: AdminConfig) {
|
|||||||
export async function clearConfigCache() {
|
export async function clearConfigCache() {
|
||||||
cachedConfig = null as any;
|
cachedConfig = null as any;
|
||||||
configInitPromise = null;
|
configInitPromise = null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user