diff --git a/ui/src/lib/RPCClient.ts b/ui/src/lib/RPCClient.ts index e4dee33..366cba9 100644 --- a/ui/src/lib/RPCClient.ts +++ b/ui/src/lib/RPCClient.ts @@ -23,6 +23,9 @@ export class RPCClient { ) } + /** + * Websocket connection + */ public get socket() { return this._socket$ } @@ -61,6 +64,11 @@ export class RPCClient { return data } + /** + * Request a new download. Handles arguments sanitization. + * @param req payload + * @returns + */ public download(req: DownloadRequestArgs) { if (!req.url) { return @@ -105,6 +113,11 @@ export class RPCClient { }) } + /** + * Requests the available formats for a given url (-f arg) + * @param url requested url + * @returns + */ public formats(url: string) { if (url) { return this.sendHTTP({ @@ -116,6 +129,9 @@ export class RPCClient { } } + /** + * Requests all downloads + */ public running() { this.send({ method: 'Service.Running', @@ -123,6 +139,10 @@ export class RPCClient { }) } + /** + * Stops and removes a download asynchronously + * @param id download id + */ public kill(id: string) { this.sendHTTP({ method: 'Service.Kill', @@ -130,6 +150,9 @@ export class RPCClient { }) } + /** + * Stops and removes all downloads + */ public killAll() { this.sendHTTP({ method: 'Service.KillAll', @@ -137,6 +160,10 @@ export class RPCClient { }) } + /** + * Get asynchronously the avaliable space on downloads directory + * @returns free space in bytes + */ public freeSpace() { return this.sendHTTP({ method: 'Service.FreeSpace', @@ -144,6 +171,10 @@ export class RPCClient { }) } + /** + * Get asynchronously the tree view of the download directory + * @returns free space in bytes + */ public directoryTree() { return this.sendHTTP({ method: 'Service.DirectoryTree', @@ -151,6 +182,10 @@ export class RPCClient { }) } + /** + * Updates synchronously yt-dlp executable + * @returns free space in bytes + */ public updateExecutable() { return this.sendHTTP({ method: 'Service.UpdateExecutable', diff --git a/ui/src/lib/store.ts b/ui/src/lib/store.ts index 2745272..b65eecf 100644 --- a/ui/src/lib/store.ts +++ b/ui/src/lib/store.ts @@ -6,8 +6,10 @@ import type { RPCResult } from './types' export const rpcHost = writable(localStorage.getItem('rpcHost') ?? 'localhost') export const rpcPort = writable(Number(localStorage.getItem('rpcPort')) || 3033) +// if authentication is enabled... export const rpcWebToken = writable(localStorage.getItem('rpcWebToken') ?? '') +// will be used to access the api and archive endpoints export const serverApiEndpoint = derived( [rpcHost, rpcPort], ([$host, $port]) => window.location.port == '' @@ -15,6 +17,7 @@ export const serverApiEndpoint = derived( : `${window.location.protocol}//${$host}:${$port}` ) +// access the websocket JSON-RPC 1.0 to gather downloads state export const websocketRpcEndpoint = derived( [rpcHost, rpcPort], ([$host, $port]) => window.location.port == '' @@ -22,14 +25,21 @@ export const websocketRpcEndpoint = derived( : `${window.location.protocol.startsWith('https') ? 'wss:' : 'ws:'}//${$host}:${$port}/rpc/ws` ) +// same as websocket one but using HTTP-POST mainly used to send commands (download, stop, ...) export const httpPostRpcEndpoint = derived( serverApiEndpoint, $ep => window.location.port == '' ? `${$ep}/rpc/http` : `${$ep}/rpc/http` ) +/** + * Will handle Websocket and HTTP-POST communications based on the requested method +*/ export const rpcClient = derived( [httpPostRpcEndpoint, websocketRpcEndpoint, rpcWebToken], ([$http, $ws, $token]) => new RPCClient($http, $ws, $token) ) +/** + * Stores all the downloads returned by the rpc + */ export const downloads = writable>(O.none) \ No newline at end of file