tubearchivist-frontend/tubearchivist/www/src/lib/getDownloads.ts

77 lines
2.3 KiB
TypeScript
Raw Normal View History

import { Download } from "../types/download";
2022-04-17 19:47:18 +00:00
import { getTAUrl } from "./constants";
2022-04-17 19:47:18 +00:00
const TA_BASE_URL = getTAUrl();
2022-04-17 23:32:10 +00:00
export const getDownloads = async (token: string, filter: boolean): Promise<Download> => {
const response = await fetch(`${TA_BASE_URL.server}/api/download/?filter=${filter ? 'ignore' : 'pending'}`, {
headers: {
Accept: "application/json",
"Content-Type": "application/json",
Authorization: `Token ${token}`,
mode: "no-cors",
},
});
if (!response.ok) {
throw new Error("Error getting download queue information");
}
return response.json();
};
2022-04-17 01:03:17 +00:00
2022-04-18 17:33:14 +00:00
export const sendDownloads = async (token: string, input: string): Promise<Download> => {
2022-04-17 01:03:17 +00:00
var data = {
"data": [{
"youtube_id": input,
"status": "pending"
}]
};
2022-04-17 19:47:18 +00:00
const response = await fetch(`${TA_BASE_URL.server}/api/download/`, {
2022-04-17 01:03:17 +00:00
body: JSON.stringify(data),
headers: {
Accept: "application/json",
"Content-Type": "application/json",
Authorization: `Token ${token}`,
mode: "no-cors",
},
method: "POST"
});
if (!response.ok) {
2022-04-18 16:00:53 +00:00
// throw new Error("Error adding content to the download queue.");
// return response.json();
2022-04-17 01:03:17 +00:00
}
return response.json();
};
2022-04-18 17:33:14 +00:00
export const sendDeleteAllQueuedIgnored = async (token: string, filter: string): Promise<Download> => {
const response = await fetch(`${TA_BASE_URL.server}/api/download/?filter=${filter}`, {
headers: {
Accept: "application/json",
"Content-Type": "application/json",
Authorization: `Token ${token}`,
mode: "no-cors",
},
method: "DELETE"
});
if (!response.ok) {
// throw new Error("Error adding content to the download queue.");
// return response.json();
}
return response.json();
};
export const sendDeleteVideoQueuedIgnored = async (token: string, videoId: string): Promise<Download> => {
const response = await fetch(`${TA_BASE_URL.server}/api/download/${videoId}/`, {
headers: {
Accept: "application/json",
"Content-Type": "application/json",
Authorization: `Token ${token}`,
mode: "no-cors",
},
method: "DELETE"
});
if (!response.ok) {
// throw new Error("Error adding content to the download queue.");
// return response.json();
}
return response.json();
2022-04-18 17:33:14 +00:00
};