mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-02-04 06:31:13 +00:00
fix: #1575
This commit is contained in:
parent
7c65b1eaf1
commit
cc8891b6a1
@ -34,12 +34,12 @@ const CACHE_TTL = 10 * 60 * 1000; // 10分钟缓存
|
||||
|
||||
/**
|
||||
* 从多个源获取插件列表,使用镜像系统
|
||||
* 带10分钟缓存
|
||||
* 带10分钟缓存,支持强制刷新
|
||||
*/
|
||||
async function fetchPluginList (): Promise<PluginStoreList> {
|
||||
// 检查缓存
|
||||
async function fetchPluginList (forceRefresh: boolean = false): Promise<PluginStoreList> {
|
||||
// 检查缓存(如果不是强制刷新)
|
||||
const now = Date.now();
|
||||
if (pluginListCache && (now - cacheTimestamp) < CACHE_TTL) {
|
||||
if (!forceRefresh && pluginListCache && (now - cacheTimestamp) < CACHE_TTL) {
|
||||
//console.log('Using cached plugin list');
|
||||
return pluginListCache;
|
||||
}
|
||||
@ -192,9 +192,11 @@ async function extractPlugin (zipPath: string, pluginId: string): Promise<void>
|
||||
/**
|
||||
* 获取插件商店列表
|
||||
*/
|
||||
export const GetPluginStoreListHandler: RequestHandler = async (_req, res) => {
|
||||
export const GetPluginStoreListHandler: RequestHandler = async (req, res) => {
|
||||
try {
|
||||
const data = await fetchPluginList();
|
||||
// 支持 forceRefresh 查询参数强制刷新缓存
|
||||
const forceRefresh = req.query['forceRefresh'] === 'true';
|
||||
const data = await fetchPluginList(forceRefresh);
|
||||
return sendSuccess(res, data);
|
||||
} catch (e: any) {
|
||||
return sendError(res, 'Failed to fetch plugin store list: ' + e.message);
|
||||
|
||||
@ -140,9 +140,11 @@ export default class PluginManager {
|
||||
|
||||
/**
|
||||
* 获取插件商店列表
|
||||
* @param forceRefresh 是否强制刷新(跳过服务端缓存)
|
||||
*/
|
||||
public static async getPluginStoreList (): Promise<PluginStoreList> {
|
||||
const { data } = await serverRequest.get<ServerResponse<PluginStoreList>>('/Plugin/Store/List');
|
||||
public static async getPluginStoreList (forceRefresh: boolean = false): Promise<PluginStoreList> {
|
||||
const params = forceRefresh ? { forceRefresh: 'true' } : {};
|
||||
const { data } = await serverRequest.get<ServerResponse<PluginStoreList>>('/Plugin/Store/List', { params });
|
||||
return data.data;
|
||||
}
|
||||
|
||||
|
||||
@ -51,10 +51,10 @@ export default function PluginStorePage () {
|
||||
const [pendingInstallPlugin, setPendingInstallPlugin] = useState<PluginStoreItem | null>(null);
|
||||
const [selectedDownloadMirror, setSelectedDownloadMirror] = useState<string | undefined>(undefined);
|
||||
|
||||
const loadPlugins = async () => {
|
||||
const loadPlugins = async (forceRefresh: boolean = false) => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const data = await PluginManager.getPluginStoreList();
|
||||
const data = await PluginManager.getPluginStoreList(forceRefresh);
|
||||
setPlugins(data.plugins);
|
||||
|
||||
// 检查插件管理器是否已加载
|
||||
@ -238,7 +238,7 @@ export default function PluginStorePage () {
|
||||
isIconOnly
|
||||
className="bg-default-100/50 hover:bg-default-200/50 text-default-700 backdrop-blur-md"
|
||||
radius="full"
|
||||
onPress={loadPlugins}
|
||||
onPress={() => loadPlugins(true)}
|
||||
isLoading={loading}
|
||||
>
|
||||
<IoMdRefresh size={24} />
|
||||
|
||||
Loading…
Reference in New Issue
Block a user