mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-07-27 16:49:51 -07:00
fix(anki): harden AnkiConnect requests and yomitan runtime fallback
- add request timeout and HTTP status check to verify-known-word-highlights AnkiConnect client - let yomitan-script-runtime search on its own when the resolved manifest path isn't usable - dedupe repeated tier-query setup in known-word-cache-maturity tests via setTierQueries helper
This commit is contained in:
@@ -224,13 +224,19 @@ function readPersistedCacheScope(cachePath: string): string | null {
|
||||
}
|
||||
}
|
||||
|
||||
const ANKI_REQUEST_TIMEOUT_MS = 30_000;
|
||||
|
||||
function createAnkiClient(url: string) {
|
||||
const request = async (action: string, params: unknown): Promise<unknown> => {
|
||||
const response = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ action, version: 6, params }),
|
||||
signal: AbortSignal.timeout(ANKI_REQUEST_TIMEOUT_MS),
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error(`AnkiConnect ${action}: HTTP ${response.status} ${response.statusText}`);
|
||||
}
|
||||
const payload = (await response.json()) as { result: unknown; error: string | null };
|
||||
if (payload.error) {
|
||||
throw new Error(`AnkiConnect ${action}: ${payload.error}`);
|
||||
|
||||
@@ -152,5 +152,6 @@ export async function createYomitanRuntimeStateWithSearch(
|
||||
}
|
||||
}
|
||||
|
||||
return createYomitanRuntimeState(userDataPath, resolvedExtensionPath ?? undefined);
|
||||
// No usable manifest at the resolved path, so let the loader search on its own.
|
||||
return createYomitanRuntimeState(userDataPath);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user