downloader-extension/js/api.js

52 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

2026-02-21 22:31:48 -05:00
import { api_url } from '/js/settings.js';
const _get = async (route) => {
const res = await fetch(await api_url(route));
return await res.json();
// const mime_type = res.headers.get('content-type').split(";")[0].trim();
// if(!mime_type) return;
// return
};
const _post = async (route, data) => await fetch(await api_url(route), {
method: 'POST',
headers: {
"Content-Type": "application/json"
},
body: typeof data === 'string' ? data : JSON.stringify(data)
});
const _delete = async (route) => await fetch(await api_url(route), { method: 'DELETE' })
export const actions = {
get_all() { return _get('actions') }
}
export const downloads = {
create(download_url, preset_id) {
return _post('download', {
url: download_url,
preset_id,
})
}
}
export const notifications = {
get_all() {
return _get('notifications');
},
remove() {
return _delete(`notifications/${notification_id}`);
},
remove_all() {
return _delete('notifications/inactive');
},
get_active() {
return _get('notifications/active');
},
get_failed() {
return _get('notifications/failed');
},
get_succeeded() {
return _get('notifications/succeeded');
},
}