mirror of
https://github.com/Moe-Sakura/frontend.git
synced 2026-05-09 00:34:20 +08:00
Update fetchVndbQuotes to increase results limit and refactor translation logic in VndbPanel for improved API handling
- Increased the number of results returned by fetchVndbQuotes from 10 to 25 for better data retrieval. - Refactored translation logic in VndbPanel.vue to execute tasks sequentially, preventing API rate limiting and ensuring accurate game ID checks during translations.
This commit is contained in:
@@ -600,7 +600,7 @@ export async function fetchVndbQuotes(vnId: string): Promise<VndbQuote[]> {
|
||||
body: JSON.stringify({
|
||||
filters: ['vn', '=', ['id', '=', vnId]],
|
||||
fields: 'id, quote, character{id, name, original}',
|
||||
results: 10,
|
||||
results: 25,
|
||||
}),
|
||||
})
|
||||
|
||||
|
||||
@@ -839,26 +839,26 @@ async function translateAllInternal(silent = false) {
|
||||
|
||||
const vnIdAtStart = currentVnId.value
|
||||
|
||||
// 并行执行所有翻译任务
|
||||
const tasks: Promise<void>[] = []
|
||||
|
||||
// 串行执行翻译任务,避免 API 限流
|
||||
// 翻译简介
|
||||
if (searchStore.vndbInfo?.description && !translatedDescription.value) {
|
||||
tasks.push(translateDescriptionInternal(vnIdAtStart, silent))
|
||||
await translateDescriptionInternal(vnIdAtStart, silent)
|
||||
// 检查游戏是否已切换
|
||||
if (currentVnId.value !== vnIdAtStart) { return }
|
||||
}
|
||||
|
||||
// 翻译标签
|
||||
if (searchStore.vndbInfo?.tags && searchStore.vndbInfo.tags.length > 0 && translatedTags.value.size === 0) {
|
||||
tasks.push(translateTagsInternal(vnIdAtStart, silent))
|
||||
await translateTagsInternal(vnIdAtStart, silent)
|
||||
// 检查游戏是否已切换
|
||||
if (currentVnId.value !== vnIdAtStart) { return }
|
||||
}
|
||||
|
||||
// 翻译名言
|
||||
if (quotes.value.length > 0 && translatedQuotes.value.size === 0) {
|
||||
tasks.push(translateQuotesInternal(vnIdAtStart, silent))
|
||||
await translateQuotesInternal(vnIdAtStart, silent)
|
||||
}
|
||||
|
||||
await Promise.all(tasks)
|
||||
|
||||
// 如果有任何翻译成功且是当前游戏,播放成功音效
|
||||
if (!silent && currentVnId.value === vnIdAtStart) {
|
||||
if (translatedDescription.value || translatedTags.value.size > 0 || translatedQuotes.value.size > 0) {
|
||||
|
||||
Reference in New Issue
Block a user