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();
|
const TA_BASE_URL = getTAUrl();
|
||||||
|
|
||||||
export const getDownloads = async (token: string, filter: boolean, pageNumber: number): Promise<Download> => {
|
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}`, {
|
const response = await fetch(`${TA_BASE_URL.server}/api/download/?filter=${filter ? 'ignore' : 'pending'}&page=${pageNumber}`, {
|
||||||
headers: {
|
headers: {
|
||||||
Accept: "application/json",
|
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> => {
|
export const sendDownloads = async (token: string, input: string): Promise<Download> => {
|
||||||
|
if (!token) {
|
||||||
|
throw new Error(`Unable to send downloads, no token provided.`);
|
||||||
|
}
|
||||||
var data = {
|
var data = {
|
||||||
"data": [{
|
"data": [{
|
||||||
"youtube_id": input,
|
"youtube_id": input,
|
||||||
@ -44,7 +50,7 @@ export const sendDownloads = async (token: string, input: string): Promise<Downl
|
|||||||
Authorization: `Token ${token}`,
|
Authorization: `Token ${token}`,
|
||||||
mode: "no-cors",
|
mode: "no-cors",
|
||||||
},
|
},
|
||||||
method: "POST"
|
method: "POST",
|
||||||
});
|
});
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
return response.json();
|
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> => {
|
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}`, {
|
const response = await fetch(`${TA_BASE_URL.server}/api/download/?filter=${filter}`, {
|
||||||
headers: {
|
headers: {
|
||||||
Accept: "application/json",
|
Accept: "application/json",
|
||||||
@ -64,7 +73,7 @@ export const sendDeleteAllQueuedIgnored = async (token: string, filter: string):
|
|||||||
Authorization: `Token ${token}`,
|
Authorization: `Token ${token}`,
|
||||||
mode: "no-cors",
|
mode: "no-cors",
|
||||||
},
|
},
|
||||||
method: "DELETE"
|
method: "DELETE",
|
||||||
});
|
});
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error("Error removing all videos.");
|
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> => {
|
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}/`, {
|
const response = await fetch(`${TA_BASE_URL.server}/api/download/${videoId}/`, {
|
||||||
headers: {
|
headers: {
|
||||||
Accept: "application/json",
|
Accept: "application/json",
|
||||||
@ -81,7 +93,7 @@ export const sendDeleteVideoQueuedIgnored = async (token: string, videoId: strin
|
|||||||
Authorization: `Token ${token}`,
|
Authorization: `Token ${token}`,
|
||||||
mode: "no-cors",
|
mode: "no-cors",
|
||||||
},
|
},
|
||||||
method: "DELETE"
|
method: "DELETE",
|
||||||
});
|
});
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error("Error removing video.");
|
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> => {
|
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 = {
|
var data = {
|
||||||
"status": status
|
"status": status
|
||||||
};
|
};
|
||||||
@ -102,7 +117,7 @@ export const sendMoveVideoQueuedIgnored = async (token: string, videoId: string,
|
|||||||
Authorization: `Token ${token}`,
|
Authorization: `Token ${token}`,
|
||||||
mode: "no-cors",
|
mode: "no-cors",
|
||||||
},
|
},
|
||||||
method: "POST"
|
method: "POST",
|
||||||
});
|
});
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error("Error moving video to" + status + ".");
|
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> => {
|
export const sendTasks = async (token: string, task: Tasks): Promise<Task> => {
|
||||||
|
if (!token) {
|
||||||
|
throw new Error(`Unable to start task, no token provided.`);
|
||||||
|
}
|
||||||
var data = {
|
var data = {
|
||||||
"run": task
|
"run": task
|
||||||
};
|
};
|
||||||
@ -122,7 +140,7 @@ export const sendTasks = async (token: string, task: Tasks): Promise<Task> => {
|
|||||||
Authorization: `Token ${token}`,
|
Authorization: `Token ${token}`,
|
||||||
mode: "no-cors",
|
mode: "no-cors",
|
||||||
},
|
},
|
||||||
method: "POST"
|
method: "POST",
|
||||||
});
|
});
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(`Error running task: ${task}.`);
|
throw new Error(`Error running task: ${task}.`);
|
||||||
|
Loading…
Reference in New Issue
Block a user