Files
memind_adm/server/news-engine-admin.mjs
T
john 9ec4dda6af feat(admin): add News Engine console and image-make config API
Expose memind-news-engine health, collect, rank, and scheduler controls in md.tkmind.cn admin, proxied via MEMIND_NEWS_ENGINE_URL.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-22 14:36:38 +08:00

35 lines
1.2 KiB
JavaScript

export function resolveNewsEngineBaseUrl(env = process.env) {
return String(env.MEMIND_NEWS_ENGINE_URL ?? 'http://127.0.0.1:8092').trim().replace(/\/+$/, '');
}
export async function fetchNewsEngine(path, {
env = process.env,
method = 'GET',
body = null,
fetchImpl = fetch,
} = {}) {
const baseUrl = resolveNewsEngineBaseUrl(env);
if (!baseUrl) {
return { ok: false, status: 503, data: { message: '未配置 MEMIND_NEWS_ENGINE_URL' } };
}
const token = String(env.MEMIND_NEWS_ENGINE_API_TOKEN ?? '').trim();
const response = await fetchImpl(`${baseUrl}${path}`, {
method,
headers: {
accept: 'application/json',
...(body ? { 'content-type': 'application/json' } : {}),
...(token ? { authorization: `Bearer ${token}` } : {}),
},
body: body ? JSON.stringify(body) : undefined,
signal: AbortSignal.timeout(Number(env.MEMIND_NEWS_ENGINE_TIMEOUT_MS ?? 120000) || 120000),
});
const text = await response.text().catch(() => '');
let data = null;
try {
data = text ? JSON.parse(text) : null;
} catch {
data = { message: text.slice(0, 500) || `HTTP ${response.status}` };
}
return { ok: response.ok, status: response.status, data };
}