Files
DemonGatanjieuandClaude Opus 5.5 142280e4ec Scans ask when Civitai cannot be reached; linked models keep outside info
Before an online scan (the scan page, a card's radar, after a download or
an import), scan_connection.js asks GET /anomalous/civitai_check, which
tries both of Civitai's addresses. When neither answers, a dialog says
why and offers Scan from the files (the offline scan, so nothing waits on
every model), Set a proxy (Settings → Models, Network) or Cancel. A check
that reached Civitai is trusted for five minutes. anomalousConfirm takes
okClass, so this choice is not drawn as a delete.

A model that is a link with no info beside it shows the info beside the
file it links to (metadata._info_base): A1111's Civitai Helper leaves
.civitai.info there. Only read there; covers, edits and scans stay beside
the link.

Checked on the isolated ComfyUI with the check and the scan request
stubbed in the page: the dialog's three choices (from files posts
offline_only, set a proxy opens the Models tab, cancel posts nothing),
an answering Civitai scans online without asking, and a second scan
skips the check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-16 22:21:57 +08:00

43 lines
1.7 KiB
JavaScript

/**
* Before an online scan: can Civitai be reached (GET /anomalous/civitai_check, both its
* addresses)? When not, the user is asked instead of the scan waiting on every model: scan
* from the files only (an offline scan; a later online scan fills in the rest), set a proxy
* first (Settings → Models, Network), or not now. A check that reached Civitai is trusted for
* a few minutes, so scans in a row do not wait on it.
*/
import { translate as t } from './locales.js';
import { failureWords } from './net_failure.js';
import { anomalousConfirm } from './ui_dialog.js';
import { showWorkbenchToast } from './ui_prompt_toast.js';
import { openSettingsPage } from './ui_settings_page.js';
const TRUSTED_MS = 5 * 60 * 1000;
let reachedAt = 0;
/** 'online' (Civitai answers, or this cannot be told), 'offline' (scan from the files), or null (not now). */
export async function onlineOrAsk(owner) {
if (Date.now() - reachedAt < TRUSTED_MS) return 'online';
showWorkbenchToast(t('scanCheckingNet'));
let answer = null;
try {
const res = await fetch('/anomalous/civitai_check');
answer = res.ok ? await res.json() : null;
} catch {
answer = null;
}
if (!answer || answer.reachable) {
if (answer) reachedAt = Date.now();
return 'online';
}
const choice = await anomalousConfirm(t('scanNetDownText', { why: failureWords(answer.failure) }), t('scanNetDownTitle'), {
okLabel: t('scanNetFromFiles'), okClass: 'anomalous-btn-primary', noLabel: t('scanNetSetProxy'),
});
if (choice === true) return 'offline';
if (choice === false) {
owner.show?.();
openSettingsPage(owner, { tab: 'models' });
}
return null;
}