fix: add auth token to all API calls (prompts, insights, pipeline)
This commit is contained in:
parent
89b6c0b072
commit
5091dfd1ce
|
|
@ -117,7 +117,7 @@ export default function Analysis() {
|
||||||
|
|
||||||
const loadAll = async () => {
|
const loadAll = async () => {
|
||||||
const [p, i] = await Promise.all([
|
const [p, i] = await Promise.all([
|
||||||
fetch('/api/prompts').then(r=>r.json()),
|
api.listPrompts(),
|
||||||
api.listInsights()
|
api.listInsights()
|
||||||
])
|
])
|
||||||
setPrompts(Array.isArray(p)?p:[])
|
setPrompts(Array.isArray(p)?p:[])
|
||||||
|
|
@ -128,12 +128,7 @@ export default function Analysis() {
|
||||||
const runPipeline = async () => {
|
const runPipeline = async () => {
|
||||||
setPipelineLoading(true); setError(null); setNewResult(null)
|
setPipelineLoading(true); setError(null); setNewResult(null)
|
||||||
try {
|
try {
|
||||||
const pid = localStorage.getItem('bodytrack_active_profile')||''
|
const result = await api.insightPipeline()
|
||||||
const r = await fetch('/api/insights/pipeline', {
|
|
||||||
method:'POST', headers: pid ? {'X-Profile-Id':pid} : {}
|
|
||||||
})
|
|
||||||
if (!r.ok) throw new Error(await r.text())
|
|
||||||
const result = await r.json()
|
|
||||||
setNewResult(result)
|
setNewResult(result)
|
||||||
await loadAll()
|
await loadAll()
|
||||||
setTab('run')
|
setTab('run')
|
||||||
|
|
@ -145,12 +140,7 @@ export default function Analysis() {
|
||||||
const runPrompt = async (slug) => {
|
const runPrompt = async (slug) => {
|
||||||
setLoading(slug); setError(null); setNewResult(null)
|
setLoading(slug); setError(null); setNewResult(null)
|
||||||
try {
|
try {
|
||||||
const pid = localStorage.getItem('bodytrack_active_profile')||''
|
const result = await api.runInsight(slug)
|
||||||
const r = await fetch(`/api/insights/run/${slug}`, {
|
|
||||||
method:'POST', headers: pid ? {'X-Profile-Id':pid} : {}
|
|
||||||
})
|
|
||||||
if (!r.ok) throw new Error(await r.text())
|
|
||||||
const result = await r.json()
|
|
||||||
setNewResult(result) // show immediately
|
setNewResult(result) // show immediately
|
||||||
await loadAll() // refresh lists
|
await loadAll() // refresh lists
|
||||||
setTab('run') // stay on run tab to see result
|
setTab('run') // stay on run tab to see result
|
||||||
|
|
|
||||||
|
|
@ -208,10 +208,7 @@ export default function Dashboard() {
|
||||||
setPipelineLoading(true); setPipelineError(null)
|
setPipelineLoading(true); setPipelineError(null)
|
||||||
try {
|
try {
|
||||||
const pid = localStorage.getItem('mitai-jinkendo_active_profile')||''
|
const pid = localStorage.getItem('mitai-jinkendo_active_profile')||''
|
||||||
const r = await fetch('/api/insights/pipeline', {
|
await api.insightPipeline()
|
||||||
method:'POST', headers: pid ? {'X-Profile-Id':pid} : {}
|
|
||||||
})
|
|
||||||
if (!r.ok) throw new Error(await r.text())
|
|
||||||
await load()
|
await load()
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
setPipelineError('Fehler: '+e.message)
|
setPipelineError('Fehler: '+e.message)
|
||||||
|
|
|
||||||
|
|
@ -924,7 +924,7 @@ export default function History() {
|
||||||
setLoadingSlug(slug)
|
setLoadingSlug(slug)
|
||||||
try {
|
try {
|
||||||
const pid=localStorage.getItem('bodytrack_active_profile')||''
|
const pid=localStorage.getItem('bodytrack_active_profile')||''
|
||||||
const r=await fetch(`/api/insights/run/${slug}`,{method:'POST',headers:pid?{'X-Profile-Id':pid}:{}})
|
const r=await api.runInsight(slug)
|
||||||
if(!r.ok) throw new Error(await r.text())
|
if(!r.ok) throw new Error(await r.text())
|
||||||
const ins=await api.latestInsights()
|
const ins=await api.latestInsights()
|
||||||
setInsights(Array.isArray(ins)?ins:[])
|
setInsights(Array.isArray(ins)?ins:[])
|
||||||
|
|
|
||||||
|
|
@ -335,7 +335,7 @@ export default function NutritionPage() {
|
||||||
const [corr, wkly, prof] = await Promise.all([
|
const [corr, wkly, prof] = await Promise.all([
|
||||||
nutritionApi.nutritionCorrelations(),
|
nutritionApi.nutritionCorrelations(),
|
||||||
nutritionApi.nutritionWeekly(16),
|
nutritionApi.nutritionWeekly(16),
|
||||||
fetch('/api/profile').then(r=>r.json()),
|
api.getActiveProfile(),
|
||||||
])
|
])
|
||||||
setCorr(Array.isArray(corr)?corr:[])
|
setCorr(Array.isArray(corr)?corr:[])
|
||||||
setWeekly(Array.isArray(wkly)?wkly:[])
|
setWeekly(Array.isArray(wkly)?wkly:[])
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ const jput=(d)=>({method:'PUT', headers:{'Content-Type':'application/json'},body
|
||||||
|
|
||||||
export const api = {
|
export const api = {
|
||||||
// Profiles
|
// Profiles
|
||||||
|
getActiveProfile: () => req('/profile'),
|
||||||
listProfiles: () => req('/profiles'),
|
listProfiles: () => req('/profiles'),
|
||||||
createProfile: (d) => req('/profiles', json(d)),
|
createProfile: (d) => req('/profiles', json(d)),
|
||||||
updateProfile: (id,d) => req(`/profiles/${id}`, jput(d)),
|
updateProfile: (id,d) => req(`/profiles/${id}`, jput(d)),
|
||||||
|
|
@ -82,6 +83,8 @@ export const api = {
|
||||||
// Stats & AI
|
// Stats & AI
|
||||||
getStats: () => req('/stats'),
|
getStats: () => req('/stats'),
|
||||||
insightTrend: () => req('/insights/trend',{method:'POST'}),
|
insightTrend: () => req('/insights/trend',{method:'POST'}),
|
||||||
|
listPrompts: () => req('/prompts'),
|
||||||
|
runInsight: (slug) => req(`/insights/run/${slug}`,{method:'POST'}),
|
||||||
insightPipeline: () => req('/insights/pipeline',{method:'POST'}),
|
insightPipeline: () => req('/insights/pipeline',{method:'POST'}),
|
||||||
listInsights: () => req('/insights'),
|
listInsights: () => req('/insights'),
|
||||||
latestInsights: () => req('/insights/latest'),
|
latestInsights: () => req('/insights/latest'),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user