Add delete all ignored & pending

This commit is contained in:
n8detar 2022-04-18 10:33:14 -07:00
parent 66c2799e7e
commit 2159b1d39d
3 changed files with 26 additions and 9 deletions

View File

@ -1,5 +1,4 @@
import { Download } from "../types/download";
import { DownloadResponse } from "../types/download";
import { getTAUrl } from "./constants";
const TA_BASE_URL = getTAUrl();
@ -19,7 +18,7 @@ export const getDownloads = async (token: string, filter: boolean): Promise<Down
return response.json();
};
export const sendDownloads = async (token: string, input: string): Promise<DownloadResponse> => {
export const sendDownloads = async (token: string, input: string): Promise<Download> => {
var data = {
"data": [{
"youtube_id": input,
@ -42,3 +41,20 @@ export const sendDownloads = async (token: string, input: string): Promise<Downl
}
return response.json();
};
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();
};

View File

@ -5,7 +5,7 @@ import { dehydrate, QueryClient, useQuery } from "react-query";
import { CustomHead } from "../components/CustomHead";
import { Layout } from "../components/Layout";
import NextImage from "next/image";
import { getDownloads } from "../lib/getDownloads";
import { getDownloads, sendDeleteAllQueuedIgnored } from "../lib/getDownloads";
import { sendDownloads } from "../lib/getDownloads";
import RescanIcon from "../images/icon-rescan.svg";
import DownloadIcon from "../images/icon-download.svg";
@ -199,13 +199,13 @@ const Download: NextPage = () => {
{ignoredStatus &&
<div className="title-split">
<h2>Ignored from download</h2>
<button onClick={() => console.log("deleteQueue(this)")} data-id="ignore" title="Delete all previously ignored videos from the queue">Delete all ignored</button>
<button onClick={() => sendDeleteAllQueuedIgnored(session.ta_token.token, "ignore")} title="Delete all previously ignored videos from the queue">Delete all ignored</button>
</div>
}
{!ignoredStatus &&
<div className="title-split">
<h2>Download queue</h2>
<button onClick={() => console.log("deleteQueue(this)")} data-id="pending" title="Delete all pending videos from the queue">Delete all queued</button>
<button onClick={() => sendDeleteAllQueuedIgnored(session.ta_token.token, "pending")} title="Delete all pending videos from the queue">Delete all queued</button>
</div>
}
<h3>Total videos: {downloads?.data?.length} {!downloads?.data?.length && <p>No videos queued for download. Press rescan subscriptions to check if there are any new videos.</p>}</h3>

View File

@ -2,13 +2,14 @@ export interface Download {
data: Datum[];
config: Config;
paginate: boolean;
}
export interface DownloadResponse {
data: Datum[];
message: string;
}
// export interface DownloadResponse {
// data: Datum[];
// message: string;
// }
export interface Config {
archive: Archive;
default_view: DefaultView;