feat: fetching home data with rest APIs; refactor: renamed fetch functions
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
export function fetchApi(key, data) {
|
||||
export function fetchData(key, data = {}) {
|
||||
const url = new URL(`${window.location.origin}/api/${key}`)
|
||||
|
||||
Object.keys(data).forEach(key => {
|
||||
@@ -7,3 +7,13 @@ export function fetchApi(key, data) {
|
||||
|
||||
return fetch(url.href).then(response => response.json())
|
||||
}
|
||||
|
||||
export function sendToServer(key, data) {
|
||||
const url = new URL(`${window.location.origin}/api/${key}`)
|
||||
|
||||
Object.keys(data).forEach(key => {
|
||||
url.searchParams.append(key, data[key])
|
||||
})
|
||||
|
||||
fetch(url.href).catch(console.error)
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { fetchApi } from '@/utils/api'
|
||||
import { sendToServer } from '@/utils/api'
|
||||
|
||||
/**
|
||||
* @param {string} url
|
||||
* @param {number} bitrate
|
||||
* @param {number|null} bitrate
|
||||
*/
|
||||
export function sendAddToQueue(url, bitrate = null) {
|
||||
if (!url) throw new Error('No URL given to sendAddToQueue function!')
|
||||
|
||||
fetchApi('addToQueue', { url, bitrate })
|
||||
sendToServer('addToQueue', { url, bitrate })
|
||||
}
|
||||
|
||||
export function aggregateDownloadLinks(releases) {
|
||||
|
||||
Reference in New Issue
Block a user