Compare commits
12 Commits
870a0a901e
...
b246dbcd75
Author | SHA1 | Date |
---|---|---|
Sean | b246dbcd75 | |
Sean | 40676990d2 | |
Sean | 7c4f7d8051 | |
renovate[bot] | 9b68493c9f | |
Renovate Bot | 4865b75e51 | |
n8detar | f42efe69be | |
n8detar | b5b076793d | |
Nathan DeTar | 102eaab1f5 | |
n8detar | 30f0dbb81a | |
n8detar | e41ac9276b | |
n8detar | 0ea19defcc | |
n8detar | 883f5dc801 |
|
@ -11,11 +11,11 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"next": "12.1.1",
|
||||
"next-auth": "4.3.1",
|
||||
"next-auth": "4.7.0",
|
||||
"react": "18.0.0",
|
||||
"react-dom": "18.0.0",
|
||||
"react-player": "2.10.0",
|
||||
"react-query": "3.34.19",
|
||||
"react-query": "3.39.1",
|
||||
"sharp": "0.30.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
import { Download } from "../types/download";
|
||||
import { Download, Task, Tasks } from "../types/download";
|
||||
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",
|
||||
|
@ -28,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,
|
||||
|
@ -42,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();
|
||||
|
@ -55,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",
|
||||
|
@ -62,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.");
|
||||
|
@ -72,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",
|
||||
|
@ -79,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.");
|
||||
|
@ -89,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
|
||||
};
|
||||
|
@ -100,10 +117,33 @@ 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 + ".");
|
||||
}
|
||||
return response.json();
|
||||
};
|
||||
|
||||
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
|
||||
};
|
||||
const response = await fetch(`${TA_BASE_URL.server}/api/task/`, {
|
||||
body: JSON.stringify(data),
|
||||
headers: {
|
||||
Accept: "application/json",
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Token ${token}`,
|
||||
mode: "no-cors",
|
||||
},
|
||||
method: "POST",
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error(`Error running task: ${task}.`);
|
||||
}
|
||||
return response.json();
|
||||
};
|
|
@ -5,8 +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, sendDeleteAllQueuedIgnored, sendDeleteVideoQueuedIgnored, sendMoveVideoQueuedIgnored } from "../lib/getDownloads";
|
||||
import { sendDownloads } from "../lib/getDownloads";
|
||||
import { getDownloads, sendDownloads, sendDeleteAllQueuedIgnored, sendDeleteVideoQueuedIgnored, sendMoveVideoQueuedIgnored, sendTasks } from "../lib/getDownloads";
|
||||
import RescanIcon from "../images/icon-rescan.svg";
|
||||
import DownloadIcon from "../images/icon-download.svg";
|
||||
import AddIcon from "../images/icon-add.svg";
|
||||
|
@ -15,6 +14,7 @@ import ListViewIcon from "../images/icon-listview.svg";
|
|||
import StopIcon from "../images/icon-stop.svg";
|
||||
import CloseIcon from "../images/icon-close.svg";
|
||||
import { getTAUrl } from "../lib/constants";
|
||||
import { Tasks } from "../types/download";
|
||||
|
||||
const TA_BASE_URL = getTAUrl();
|
||||
|
||||
|
@ -124,6 +124,18 @@ const Download: NextPage = () => {
|
|||
.catch(error => handleSetErrorMessage(error.message));
|
||||
}
|
||||
|
||||
const handleSendTask = (session: string, task: Tasks) => {
|
||||
sendTasks(session, task).then((response) => {
|
||||
if (response.success) {
|
||||
handleSetErrorMessage(null);
|
||||
} else {
|
||||
handleSetErrorMessage(`Error running task: ${response.task}.`);
|
||||
}
|
||||
|
||||
})
|
||||
.catch(error => handleSetErrorMessage(error.message));
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<CustomHead title="Downloads" />
|
||||
|
@ -202,7 +214,7 @@ const Download: NextPage = () => {
|
|||
alt="rescan-icon"
|
||||
title="Rescan subscriptions"
|
||||
// className="rotate-img" // Set when rescanning
|
||||
onClick={() => console.log("rescanPending()")}
|
||||
onClick={() => handleSendTask(session.ta_token.token, "rescan_pending")}
|
||||
/>
|
||||
{/* <img id="rescan-icon" onclick="rescanPending()" src="{% static 'img/icon-rescan.svg' %}" alt="rescan-icon"></img> */}
|
||||
<p>Rescan subscriptions</p>
|
||||
|
@ -215,7 +227,7 @@ const Download: NextPage = () => {
|
|||
alt="download-icon"
|
||||
title="Start download"
|
||||
// className="bounce-img" // Set when video is downloading
|
||||
onClick={() => console.log("dlPending()")}
|
||||
onClick={() => handleSendTask(session.ta_token.token, "download_pending")}
|
||||
/>
|
||||
{/* <img id="download-icon" onclick="dlPending()" src="{% static 'img/icon-download.svg' %}" alt="download-icon"></img> */}
|
||||
<p>Start download</p>
|
||||
|
|
|
@ -5,6 +5,13 @@ export interface Download {
|
|||
message: string;
|
||||
}
|
||||
|
||||
export interface Task {
|
||||
success: boolean;
|
||||
task: string;
|
||||
}
|
||||
|
||||
export type Tasks = "download_pending" | "rescan_pending";
|
||||
|
||||
export interface Paginate {
|
||||
page_size: number;
|
||||
page_from: number;
|
||||
|
@ -16,11 +23,6 @@ export interface Paginate {
|
|||
total_hits: number;
|
||||
}
|
||||
|
||||
// export interface DownloadResponse {
|
||||
// data: Datum[];
|
||||
// message: string;
|
||||
// }
|
||||
|
||||
export interface Config {
|
||||
archive: Archive;
|
||||
default_view: DefaultView;
|
||||
|
@ -106,19 +108,6 @@ export interface Datum {
|
|||
title: string;
|
||||
vid_thumb_url: string;
|
||||
youtube_id: string;
|
||||
|
||||
// active: boolean;
|
||||
// category: Category[];
|
||||
// channel: Channel;
|
||||
// date_downloaded: number;
|
||||
// description: string;
|
||||
// media_url: string;
|
||||
// player: Player;
|
||||
// playlist: Playlist[];
|
||||
// stats: Stats;
|
||||
// tags: string[];
|
||||
// vid_last_refresh: LastRefresh;
|
||||
// vid_thumb_base64: string;
|
||||
}
|
||||
|
||||
export enum Category {
|
||||
|
|
16
yarn.lock
16
yarn.lock
|
@ -1630,10 +1630,10 @@ natural-compare@^1.4.0:
|
|||
resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7"
|
||||
integrity sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=
|
||||
|
||||
next-auth@4.3.1:
|
||||
version "4.3.1"
|
||||
resolved "https://registry.yarnpkg.com/next-auth/-/next-auth-4.3.1.tgz#94520592d1d1851eb66ca3ad2758637e1df950e1"
|
||||
integrity sha512-DBYEPBLq5naIqh/1i2zEHljcA1OXXecKW3NRU1W4s6R3UX3RdLZ2lWlqgBHUiZQ1zdNikFM/bYQxVGyG7bx8oA==
|
||||
next-auth@4.7.0:
|
||||
version "4.7.0"
|
||||
resolved "https://registry.yarnpkg.com/next-auth/-/next-auth-4.7.0.tgz#2d42b44729fde77d9e98a88612daf0ee853b9641"
|
||||
integrity sha512-boXSIzHvCyNq1Jthi24LLnx12iKBsqsMxUKm5qq9alkfhVMeIRUR/wKP0FPSGc1s9WcGXMS3NmKQfADCEb0wow==
|
||||
dependencies:
|
||||
"@babel/runtime" "^7.16.3"
|
||||
"@panva/hkdf" "^1.0.1"
|
||||
|
@ -2023,10 +2023,10 @@ react-player@2.10.0:
|
|||
prop-types "^15.7.2"
|
||||
react-fast-compare "^3.0.1"
|
||||
|
||||
react-query@3.34.19:
|
||||
version "3.34.19"
|
||||
resolved "https://registry.yarnpkg.com/react-query/-/react-query-3.34.19.tgz#0ff049b6e0d2ed148e9abfdd346625d0e88dc229"
|
||||
integrity sha512-JO0Ymi58WKmvnhgg6bGIrYIeKb64KsKaPWo8JcGnmK2jJxAs2XmMBzlP75ZepSU7CHzcsWtIIyhMrLbX3pb/3w==
|
||||
react-query@3.39.1:
|
||||
version "3.39.1"
|
||||
resolved "https://registry.yarnpkg.com/react-query/-/react-query-3.39.1.tgz#3876c0fdac7a3b5a84e195534e5fa8fbdd628847"
|
||||
integrity sha512-qYKT1bavdDiQZbngWZyPotlBVzcBjDYEJg5RQLBa++5Ix5jjfbEYJmHSZRZD+USVHUSvl/ey9Hu+QfF1QAK80A==
|
||||
dependencies:
|
||||
"@babel/runtime" "^7.5.5"
|
||||
broadcast-channel "^3.4.1"
|
||||
|
|
Loading…
Reference in New Issue