refactor: simplified and renamed get function
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
export const get = function(key, data){
|
||||
let url = `/api/${key}`
|
||||
if (data){
|
||||
let query = Object.keys(data)
|
||||
.map(k => encodeURIComponent(k) + '=' + encodeURIComponent(data[k]))
|
||||
.join('&')
|
||||
url += '?'+query
|
||||
}
|
||||
return fetch(url).then(response => response.json())
|
||||
export function fetchApi(key, data) {
|
||||
const url = new URL(`${window.location.origin}/api/${key}`)
|
||||
|
||||
Object.keys(data).forEach(key => {
|
||||
url.searchParams.append(key, data[key])
|
||||
})
|
||||
|
||||
return fetch(url.href).then(response => response.json())
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { get } from '@/utils/api'
|
||||
import { fetchApi } from '@/utils/api'
|
||||
|
||||
/**
|
||||
* @param {string} url
|
||||
@@ -7,7 +7,7 @@ import { get } from '@/utils/api'
|
||||
export function sendAddToQueue(url, bitrate = null) {
|
||||
if (!url) throw new Error('No URL given to sendAddToQueue function!')
|
||||
|
||||
get('addToQueue', { url, bitrate })
|
||||
fetchApi('addToQueue', { url, bitrate })
|
||||
}
|
||||
|
||||
export function aggregateDownloadLinks(releases) {
|
||||
|
||||
Reference in New Issue
Block a user