From 605b2697d1fc6679ce651e9e2c8e26b6d780fea3 Mon Sep 17 00:00:00 2001 From: posimai Date: Sun, 22 Mar 2026 17:06:22 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20personalized=20feed=20=E2=80=94=20fetch?= =?UTF-8?q?=20/feed/media=20when=20API=20key=20is=20set?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If API key present, GET /feed/media from Brain API to collect user's custom sources, then POST to Feed API with customFeeds array. Falls back to default GET if no key or fetch fails. Co-Authored-By: Claude Sonnet 4.6 --- index.html | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index e70752c..ac33af0 100644 --- a/index.html +++ b/index.html @@ -950,7 +950,38 @@ async function loadFeed() { document.getElementById('briefList').innerHTML = ''; try { - const res = await fetch(FEED_API, { cache: 'no-store' }); + const apiKey = localStorage.getItem('posimai-brief-apikey'); + let res; + if (apiKey) { + let customFeeds = []; + try { + const mediaRes = await fetch(API_BASE + '/feed/media', { + headers: { 'Authorization': `Bearer ${apiKey}` } + }); + if (mediaRes.ok) { + const medias = await mediaRes.json(); + customFeeds = medias + .filter(m => m.is_active !== false) + .map(m => ({ + id: `db-${m.id}`, + name: m.name, + url: m.feed_url, + siteUrl: m.site_url, + category: m.category || 'tech', + icon: 'rss', + dbId: m.id, + })); + } + } catch (_) { /* カスタムソース取得失敗 → デフォルトのみで続行 */ } + res = await fetch(FEED_API, { + method: 'POST', + cache: 'no-store', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ customFeeds }), + }); + } else { + res = await fetch(FEED_API, { cache: 'no-store' }); + } if (!res.ok) throw new Error(`Feed ${res.status}`); const data = await res.json(); const list = (data.articles || []).slice(0, 8);