fix: BLS-Import-UI und Timeout beim Daten-Apply
Datei-Button volle Breite, Import als Aktionsbutton, Batch-Upsert statt Einzel-INSERTs. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
7ccae33844
commit
8e964509d7
7 files changed
+170
-145
No files matched your search
@@ -73,6 +73,29 @@ async function req(path, opts={}) {
|
||||
}
|
||||
return res.json()
|
||||
}
|
||||
async function readJsonResponse(res) {
|
||||
const text = await res.text()
|
||||
const trimmed = (text || '').trim()
|
||||
if (!trimmed) {
|
||||
throw new Error(res.ok ? 'Leere Antwort' : `HTTP ${res.status}`)
|
||||
}
|
||||
if (trimmed.startsWith('<')) {
|
||||
throw new Error(
|
||||
`Server lieferte HTML statt JSON (HTTP ${res.status}). Meist Timeout oder Datei zu groß — erneut versuchen.`
|
||||
)
|
||||
}
|
||||
let parsed
|
||||
try {
|
||||
parsed = JSON.parse(trimmed)
|
||||
} catch {
|
||||
throw new Error(trimmed.slice(0, 180) || `HTTP ${res.status}`)
|
||||
}
|
||||
if (!res.ok) {
|
||||
throw new Error(formatFastApiDetail(parsed.detail, JSON.stringify(parsed)))
|
||||
}
|
||||
return parsed
|
||||
}
|
||||
|
||||
const json=(d)=>({method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify(d)})
|
||||
const jput=(d)=>({method:'PUT', headers:{'Content-Type':'application/json'},body:JSON.stringify(d)})
|
||||
|
||||
@@ -231,12 +254,12 @@ export const api = {
|
||||
adminBlsImportComponents: async (file, dryRun=true) => {
|
||||
const fd=new FormData();fd.append('file',file)
|
||||
const r=await fetch(`${BASE}/admin/bls/import/components?dry_run=${dryRun}`,{method:'POST',body:fd,headers:hdrs()})
|
||||
const d=await r.json();if(!r.ok)throw new Error(formatFastApiDetail(d.detail, JSON.stringify(d)));return d
|
||||
return readJsonResponse(r)
|
||||
},
|
||||
adminBlsImportFoods: async (file, dryRun=true) => {
|
||||
const fd=new FormData();fd.append('file',file)
|
||||
const r=await fetch(`${BASE}/admin/bls/import/foods?dry_run=${dryRun}`,{method:'POST',body:fd,headers:hdrs()})
|
||||
const d=await r.json();if(!r.ok)throw new Error(formatFastApiDetail(d.detail, JSON.stringify(d)));return d
|
||||
return readJsonResponse(r)
|
||||
},
|
||||
adminBlsFoods: (q, kind) => req(`/admin/bls/foods?${q?('q='+encodeURIComponent(q)+'&'):''}${kind?('kind='+kind):''}`),
|
||||
adminBlsFoodDetail: (id) => req(`/admin/bls/foods/${id}`),
|
||||
|
||||
Reference in new issue
Block a user