mirror of
https://github.com/tubearchivist/tubearchivist-frontend.git
synced 2024-11-24 04:40:12 +00:00
Added no token message.
This commit is contained in:
parent
30f0dbb81a
commit
b5b076793d
@ -6,6 +6,9 @@ import { getTAUrl } from "./constants";
|
||||
const TA_BASE_URL = getTAUrl();
|
||||
|
||||
export const getDownloads = async (token: string, filter: boolean, pageNumber: number): Promise<Download> => {
|
||||
if (!token) {
|
||||
throw new Error(`Unable to fetch downloads, no token provided.`);
|
||||
}
|
||||
const response = await fetch(`${TA_BASE_URL.server}/api/download/?filter=${filter ? 'ignore' : 'pending'}&page=${pageNumber}`, {
|
||||
headers: {
|
||||
Accept: "application/json",
|
||||
@ -30,6 +33,9 @@ export const getDownloads = async (token: string, filter: boolean, pageNumber: n
|
||||
};
|
||||
|
||||
export const sendDownloads = async (token: string, input: string): Promise<Download> => {
|
||||
if (!token) {
|
||||
throw new Error(`Unable to send downloads, no token provided.`);
|
||||
}
|
||||
var data = {
|
||||
"data": [{
|
||||
"youtube_id": input,
|
||||
@ -44,7 +50,7 @@ export const sendDownloads = async (token: string, input: string): Promise<Downl
|
||||
Authorization: `Token ${token}`,
|
||||
mode: "no-cors",
|
||||
},
|
||||
method: "POST"
|
||||
method: "POST",
|
||||
});
|
||||
if (response.ok) {
|
||||
return response.json();
|
||||
@ -57,6 +63,9 @@ export const sendDownloads = async (token: string, input: string): Promise<Downl
|
||||
};
|
||||
|
||||
export const sendDeleteAllQueuedIgnored = async (token: string, filter: string): Promise<Download> => {
|
||||
if (!token) {
|
||||
throw new Error(`Unable to delete downloads, no token provided.`);
|
||||
}
|
||||
const response = await fetch(`${TA_BASE_URL.server}/api/download/?filter=${filter}`, {
|
||||
headers: {
|
||||
Accept: "application/json",
|
||||
@ -64,7 +73,7 @@ export const sendDeleteAllQueuedIgnored = async (token: string, filter: string):
|
||||
Authorization: `Token ${token}`,
|
||||
mode: "no-cors",
|
||||
},
|
||||
method: "DELETE"
|
||||
method: "DELETE",
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error("Error removing all videos.");
|
||||
@ -74,6 +83,9 @@ export const sendDeleteAllQueuedIgnored = async (token: string, filter: string):
|
||||
};
|
||||
|
||||
export const sendDeleteVideoQueuedIgnored = async (token: string, videoId: string): Promise<Download> => {
|
||||
if (!token) {
|
||||
throw new Error(`Unable to delete downloads, no token provided.`);
|
||||
}
|
||||
const response = await fetch(`${TA_BASE_URL.server}/api/download/${videoId}/`, {
|
||||
headers: {
|
||||
Accept: "application/json",
|
||||
@ -81,7 +93,7 @@ export const sendDeleteVideoQueuedIgnored = async (token: string, videoId: strin
|
||||
Authorization: `Token ${token}`,
|
||||
mode: "no-cors",
|
||||
},
|
||||
method: "DELETE"
|
||||
method: "DELETE",
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error("Error removing video.");
|
||||
@ -91,6 +103,9 @@ export const sendDeleteVideoQueuedIgnored = async (token: string, videoId: strin
|
||||
};
|
||||
|
||||
export const sendMoveVideoQueuedIgnored = async (token: string, videoId: string, status: string): Promise<Download> => {
|
||||
if (!token) {
|
||||
throw new Error(`Unable to move downloads, no token provided.`);
|
||||
}
|
||||
var data = {
|
||||
"status": status
|
||||
};
|
||||
@ -102,7 +117,7 @@ export const sendMoveVideoQueuedIgnored = async (token: string, videoId: string,
|
||||
Authorization: `Token ${token}`,
|
||||
mode: "no-cors",
|
||||
},
|
||||
method: "POST"
|
||||
method: "POST",
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error("Error moving video to" + status + ".");
|
||||
@ -111,6 +126,9 @@ export const sendMoveVideoQueuedIgnored = async (token: string, videoId: string,
|
||||
};
|
||||
|
||||
export const sendTasks = async (token: string, task: Tasks): Promise<Task> => {
|
||||
if (!token) {
|
||||
throw new Error(`Unable to start task, no token provided.`);
|
||||
}
|
||||
var data = {
|
||||
"run": task
|
||||
};
|
||||
@ -122,7 +140,7 @@ export const sendTasks = async (token: string, task: Tasks): Promise<Task> => {
|
||||
Authorization: `Token ${token}`,
|
||||
mode: "no-cors",
|
||||
},
|
||||
method: "POST"
|
||||
method: "POST",
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error(`Error running task: ${task}.`);
|
||||
|
Loading…
Reference in New Issue
Block a user