MCPcopy Create free account
hub / github.com/error311/FileRise / runSourceTest

Function runSourceTest

public/js/adminPanel.js:2289–2346  ·  view source on GitHub ↗
(src)

Source from the content-addressed store, hash-verified

2287 };
2288
2289 const runSourceTest = async (src) => {
2290 const id = String(src.id || '');
2291 if (!id) return null;
2292 const current = getTestStatus(id);
2293 if (current.state === 'testing') {
2294 return null;
2295 }
2296 setTestStatus(id, { state: 'testing', message: '', checks: [], capabilities: {}, limited: false });
2297 const controller = new AbortController();
2298 const timer = setTimeout(() => controller.abort(), 25000);
2299 try {
2300 const res = await fetch(withBase('/api/pro/sources/test.php'), {
2301 method: 'POST',
2302 credentials: 'include',
2303 headers: {
2304 'Content-Type': 'application/json',
2305 'X-CSRF-Token': getCsrf(),
2306 'Accept': 'application/json',
2307 },
2308 body: JSON.stringify({ id }),
2309 signal: controller.signal,
2310 });
2311 const data = await safeJson(res);
2312 const checks = normalizeTestChecks(data && data.checks);
2313 const capabilities = normalizeCapabilities(data && data.capabilities);
2314 const limited = !!(data && data.limited);
2315 if (!data || data.ok !== true) {
2316 const msg = String((data && (data.error || data.message)) || tf('source_test_error', 'Test failed')).trim();
2317 setTestStatus(id, { state: 'error', message: msg, checks, capabilities, limited: false });
2318 showToast(msg, 5000);
2319 return false;
2320 }
2321
2322 const msg = data && data.message ? String(data.message) : '';
2323 setTestStatus(id, {
2324 state: limited ? 'warning' : 'ok',
2325 message: msg,
2326 checks,
2327 capabilities,
2328 limited,
2329 });
2330 if (limited) {
2331 const warn = msg || tf('source_test_limited', 'Connected (limited)');
2332 showToast(warn, 5000);
2333 }
2334 return true;
2335 } catch (err) {
2336 const timedOut = err && err.name === 'AbortError';
2337 const msg = timedOut
2338 ? tf('source_test_timeout', 'Test timed out.')
2339 : (err?.message || tf('source_test_error', 'Test failed'));
2340 setTestStatus(id, { state: 'error', message: msg, checks: [], capabilities: {}, limited: false });
2341 showToast(msg, 5000);
2342 return false;
2343 } finally {
2344 clearTimeout(timer);
2345 }
2346 };

Callers 1

initSourcesSectionFunction · 0.85

Calls 9

getTestStatusFunction · 0.85
setTestStatusFunction · 0.85
withBaseFunction · 0.85
getCsrfFunction · 0.85
normalizeTestChecksFunction · 0.85
normalizeCapabilitiesFunction · 0.85
safeJsonFunction · 0.70
tfFunction · 0.70
showToastFunction · 0.70

Tested by

no test coverage detected