web: basic api interaction & downloading

download button now acts the way it should with various states
This commit is contained in:
wukko
2024-06-16 18:22:44 +06:00
parent 324729eb21
commit 1f2c28bd02
4 changed files with 104 additions and 5 deletions

31
web/src/lib/api.ts Normal file
View File

@@ -0,0 +1,31 @@
const apiURL = "https://api.cobalt.tools";
const request = async (url: string) => {
const request = {
url
}
const response = await fetch(`${apiURL}/api/json`, {
method: "POST",
body: JSON.stringify(request),
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
}).then(r => r.json()).catch(() => {});
return response;
}
const probeCobaltStream = async (url: string) => {
const request = await fetch(`${url}&p=1`).catch(() => {});
if (request?.status === 200) {
return request?.status;
}
return 0;
}
export default {
request,
probeCobaltStream,
}