forked from flow/vue3js-app-proposal-for-sdk-claude
43 lines
1.3 KiB
JavaScript
43 lines
1.3 KiB
JavaScript
function authHeader(credentials) {
|
|
if (!credentials) return {};
|
|
const b64 = btoa(`${credentials.username}:${credentials.password}`);
|
|
return { Authorization: `Basic ${b64}` };
|
|
}
|
|
|
|
export async function fetchAstLog(credentials) {
|
|
const res = await fetch('/sompyle/astlog', {
|
|
headers: authHeader(credentials),
|
|
});
|
|
if (!res.ok) throw new Error(`${res.status} ${res.statusText}`);
|
|
return res.text();
|
|
}
|
|
|
|
export async function fetchScoreText(credentials) {
|
|
const res = await fetch('/sompyle/score.spls', {
|
|
headers: authHeader(credentials),
|
|
});
|
|
if (!res.ok) throw new Error(`${res.status} ${res.statusText}`);
|
|
return res.text();
|
|
}
|
|
|
|
export async function putScoreText(text, credentials) {
|
|
const res = await fetch('/sompyle/score.spls', {
|
|
method: 'PUT',
|
|
headers: {
|
|
...authHeader(credentials),
|
|
'Content-Type': 'text/yaml',
|
|
},
|
|
body: text,
|
|
});
|
|
if (!res.ok) throw new Error(`${res.status} ${res.statusText}`);
|
|
return res;
|
|
}
|
|
|
|
export async function fetchStatus(credentials) {
|
|
const res = await fetch('/sompyle/status.json', {
|
|
headers: authHeader(credentials),
|
|
});
|
|
if (!res.ok) throw new Error(`${res.status} ${res.statusText}`);
|
|
return res.json();
|
|
}
|