mirror of
https://github.com/Moe-Sakura/frontend.git
synced 2026-04-21 21:50:24 +08:00
feat: 支持VNDB图片代理并优化信息展示
- 引入VNDB图片代理功能,提升图片加载速度。 - 添加代理可用性检测,确保图片服务正常。 - 更新游戏介绍和人物信息来源说明,明确数据由VNDB提供并经AI翻译。 - 优化搜索提交体验,在搜索后自动使输入框失焦。
This commit is contained in:
@@ -431,7 +431,7 @@
|
||||
为了支持各 Galgame
|
||||
站点能长久运营,还请各位把浏览器的<strong>广告屏蔽插件</strong>关掉,或将这些站点加入白名单。大家建站不易,小小的支持也是大大的动力!
|
||||
</li>
|
||||
<li>游戏介绍和人物信息均由AI生成,不保证准确性,仅作为检索游戏时的参考!</span>
|
||||
<li>游戏介绍和人物信息数据由 <a href="https://vndb.org/" target="_blank" class="text-blue-600 hover:underline font-semibold">VNDB</a> 提供,由AI大模型翻译,翻译结果不保证准确性,仅作为检索游戏时的参考!</span>
|
||||
</li>
|
||||
<li>
|
||||
<span class="font-bold text-red-600">郑重呼吁:请务必支持 Galgame 正版!让爱与梦想延续!</span>
|
||||
|
||||
77
src/main.js
77
src/main.js
@@ -10,6 +10,13 @@ const AI_TRANSLATE_API_KEY =
|
||||
"sk-Md5kXePgq6HJjPa1Cf3265511bEe4e4c888232A0837e371e";
|
||||
const AI_TRANSLATE_MODEL = "Qwen/Qwen2.5-32B-Instruct";
|
||||
|
||||
// -- VNDB 图片代理配置 --
|
||||
// 在代理vndb前会先发送请求到VNDB_IMAGE_PROXY_URL, 返回200才会进行代理
|
||||
const ENABLE_VNDB_IMAGE_PROXY = true; // 设置为 true 启用vndb图片代理, false 则不启用
|
||||
const VNDB_IMAGE_PROXY_URL = "https://rpx.searchgal.homes/";
|
||||
|
||||
let isProxyAvailable = false;
|
||||
|
||||
const ITEMS_PER_PAGE = 10;
|
||||
const platformResults = new Map();
|
||||
const SEARCH_COOLDOWN_MS = 30 * 1000; // 30 seconds cooldown
|
||||
@@ -742,6 +749,12 @@ function updateNavigationLayout() {
|
||||
async function handleSearchSubmit(e) {
|
||||
e.preventDefault();
|
||||
|
||||
// 让输入框失焦
|
||||
const searchInput = searchForm.querySelector('input[name="game"]');
|
||||
if (searchInput) {
|
||||
searchInput.blur();
|
||||
}
|
||||
|
||||
if (lockViewBtn) {
|
||||
lockViewBtn.disabled = true; // Disable on new search
|
||||
lockViewBtn.classList.remove("visible");
|
||||
@@ -1873,6 +1886,19 @@ async function fetchVndbData(gameName) {
|
||||
console.log("[DEBUG] Extracted Description:", finalResult.description);
|
||||
console.log("[DEBUG] Final VNDB result object:", finalResult);
|
||||
|
||||
// Recursively replace all vndb URLs if proxy is enabled
|
||||
// Recursively replace all vndb URLs if proxy is enabled and available
|
||||
if (ENABLE_VNDB_IMAGE_PROXY) {
|
||||
await checkProxyAvailability();
|
||||
if (isProxyAvailable) {
|
||||
replaceVndbUrls(finalResult);
|
||||
console.log(
|
||||
"[DEBUG] Final VNDB result object after URL replacement:",
|
||||
finalResult
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return finalResult;
|
||||
} catch (error) {
|
||||
console.error("Failed to fetch or process VNDB data:", error);
|
||||
@@ -1880,6 +1906,57 @@ async function fetchVndbData(gameName) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively traverses an object or array and replaces all instances of
|
||||
* "https://t.vndb.org/" with a proxy URL in string values.
|
||||
* @param {any} obj The object or array to process.
|
||||
*/
|
||||
/**
|
||||
* Checks if the proxy server is available by sending a HEAD request.
|
||||
* Updates the global `isProxyAvailable` state.
|
||||
*/
|
||||
async function checkProxyAvailability() {
|
||||
try {
|
||||
const response = await fetch(VNDB_IMAGE_PROXY_URL, { method: "HEAD" });
|
||||
if (response.ok) {
|
||||
isProxyAvailable = true;
|
||||
console.log("[DEBUG] Proxy server is available.");
|
||||
} else {
|
||||
isProxyAvailable = false;
|
||||
console.warn(
|
||||
`[DEBUG] Proxy server check failed with status: ${response.status}`
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
isProxyAvailable = false;
|
||||
console.error("[DEBUG] Proxy server check failed with error:", error);
|
||||
}
|
||||
}
|
||||
|
||||
function replaceVndbUrls(obj) {
|
||||
if (
|
||||
!ENABLE_VNDB_IMAGE_PROXY ||
|
||||
!isProxyAvailable ||
|
||||
obj === null ||
|
||||
typeof obj !== "object"
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const key in obj) {
|
||||
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
||||
const value = obj[key];
|
||||
if (typeof value === "string") {
|
||||
if (value.startsWith("https://t.vndb.org/")) {
|
||||
obj[key] = VNDB_IMAGE_PROXY_URL + value;
|
||||
}
|
||||
} else if (typeof value === "object") {
|
||||
replaceVndbUrls(value); // Recurse into nested objects/arrays
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the latest commit dates from GitHub repos and displays them as version.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user