implementing download
This commit is contained in:
@@ -1,13 +1,16 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Vite + Svelte + TS</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/svelte.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>yt-dlp WebUI</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -12,6 +12,7 @@
|
||||
"devDependencies": {
|
||||
"@sveltejs/vite-plugin-svelte": "^3.0.1",
|
||||
"@tsconfig/svelte": "^5.0.2",
|
||||
"@zerodevx/svelte-toast": "^0.9.5",
|
||||
"autoprefixer": "^10.4.17",
|
||||
"postcss": "^8.4.34",
|
||||
"svelte": "^4.2.8",
|
||||
@@ -22,6 +23,8 @@
|
||||
"vite": "^5.0.8"
|
||||
},
|
||||
"dependencies": {
|
||||
"fp-ts": "^2.16.2"
|
||||
"@fontsource/roboto": "^5.0.8",
|
||||
"fp-ts": "^2.16.2",
|
||||
"lucide-svelte": "^0.323.0"
|
||||
}
|
||||
}
|
||||
|
||||
50
ui/pnpm-lock.yaml
generated
50
ui/pnpm-lock.yaml
generated
@@ -5,9 +5,15 @@ settings:
|
||||
excludeLinksFromLockfile: false
|
||||
|
||||
dependencies:
|
||||
'@fontsource/roboto':
|
||||
specifier: ^5.0.8
|
||||
version: 5.0.8
|
||||
fp-ts:
|
||||
specifier: ^2.16.2
|
||||
version: 2.16.2
|
||||
lucide-svelte:
|
||||
specifier: ^0.323.0
|
||||
version: 0.323.0(svelte@4.2.10)
|
||||
|
||||
devDependencies:
|
||||
'@sveltejs/vite-plugin-svelte':
|
||||
@@ -16,6 +22,9 @@ devDependencies:
|
||||
'@tsconfig/svelte':
|
||||
specifier: ^5.0.2
|
||||
version: 5.0.2
|
||||
'@zerodevx/svelte-toast':
|
||||
specifier: ^0.9.5
|
||||
version: 0.9.5(svelte@4.2.10)
|
||||
autoprefixer:
|
||||
specifier: ^10.4.17
|
||||
version: 10.4.17(postcss@8.4.34)
|
||||
@@ -54,7 +63,6 @@ packages:
|
||||
dependencies:
|
||||
'@jridgewell/gen-mapping': 0.3.3
|
||||
'@jridgewell/trace-mapping': 0.3.22
|
||||
dev: true
|
||||
|
||||
/@esbuild/aix-ppc64@0.19.12:
|
||||
resolution: {integrity: sha512-bmoCYyWdEL3wDQIVbcyzRyeKLgk2WtWLTWz1ZIAZF/EGbNOwSA6ew3PftJ1PqMiOOGu0OyFMzG53L0zqIpPeNA==}
|
||||
@@ -263,6 +271,10 @@ packages:
|
||||
dev: true
|
||||
optional: true
|
||||
|
||||
/@fontsource/roboto@5.0.8:
|
||||
resolution: {integrity: sha512-XxPltXs5R31D6UZeLIV1td3wTXU3jzd3f2DLsXI8tytMGBkIsGcc9sIyiupRtA8y73HAhuSCeweOoBqf6DbWCA==}
|
||||
dev: false
|
||||
|
||||
/@isaacs/cliui@8.0.2:
|
||||
resolution: {integrity: sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA==}
|
||||
engines: {node: '>=12'}
|
||||
@@ -282,28 +294,23 @@ packages:
|
||||
'@jridgewell/set-array': 1.1.2
|
||||
'@jridgewell/sourcemap-codec': 1.4.15
|
||||
'@jridgewell/trace-mapping': 0.3.22
|
||||
dev: true
|
||||
|
||||
/@jridgewell/resolve-uri@3.1.1:
|
||||
resolution: {integrity: sha512-dSYZh7HhCDtCKm4QakX0xFpsRDqjjtZf/kjI/v3T3Nwt5r8/qz/M19F9ySyOqU94SXBmeG9ttTul+YnR4LOxFA==}
|
||||
engines: {node: '>=6.0.0'}
|
||||
dev: true
|
||||
|
||||
/@jridgewell/set-array@1.1.2:
|
||||
resolution: {integrity: sha512-xnkseuNADM0gt2bs+BvhO0p78Mk762YnZdsuzFV018NoG1Sj1SCQvpSqa7XUaTam5vAGasABV9qXASMKnFMwMw==}
|
||||
engines: {node: '>=6.0.0'}
|
||||
dev: true
|
||||
|
||||
/@jridgewell/sourcemap-codec@1.4.15:
|
||||
resolution: {integrity: sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==}
|
||||
dev: true
|
||||
|
||||
/@jridgewell/trace-mapping@0.3.22:
|
||||
resolution: {integrity: sha512-Wf963MzWtA2sjrNt+g18IAln9lKnlRp+K2eH4jjIoF1wYeq3aMREpG09xhlhdzS0EjwU7qmUJYangWa+151vZw==}
|
||||
dependencies:
|
||||
'@jridgewell/resolve-uri': 3.1.1
|
||||
'@jridgewell/sourcemap-codec': 1.4.15
|
||||
dev: true
|
||||
|
||||
/@nodelib/fs.scandir@2.1.5:
|
||||
resolution: {integrity: sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==}
|
||||
@@ -479,17 +486,23 @@ packages:
|
||||
|
||||
/@types/estree@1.0.5:
|
||||
resolution: {integrity: sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==}
|
||||
dev: true
|
||||
|
||||
/@types/pug@2.0.10:
|
||||
resolution: {integrity: sha512-Sk/uYFOBAB7mb74XcpizmH0KOR2Pv3D2Hmrh1Dmy5BmK3MpdSa5kqZcg6EKBdklU0bFXX9gCfzvpnyUehrPIuA==}
|
||||
dev: true
|
||||
|
||||
/@zerodevx/svelte-toast@0.9.5(svelte@4.2.10):
|
||||
resolution: {integrity: sha512-JLeB/oRdJfT+dz9A5bgd3Z7TuQnBQbeUtXrGIrNWMGqWbabpepBF2KxtWVhL2qtxpRqhae2f6NAOzH7xs4jUSw==}
|
||||
peerDependencies:
|
||||
svelte: ^3.57.0 || ^4.0.0
|
||||
dependencies:
|
||||
svelte: 4.2.10
|
||||
dev: true
|
||||
|
||||
/acorn@8.11.3:
|
||||
resolution: {integrity: sha512-Y9rRfJG5jcKOE0CLisYbojUjIrIEE7AGMzA/Sm4BslANhbS+cDMpgBdcPT91oJ7OuJ9hYJBx59RjbhxVnrF8Xg==}
|
||||
engines: {node: '>=0.4.0'}
|
||||
hasBin: true
|
||||
dev: true
|
||||
|
||||
/ansi-regex@5.0.1:
|
||||
resolution: {integrity: sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==}
|
||||
@@ -533,7 +546,6 @@ packages:
|
||||
resolution: {integrity: sha512-b0P0sZPKtyu8HkeRAfCq0IfURZK+SuwMjY1UXGBU27wpAiTwQAIlq56IbIO+ytk/JjS1fMR14ee5WBBfKi5J6A==}
|
||||
dependencies:
|
||||
dequal: 2.0.3
|
||||
dev: true
|
||||
|
||||
/autoprefixer@10.4.17(postcss@8.4.34):
|
||||
resolution: {integrity: sha512-/cpVNRLSfhOtcGflT13P2794gVSgmPgTR+erw5ifnMLZb0UnSlkK4tquLmkd3BhA+nLo5tX8Cu0upUsGKvKbmg==}
|
||||
@@ -555,7 +567,6 @@ packages:
|
||||
resolution: {integrity: sha512-+60uv1hiVFhHZeO+Lz0RYzsVHy5Wr1ayX0mwda9KPDVLNJgZ1T9Ny7VmFbLDzxsH0D87I86vgj3gFrjTJUYznw==}
|
||||
dependencies:
|
||||
dequal: 2.0.3
|
||||
dev: true
|
||||
|
||||
/balanced-match@1.0.2:
|
||||
resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==}
|
||||
@@ -638,7 +649,6 @@ packages:
|
||||
acorn: 8.11.3
|
||||
estree-walker: 3.0.3
|
||||
periscopic: 3.1.0
|
||||
dev: true
|
||||
|
||||
/color-convert@2.0.1:
|
||||
resolution: {integrity: sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==}
|
||||
@@ -675,7 +685,6 @@ packages:
|
||||
dependencies:
|
||||
mdn-data: 2.0.30
|
||||
source-map-js: 1.0.2
|
||||
dev: true
|
||||
|
||||
/cssesc@3.0.0:
|
||||
resolution: {integrity: sha512-/Tb/JcjK111nNScGob5MNtsntNM1aCNUDipB/TkwZFhyDrrE47SOx/18wF2bbjgc3ZzCSKW1T5nt5EbFoAz/Vg==}
|
||||
@@ -703,7 +712,6 @@ packages:
|
||||
/dequal@2.0.3:
|
||||
resolution: {integrity: sha512-0je+qPKHEMohvfRTCEo3CrPG6cAzAYgmzKyxRiYSSDkS6eGJdyVJm7WaYA5ECaAD9wLB2T4EEeymA5aFVcYXCA==}
|
||||
engines: {node: '>=6'}
|
||||
dev: true
|
||||
|
||||
/detect-indent@6.1.0:
|
||||
resolution: {integrity: sha512-reYkTUJAZb9gUuZ2RvVCNhVHdg62RHnJ7WJl8ftMi4diZ6NWlciOzQN88pUhSELEwflJht4oQDv0F0BMlwaYtA==}
|
||||
@@ -778,7 +786,6 @@ packages:
|
||||
resolution: {integrity: sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==}
|
||||
dependencies:
|
||||
'@types/estree': 1.0.5
|
||||
dev: true
|
||||
|
||||
/fast-glob@3.3.2:
|
||||
resolution: {integrity: sha512-oX2ruAFQwf/Orj8m737Y5adxDQO0LAB7/S5MnxCdTNDd4p6BsyIVsv9JQsATbTSq8KHRpLwIHbVlUNatxd+1Ow==}
|
||||
@@ -942,7 +949,6 @@ packages:
|
||||
resolution: {integrity: sha512-v3rht/LgVcsdZa3O2Nqs+NMowLOxeOm7Ay9+/ARQ2F+qEoANRcqrjAZKGN0v8ymUetZGgkp26LTnGT7H0Qo9Pg==}
|
||||
dependencies:
|
||||
'@types/estree': 1.0.5
|
||||
dev: true
|
||||
|
||||
/isexe@2.0.0:
|
||||
resolution: {integrity: sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==}
|
||||
@@ -983,23 +989,28 @@ packages:
|
||||
|
||||
/locate-character@3.0.0:
|
||||
resolution: {integrity: sha512-SW13ws7BjaeJ6p7Q6CO2nchbYEc3X3J6WrmTTDto7yMPqVSZTUyY5Tjbid+Ab8gLnATtygYtiDIJGQRRn2ZOiA==}
|
||||
dev: true
|
||||
|
||||
/lru-cache@10.2.0:
|
||||
resolution: {integrity: sha512-2bIM8x+VAf6JT4bKAljS1qUWgMsqZRPGJS6FSahIMPVvctcNhyVp7AJu7quxOW9jwkryBReKZY5tY5JYv2n/7Q==}
|
||||
engines: {node: 14 || >=16.14}
|
||||
dev: true
|
||||
|
||||
/lucide-svelte@0.323.0(svelte@4.2.10):
|
||||
resolution: {integrity: sha512-3GEFk1vCwB8BtHTHZTocFJfX6AtTLQw9a74JSuihAGx+MzhxqeWk8W1TkM4WUlvE0x9UdONM2rJGRyx9IyjkJg==}
|
||||
peerDependencies:
|
||||
svelte: ^3 || ^4 || ^5.0.0-next.42
|
||||
dependencies:
|
||||
svelte: 4.2.10
|
||||
dev: false
|
||||
|
||||
/magic-string@0.30.7:
|
||||
resolution: {integrity: sha512-8vBuFF/I/+OSLRmdf2wwFCJCz+nSn0m6DPvGH1fS/KiQoSaR+sETbov0eIk9KhEKy8CYqIkIAnbohxT/4H0kuA==}
|
||||
engines: {node: '>=12'}
|
||||
dependencies:
|
||||
'@jridgewell/sourcemap-codec': 1.4.15
|
||||
dev: true
|
||||
|
||||
/mdn-data@2.0.30:
|
||||
resolution: {integrity: sha512-GaqWWShW4kv/G9IEucWScBx9G1/vsFZZJUO+tD26M8J8z3Kw5RDQjaoZe03YAClgeS/SWPOcb4nkFBTEi5DUEA==}
|
||||
dev: true
|
||||
|
||||
/merge2@1.4.1:
|
||||
resolution: {integrity: sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==}
|
||||
@@ -1136,7 +1147,6 @@ packages:
|
||||
'@types/estree': 1.0.5
|
||||
estree-walker: 3.0.3
|
||||
is-reference: 3.0.2
|
||||
dev: true
|
||||
|
||||
/picocolors@1.0.0:
|
||||
resolution: {integrity: sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==}
|
||||
@@ -1345,7 +1355,6 @@ packages:
|
||||
/source-map-js@1.0.2:
|
||||
resolution: {integrity: sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw==}
|
||||
engines: {node: '>=0.10.0'}
|
||||
dev: true
|
||||
|
||||
/string-width@4.2.3:
|
||||
resolution: {integrity: sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==}
|
||||
@@ -1507,7 +1516,6 @@ packages:
|
||||
locate-character: 3.0.0
|
||||
magic-string: 0.30.7
|
||||
periscopic: 3.1.0
|
||||
dev: true
|
||||
|
||||
/tailwindcss@3.4.1:
|
||||
resolution: {integrity: sha512-qAYmXRfk3ENzuPBakNK0SRrUDipP8NQnEY6772uDhflcQz5EhRdD7JNZxyrFHVQNCwULPBn6FNPp9brpO7ctcA==}
|
||||
|
||||
|
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
@@ -1,10 +1,15 @@
|
||||
<script lang="ts">
|
||||
import { SvelteToast } from '@zerodevx/svelte-toast';
|
||||
import * as O from 'fp-ts/Option';
|
||||
import { pipe } from 'fp-ts/lib/function';
|
||||
import { onDestroy } from 'svelte';
|
||||
import DownloadCard from './lib/DownloadCard.svelte';
|
||||
import FloatingAction from './lib/FloatingAction.svelte';
|
||||
import Footer from './lib/Footer.svelte';
|
||||
import Navbar from './lib/Navbar.svelte';
|
||||
import Spinner from './lib/Spinner.svelte';
|
||||
import { downloads, rpcClient } from './lib/store';
|
||||
import { datetimeCompareFunc, isRPCResponse } from './lib/utils';
|
||||
import { onDestroy } from 'svelte';
|
||||
import Navbar from './lib/Navbar.svelte';
|
||||
|
||||
const unsubscribe = rpcClient.subscribe(($client) => {
|
||||
setInterval(() => $client.running(), 750);
|
||||
@@ -38,18 +43,22 @@
|
||||
onDestroy(unsubscribe);
|
||||
</script>
|
||||
|
||||
<main>
|
||||
<main
|
||||
class="bg-neutral-50 dark:bg-neutral-900 h-screen text-neutral-950 dark:text-neutral-50"
|
||||
>
|
||||
<Navbar />
|
||||
<div class="flex flex-col gap-2 p-8">
|
||||
{#each pipe( $downloads, O.getOrElseW(() => []), ) as download}
|
||||
<div class="flex gap-4 bg-neutral-100 p-4 rounded-lg shadow-lg border">
|
||||
<img src={download.info.thumbnail} class="h-48 rounded" alt="" />
|
||||
<div class="break-all">
|
||||
<div>{download.id}</div>
|
||||
<div>{JSON.stringify(download.info)}</div>
|
||||
<div>{JSON.stringify(download.progress)}</div>
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{#if O.isNone($downloads)}
|
||||
<div class="h-[90vh] w-full flex justify-center items-center">
|
||||
<Spinner />
|
||||
</div>
|
||||
{:else}
|
||||
<div class="grid grid-cols-1 lg:grid-cols-2 gap-2 p-8">
|
||||
{#each pipe( $downloads, O.getOrElseW(() => []), ) as download}
|
||||
<DownloadCard {download} />
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
<FloatingAction />
|
||||
<Footer />
|
||||
<SvelteToast />
|
||||
</main>
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
@tailwind utilities;
|
||||
|
||||
/* body {
|
||||
font-family: "Roboto";
|
||||
} */
|
||||
15
ui/src/lib/Button.svelte
Normal file
15
ui/src/lib/Button.svelte
Normal file
@@ -0,0 +1,15 @@
|
||||
<script lang="ts">
|
||||
let clazz: string = '';
|
||||
export let disabled: boolean = false;
|
||||
export { clazz as class };
|
||||
</script>
|
||||
|
||||
<button
|
||||
class={`px-2.5 py-2 rounded-lg bg-orange-300 hover:bg-orange-400 hover:duration-150 text-sm font-semibold ${
|
||||
disabled && 'bg-neutral-300 hover:bg-neutral-300'
|
||||
} ${clazz}`}
|
||||
{disabled}
|
||||
on:click
|
||||
>
|
||||
<slot />
|
||||
</button>
|
||||
10
ui/src/lib/Chip.svelte
Normal file
10
ui/src/lib/Chip.svelte
Normal file
@@ -0,0 +1,10 @@
|
||||
<script lang="ts">
|
||||
export let text: string;
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="flex items-center gap-1.5 p-1 bg-orange-200 rounded-lg text-neutral-900"
|
||||
>
|
||||
<slot />
|
||||
{text}
|
||||
</div>
|
||||
137
ui/src/lib/CookiesTextField.svelte
Normal file
137
ui/src/lib/CookiesTextField.svelte
Normal file
@@ -0,0 +1,137 @@
|
||||
<script lang="ts">
|
||||
import { toast } from '@zerodevx/svelte-toast';
|
||||
import * as A from 'fp-ts/Array';
|
||||
import * as E from 'fp-ts/Either';
|
||||
import * as O from 'fp-ts/Option';
|
||||
import { pipe } from 'fp-ts/lib/function';
|
||||
import { get } from 'svelte/store';
|
||||
import { ffetch } from './ffetch';
|
||||
import { cookiesTemplate, serverApiEndpoint } from './store';
|
||||
import { debounce } from './utils';
|
||||
|
||||
const flag = '--cookies=cookies.txt';
|
||||
|
||||
let cookies = localStorage.getItem('cookies') ?? '';
|
||||
|
||||
const validateCookie = (cookie: string) =>
|
||||
pipe(
|
||||
cookie,
|
||||
(cookie) => cookie.replace(/\s\s+/g, ' '),
|
||||
(cookie) => cookie.replaceAll('\t', ' '),
|
||||
(cookie) => cookie.split(' '),
|
||||
E.of,
|
||||
E.flatMap(
|
||||
E.fromPredicate(
|
||||
(f) => f.length === 7,
|
||||
() => `missing parts`,
|
||||
),
|
||||
),
|
||||
E.flatMap(
|
||||
E.fromPredicate(
|
||||
(f) => f[0].length > 0,
|
||||
() => 'missing domain',
|
||||
),
|
||||
),
|
||||
E.flatMap(
|
||||
E.fromPredicate(
|
||||
(f) => f[1] === 'TRUE' || f[1] === 'FALSE',
|
||||
() => `invalid include subdomains`,
|
||||
),
|
||||
),
|
||||
E.flatMap(
|
||||
E.fromPredicate(
|
||||
(f) => f[2].length > 0,
|
||||
() => 'invalid path',
|
||||
),
|
||||
),
|
||||
E.flatMap(
|
||||
E.fromPredicate(
|
||||
(f) => f[3] === 'TRUE' || f[3] === 'FALSE',
|
||||
() => 'invalid secure flag',
|
||||
),
|
||||
),
|
||||
E.flatMap(
|
||||
E.fromPredicate(
|
||||
(f) => isFinite(Number(f[4])),
|
||||
() => 'invalid expiration',
|
||||
),
|
||||
),
|
||||
E.flatMap(
|
||||
E.fromPredicate(
|
||||
(f) => f[5].length > 0,
|
||||
() => 'invalid name',
|
||||
),
|
||||
),
|
||||
E.flatMap(
|
||||
E.fromPredicate(
|
||||
(f) => f[6].length > 0,
|
||||
() => 'invalid value',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
const validateNetscapeCookies = (cookies: string) =>
|
||||
pipe(
|
||||
cookies,
|
||||
(cookies) => cookies.split('\n'),
|
||||
(cookies) => cookies.filter((f) => !f.startsWith('\n')), // empty lines
|
||||
(cookies) => cookies.filter((f) => !f.startsWith('# ')), // comments
|
||||
(cookies) => cookies.filter(Boolean), // empty lines
|
||||
A.map(validateCookie),
|
||||
A.mapWithIndex((i, either) =>
|
||||
pipe(
|
||||
either,
|
||||
E.matchW(
|
||||
(l) => toast.push(`Error in line ${i + 1}: ${l}`),
|
||||
() => E.isRight(either),
|
||||
),
|
||||
),
|
||||
),
|
||||
A.filter(Boolean),
|
||||
A.match(
|
||||
() => false,
|
||||
(c) => {
|
||||
toast.push(`Valid ${c.length} Netscape cookies`);
|
||||
return true;
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
const submitCookies = (cookies: string) =>
|
||||
ffetch(`${get(serverApiEndpoint)}/api/v1/cookies`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
cookies,
|
||||
}),
|
||||
})();
|
||||
|
||||
const execute = (cookies: KeyboardEvent) =>
|
||||
pipe(
|
||||
cookies.target as HTMLTextAreaElement,
|
||||
(cookies) => cookies.value,
|
||||
O.fromPredicate(validateNetscapeCookies),
|
||||
O.match(
|
||||
() => cookiesTemplate.set(''),
|
||||
async (cookies) => {
|
||||
pipe(
|
||||
await submitCookies(cookies),
|
||||
E.match(
|
||||
(l) => toast.push(l),
|
||||
() => {
|
||||
toast.push(`Saved Netscape cookies`);
|
||||
cookiesTemplate.set(flag);
|
||||
localStorage.setItem('cookies', cookies);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
</script>
|
||||
|
||||
<textarea
|
||||
cols="80"
|
||||
rows="8"
|
||||
value={cookies}
|
||||
on:keyup={debounce(execute, 500)}
|
||||
/>
|
||||
82
ui/src/lib/DownloadCard.svelte
Normal file
82
ui/src/lib/DownloadCard.svelte
Normal file
@@ -0,0 +1,82 @@
|
||||
<script lang="ts">
|
||||
import { get } from 'svelte/store';
|
||||
import Chip from './Chip.svelte';
|
||||
import type { RPCResult } from './types';
|
||||
import { formatSpeedMiB, mapProcessStatus, roundMiB } from './utils';
|
||||
import { rpcClient } from './store';
|
||||
import Button from './Button.svelte';
|
||||
|
||||
export let download: RPCResult;
|
||||
|
||||
const remove = (id: string) => get(rpcClient).kill(id);
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="flex gap-4
|
||||
bg-neutral-100 dark:bg-neutral-800
|
||||
pt-2 md:p-4
|
||||
rounded-lg shadow-lg
|
||||
border dark:border-neutral-700"
|
||||
>
|
||||
<div
|
||||
class="h-full w-96 bg-cover bg-center rounded"
|
||||
style="background-image: url({download.info.thumbnail})"
|
||||
/>
|
||||
|
||||
<div class="flex flex-col justify-between gap-2 w-full">
|
||||
<div>
|
||||
<h2 class="font-bold text-lg">{download.info.title}</h2>
|
||||
<p
|
||||
class="font-mono text-sm mt-2 p-1 break-all bg-neutral-200 dark:bg-neutral-700 rounded"
|
||||
>
|
||||
{download.info.url}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col justify-end gap-2 select-none flex-wrap">
|
||||
<div class="flex items-center gap-2 text-sm">
|
||||
{#if download.info.vcodec}
|
||||
<Chip text={download.info.vcodec} />
|
||||
{/if}
|
||||
{#if download.info.acodec}
|
||||
<Chip text={download.info.acodec} />
|
||||
{/if}
|
||||
{#if download.info.ext}
|
||||
<Chip text={download.info.ext} />
|
||||
{/if}
|
||||
{#if download.info.resolution}
|
||||
<Chip text={download.info.resolution} />
|
||||
{/if}
|
||||
{#if download.info.filesize_approx}
|
||||
<Chip text={roundMiB(download.info.filesize_approx)} />
|
||||
{/if}
|
||||
{#if download.progress.process_status}
|
||||
<Chip text={mapProcessStatus(download.progress.process_status)} />
|
||||
{/if}
|
||||
{#if download.progress.speed}
|
||||
<Chip text={formatSpeedMiB(download.progress.speed)} />
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<div class="flex gap-2">
|
||||
<Button class="w-14" on:click={() => remove(download.id)}>Stop</Button>
|
||||
{#if download.progress.process_status === 2}
|
||||
<Button class="w-18">Download</Button>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<div
|
||||
class="w-full mt-4 h-2 rounded-full bg-neutral-200 dark:bg-neutral-700"
|
||||
>
|
||||
<div
|
||||
class={`h-2 rounded-full ${
|
||||
download.progress.process_status === 2
|
||||
? 'bg-green-600'
|
||||
: 'bg-orange-500'
|
||||
}`}
|
||||
style="width: {download.progress.percentage}"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
23
ui/src/lib/FloatingAction.svelte
Normal file
23
ui/src/lib/FloatingAction.svelte
Normal file
@@ -0,0 +1,23 @@
|
||||
<script lang="ts">
|
||||
import { Plus } from 'lucide-svelte';
|
||||
</script>
|
||||
|
||||
<div class="absolute bottom-10 right-10">
|
||||
<!-- <div class="relative mb-4 flex flex-col justify-center items-center gap-2">
|
||||
<button
|
||||
class="relative flex items-center justify-center bg-orange-500 h-8 w-8 z-10 rounded-2xl shadow-xl text-neutral-100"
|
||||
>
|
||||
<Plus size={18} />
|
||||
</button>
|
||||
<button
|
||||
class="relative flex items-center justify-center bg-orange-500 h-8 w-8 z-10 rounded-2xl shadow-xl text-neutral-100"
|
||||
>
|
||||
<Plus size={18} />
|
||||
</button>
|
||||
</div> -->
|
||||
<button
|
||||
class="relative bg-orange-500 p-5 z-10 rounded-2xl shadow-xl text-neutral-100"
|
||||
>
|
||||
<Plus />
|
||||
</button>
|
||||
</div>
|
||||
50
ui/src/lib/Footer.svelte
Normal file
50
ui/src/lib/Footer.svelte
Normal file
@@ -0,0 +1,50 @@
|
||||
<script lang="ts">
|
||||
import { ChevronUp, ChevronDown } from 'lucide-svelte';
|
||||
import { cubicOut } from 'svelte/easing';
|
||||
import { tweened } from 'svelte/motion';
|
||||
import Settings from './Settings.svelte';
|
||||
import NewDownload from './NewDownload.svelte';
|
||||
|
||||
const height = tweened(52, {
|
||||
duration: 300,
|
||||
easing: cubicOut,
|
||||
});
|
||||
|
||||
const minHeight = 52;
|
||||
const maxHeight = 600;
|
||||
|
||||
let open = false;
|
||||
$: open = $height > minHeight;
|
||||
</script>
|
||||
|
||||
<footer
|
||||
class="
|
||||
absolute bottom-0
|
||||
w-full
|
||||
p-2
|
||||
bg-neutral-100 dark:bg-neutral-800
|
||||
border-t dark:border-t-neutral-700
|
||||
shadow-lg
|
||||
rounded-t-xl"
|
||||
style="height: {$height}px;"
|
||||
>
|
||||
<button
|
||||
class="p-1 bg-neutral-200 dark:bg-neutral-700 rounded-lg border dark:border-neutral-700"
|
||||
on:click={() => (open ? height.set(minHeight) : height.set(maxHeight))}
|
||||
>
|
||||
{#if open}
|
||||
<ChevronDown />
|
||||
{:else}
|
||||
<ChevronUp />
|
||||
{/if}
|
||||
</button>
|
||||
|
||||
<div />
|
||||
|
||||
{#if $height > 100}
|
||||
<div class="mt-2">
|
||||
<NewDownload />
|
||||
<Settings />
|
||||
</div>
|
||||
{/if}
|
||||
</footer>
|
||||
@@ -1,23 +1,75 @@
|
||||
<script lang="ts">
|
||||
import { rpcClient, serverApiEndpoint } from './store';
|
||||
import { ArrowDownUp, HardDrive, Network } from 'lucide-svelte';
|
||||
import { downloads, rpcClient, serverApiEndpoint } from './store';
|
||||
import { formatGiB, formatSpeedMiB } from './utils';
|
||||
import * as O from 'fp-ts/Option';
|
||||
import { pipe } from 'fp-ts/lib/function';
|
||||
import { onDestroy } from 'svelte';
|
||||
|
||||
let downloadSpeed = 0;
|
||||
|
||||
const unsubscribe = downloads.subscribe((downloads) =>
|
||||
pipe(
|
||||
downloads,
|
||||
O.matchW(
|
||||
() => (downloadSpeed = 0),
|
||||
(d) =>
|
||||
(downloadSpeed = d
|
||||
.map((d) => d.progress.speed)
|
||||
.reduce((a, b) => a + b)),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
onDestroy(unsubscribe);
|
||||
</script>
|
||||
|
||||
<nav
|
||||
class="p-4 flex justify-between items-center bg-neutral-100 rounded-b-lg border shadow-lg"
|
||||
class="
|
||||
p-4
|
||||
flex justify-between items-center
|
||||
bg-neutral-100 dark:bg-neutral-800
|
||||
rounded-b-xl
|
||||
border-b dark:border-b-neutral-700
|
||||
shadow-lg
|
||||
select-none"
|
||||
>
|
||||
<div class="font-semibold">yt-dlp WebUI</div>
|
||||
<div class="font-semibold text-lg">yt-dlp WebUI</div>
|
||||
|
||||
<div />
|
||||
|
||||
<div class="flex gap-2">
|
||||
<div>
|
||||
HDD: {#await $rpcClient.freeSpace()}
|
||||
Loading...
|
||||
{:then freeSpace}
|
||||
{freeSpace.result}
|
||||
{/await}
|
||||
<div class="flex items-center gap-2 text-sm">
|
||||
<div
|
||||
class="flex items-center gap-1.5 p-1 text-neutral-900 bg-orange-200 rounded-lg"
|
||||
>
|
||||
<ArrowDownUp size={18} />
|
||||
<div>
|
||||
{formatSpeedMiB(downloadSpeed)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>RPC: {$serverApiEndpoint.split('//')[1]}</div>
|
||||
<div class="flex items-center gap-2 text-sm">
|
||||
<div
|
||||
class="flex items-center gap-1.5 p-1 text-neutral-900 bg-orange-200 rounded-lg"
|
||||
>
|
||||
<HardDrive size={18} />
|
||||
<div>
|
||||
{#await $rpcClient.freeSpace()}
|
||||
Loading...
|
||||
{:then freeSpace}
|
||||
{formatGiB(freeSpace.result)}
|
||||
{/await}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
class="flex items-center gap-1.5 p-1 text-neutral-900 bg-orange-200 rounded-lg"
|
||||
>
|
||||
<Network size={18} />
|
||||
<div>
|
||||
{$serverApiEndpoint.split('//')[1]}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
21
ui/src/lib/NewDownload.svelte
Normal file
21
ui/src/lib/NewDownload.svelte
Normal file
@@ -0,0 +1,21 @@
|
||||
<script lang="ts">
|
||||
import { get } from 'svelte/store';
|
||||
import Button from './Button.svelte';
|
||||
import TextField from './TextField.svelte';
|
||||
import { rpcClient } from './store';
|
||||
|
||||
let url: string = '';
|
||||
let args: string = '';
|
||||
|
||||
const download = () =>
|
||||
get(rpcClient).download({
|
||||
url,
|
||||
args,
|
||||
});
|
||||
</script>
|
||||
|
||||
<div>
|
||||
<TextField label="url" bind:value={url} />
|
||||
<TextField label="args" bind:value={args} />
|
||||
<Button on:click={download}>Download</Button>
|
||||
</div>
|
||||
13
ui/src/lib/Settings.svelte
Normal file
13
ui/src/lib/Settings.svelte
Normal file
@@ -0,0 +1,13 @@
|
||||
<script lang="ts">
|
||||
import CookiesTextField from './CookiesTextField.svelte';
|
||||
import { rpcHost, rpcPort } from './store';
|
||||
</script>
|
||||
|
||||
<div>
|
||||
<div class="font-semibold text-lg">Settings</div>
|
||||
|
||||
<input type="text" bind:value={$rpcHost} />
|
||||
<input type="text" bind:value={$rpcPort} />
|
||||
|
||||
<CookiesTextField />
|
||||
</div>
|
||||
19
ui/src/lib/Spinner.svelte
Normal file
19
ui/src/lib/Spinner.svelte
Normal file
@@ -0,0 +1,19 @@
|
||||
<div role="status">
|
||||
<svg
|
||||
aria-hidden="true"
|
||||
class="w-8 h-8 text-gray-200 animate-spin dark:text-gray-600 fill-orange-400"
|
||||
viewBox="0 0 100 101"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path
|
||||
d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
|
||||
fill="currentColor"
|
||||
/>
|
||||
<path
|
||||
d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
|
||||
fill="currentFill"
|
||||
/>
|
||||
</svg>
|
||||
<span class="sr-only">Loading...</span>
|
||||
</div>
|
||||
14
ui/src/lib/TextField.svelte
Normal file
14
ui/src/lib/TextField.svelte
Normal file
@@ -0,0 +1,14 @@
|
||||
<script lang="ts">
|
||||
export let label: string;
|
||||
export let value: any;
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col gap-0.5 text-sm">
|
||||
<label for=""> {label} </label>
|
||||
<input
|
||||
type="text"
|
||||
class="p-2 bg-neutral-50 border rounded-lg"
|
||||
on:keyup
|
||||
bind:value
|
||||
/>
|
||||
</div>
|
||||
30
ui/src/lib/ffetch.ts
Normal file
30
ui/src/lib/ffetch.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { tryCatch } from 'fp-ts/TaskEither'
|
||||
|
||||
export const ffetch = <T>(url: string, opt?: RequestInit) => tryCatch(
|
||||
() => fetcher<T>(url, opt),
|
||||
(e) => `error while fetching: ${e}`
|
||||
)
|
||||
|
||||
|
||||
const fetcher = async <T>(url: string, opt?: RequestInit) => {
|
||||
const jwt = localStorage.getItem('token')
|
||||
|
||||
if (opt && !opt.headers) {
|
||||
opt.headers = {
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
}
|
||||
|
||||
const res = await fetch(url, {
|
||||
...opt,
|
||||
headers: {
|
||||
...opt?.headers,
|
||||
'X-Authentication': jwt ?? ''
|
||||
}
|
||||
})
|
||||
|
||||
if (!res.ok) {
|
||||
throw await res.text()
|
||||
}
|
||||
return res.json() as T
|
||||
}
|
||||
@@ -42,4 +42,6 @@ export const rpcClient = derived(
|
||||
/**
|
||||
* Stores all the downloads returned by the rpc
|
||||
*/
|
||||
export const downloads = writable<O.Option<RPCResult[]>>(O.none)
|
||||
export const downloads = writable<O.Option<RPCResult[]>>(O.none)
|
||||
|
||||
export const cookiesTemplate = writable<string>('')
|
||||
@@ -81,4 +81,13 @@ export const base64URLEncode = (s: string) => pipe(
|
||||
s => String.fromCodePoint(...new TextEncoder().encode(s)),
|
||||
btoa,
|
||||
encodeURIComponent
|
||||
)
|
||||
)
|
||||
|
||||
export const debounce = (callback: Function, wait = 300) => {
|
||||
let timeout: ReturnType<typeof setTimeout>
|
||||
|
||||
return (...args: any[]) => {
|
||||
clearTimeout(timeout)
|
||||
timeout = setTimeout(() => callback(...args), wait)
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,7 @@
|
||||
import './app.css'
|
||||
import '@fontsource/roboto'
|
||||
import '@fontsource/roboto/400-italic.css'
|
||||
import '@fontsource/roboto/400.css'
|
||||
import App from './App.svelte'
|
||||
|
||||
const app = new App({
|
||||
|
||||
Reference in New Issue
Block a user