File size: 1,617 Bytes
8d3471e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | export async function parseJSONResponse(res, t) {
const contentType = String(res.headers.get('content-type') || '').toLowerCase()
if (!contentType.includes('application/json')) {
throw new Error(t('settings.nonJsonResponse', { status: res.status }))
}
return res.json()
}
export async function fetchSettings(apiFetch, t) {
const res = await apiFetch('/admin/settings')
const data = await parseJSONResponse(res, t)
return { res, data }
}
export async function putSettings(apiFetch, payload) {
const res = await apiFetch('/admin/settings', {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload),
})
const data = await res.json()
return { res, data }
}
export async function postPassword(apiFetch, newPassword) {
const res = await apiFetch('/admin/settings/password', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ new_password: newPassword }),
})
const data = await res.json()
return { res, data }
}
export async function getExportData(apiFetch) {
const res = await apiFetch('/admin/config/export')
const data = await res.json()
return { res, data }
}
export async function postImportData(apiFetch, mode, config) {
const res = await apiFetch(`/admin/config/import?mode=${encodeURIComponent(mode)}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ config, mode }),
})
const data = await res.json()
return { res, data }
}
|