From 88aa0325e91b805a928e22e949869f55783fda34 Mon Sep 17 00:00:00 2001 From: DanielTQuach Date: Fri, 13 Jun 2025 15:27:23 -0700 Subject: [PATCH] remove axios --- src/APIFunctions/Speaker.js | 224 +++++++++++++++++++++--------------- 1 file changed, 129 insertions(+), 95 deletions(-) diff --git a/src/APIFunctions/Speaker.js b/src/APIFunctions/Speaker.js index e579caaac..a654022b9 100644 --- a/src/APIFunctions/Speaker.js +++ b/src/APIFunctions/Speaker.js @@ -1,4 +1,3 @@ -import axios from 'axios'; import { ApiResponse } from './ApiResponses'; import { BASE_API_URL } from '../Enums'; @@ -6,162 +5,197 @@ import { BASE_API_URL } from '../Enums'; export async function queued(token) { let status = new ApiResponse(); const url = new URL('/api/Speaker/queued', BASE_API_URL); - await axios - .get(url.href, { + try { + const res = await fetch(url.href, { + method: 'GET', headers: { - 'Authorization': `Bearer ${token}` + 'Content-Type': 'application/json', + Authorization: `Bearer ${token}`, } - } - ) - .then(res => { - status.responseData = res.data.queue; - }) - .catch(err => { - status.responseData = err; - status.error = true; }); + if (res.ok) { + const result = await res.json(); + status.responseData = result; + } else { + status.error = true; + } + } catch(err) { + status.error = true; + status.responseData = error; + } return status; } export async function addUrl(urlToAdd, token) { let status = new ApiResponse(); const url = new URL('/api/Speaker/stream', BASE_API_URL); - await axios - .post(url.href, { - url: urlToAdd - }, { + try { + const res = await fetch(url.href, { + method: 'POST', headers: { - 'Authorization': `Bearer ${token}` - } - } - ) - .then(res => { - status = res.data; - }) - .catch(err => { - status.responseData = err; - status.error = true; + 'Content-Type': 'application/json', + Authorization: `Bearer ${token}`, + }, + body: JSON.stringify({ + url: urlToAdd + }) }); + if (res.ok) { + const result = await res.json(); + status.responseData = result; + } else { + status.error = true; + } + } catch(err) { + status.error = true; + status.responseData = error; + } return status; } export async function skip(token) { let status = new ApiResponse(); const url = new URL('/api/Speaker/skip', BASE_API_URL); - await axios - .post(url.href, {}, { + try { + const res = await fetch(url.href, { + method: 'POST', headers: { - 'Authorization': `Bearer ${token}` + 'Content-Type': 'application/json', + Authorization: `Bearer ${token}`, } - } - ) - .then(res => { - status = res.data; - }) - .catch(err => { - status.responseData = err; - status.error = true; }); + if (res.ok) { + const result = await res.json(); + status.responseData = result; + } else { + status.error = true; + } + } catch(err) { + status.error = true; + status.responseData = error; + } return status; } export async function pause(token) { let status = new ApiResponse(); const url = new URL('/api/Speaker/pause', BASE_API_URL); - await axios - .post(url.href, {}, { + try { + const res = await fetch(url.rhef, { + method: 'POST', headers: { - 'Authorization': `Bearer ${token}` + 'Content-Type': 'application/json', + Authorization: `Bearer ${token}`, } - } - ) - .then(res => { - status = res.data; - }) - .catch(err => { - status.responseData = err; - status.error = true; }); + if (res.ok) { + const result = await res.json(); + status.responseData = result; + } else { + status.error = true; + } + } catch(err) { + status.error = true; + status.responseData = error; + } return status; } export async function resume(token) { let status = new ApiResponse(); const url = new URL('/api/Speaker/resume', BASE_API_URL); - await axios - .post(url.href, {}, { + try { + const res = await fetch(url.href, { + method: 'POST', headers: { - 'Authorization': `Bearer ${token}` + 'Content-Type': 'application/json', + Authorization: `Bearer ${token}`, } - } - ) - .then(res => { - status = res.data; - }) - .catch(err => { - status.responseData = err; - status.error = true; }); + if (res.ok) { + const result = await res.json(); + status.responseData = result; + } else { + status.error = true; + } + } catch (err) { + status.error = true; + status.responseData = error; + } return status; } export async function setVolume(volumeToSet, token) { let status = new ApiResponse(); const url = new URL('/api/Speaker/volume', BASE_API_URL); - await axios - .post(url.href, { - volume: volumeToSet - }, { + try { + const res = await fetch(url.href, { + method: 'POST', headers: { - 'Authorization': `Bearer ${token}` - } - } - ) - .then(res => { - status = res.data; - }) - .catch(err => { - status.responseData = err; - status.error = true; + 'Content-Type': 'application/json', + Authorization: `Bearer ${token}`, + }, + body: JSON.stringify({ + volume: volumeToSet + }) }); + if (res.ok) { + const result = await res.json(); + status.responseData = result; + } else { + status.error = true; + } + } catch(err) { + status.error = true; + status.responseData = error; + } + return status; } export async function rewind(token) { let status = new ApiResponse(); const url = new URL('/api/Speaker/rewind', BASE_API_URL); - await axios - .post(url.href, {}, { + try { + const res = await fetch(url.href, { + method: 'POST', headers: { - 'Authorization': `Bearer ${token}` + 'Content-Type': 'application/json', + Authorization: `Bearer ${token}`, } - } - ) - .then(res => { - status = res.data; - }) - .catch(err => { - status.responseData = err; - status.error = true; }); + if (res.ok) { + const result = await res.json(); + status.responseData = result; + } else { + status.error = true; + } + } catch (err) { + status.error = true; + status.responseData = error; + } return status; } export async function forward(token) { let status = new ApiResponse(); const url = new URL('/api/Speaker/forward', BASE_API_URL); - await axios - .post(url.href, {}, { + try { + const res = await fetch(url.href, { + method: 'POST', headers: { - 'Authorization': `Bearer ${token}` + 'Content-Type': 'application/json', + Authorization: `Bearer ${token}`, } - } - ) - .then(res => { - status = res.data; - }) - .catch(err => { - status.responseData = err; - status.error = true; }); + if (res.ok) { + const result = await res.json(); + status.responseData = result; + } else { + status.error = true; + } + } catch (err) { + status.error = true; + status.responseData = error; + } return status; }