From 1845f3e491b9e161a47c51234617763b4f557ea2 Mon Sep 17 00:00:00 2001 From: marcobaobao Date: Wed, 18 Sep 2024 10:46:56 +0200 Subject: [PATCH] ready for 3.2.1 --- frontend/package.json | 2 +- frontend/src/atoms/status.ts | 12 +++++++---- frontend/src/components/Footer.tsx | 12 ++++------- frontend/src/components/VersionIndicator.tsx | 13 ++++++------ frontend/src/types/index.ts | 7 ++++++- go.mod | 7 ++++--- go.sum | 10 ++++++++++ server/rest/handlers.go | 14 +++++++++++-- server/rest/service.go | 21 +++++++++++--------- 9 files changed, 64 insertions(+), 34 deletions(-) diff --git a/frontend/package.json b/frontend/package.json index cb63148..0e6a56e 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,6 +1,6 @@ { "name": "yt-dlp-webui", - "version": "3.2.0", + "version": "3.2.1", "description": "Frontend compontent of yt-dlp-webui", "scripts": { "dev": "vite", diff --git a/frontend/src/atoms/status.ts b/frontend/src/atoms/status.ts index 2951203..b171fce 100644 --- a/frontend/src/atoms/status.ts +++ b/frontend/src/atoms/status.ts @@ -3,6 +3,7 @@ import { of } from 'fp-ts/lib/Task' import { getOrElse } from 'fp-ts/lib/TaskEither' import { atom, selector } from 'recoil' import { ffetch } from '../lib/httpClient' +import { RPCVersion } from '../types' import { rpcClientState } from './rpc' import { serverURL } from './settings' @@ -29,12 +30,15 @@ export const availableDownloadPathsState = selector({ } }) -export const ytdlpVersionState = selector({ - key: 'ytdlpVersionState', +export const ytdlpRpcVersionState = selector({ + key: 'ytdlpRpcVersionState', get: async ({ get }) => await pipe( - ffetch(`${get(serverURL)}/api/v1/version`), + ffetch(`${get(serverURL)}/api/v1/version`), getOrElse(() => pipe( - 'unknown version', + { + rpcVersion: 'unknown version', + ytdlpVersion: 'unknown version', + }, of )), )() diff --git a/frontend/src/components/Footer.tsx b/frontend/src/components/Footer.tsx index 7b52c47..1d64329 100644 --- a/frontend/src/components/Footer.tsx +++ b/frontend/src/components/Footer.tsx @@ -1,6 +1,6 @@ import DownloadIcon from '@mui/icons-material/Download' import SettingsEthernet from '@mui/icons-material/SettingsEthernet' -import { AppBar, Chip, Divider, Toolbar } from '@mui/material' +import { AppBar, CircularProgress, Divider, Toolbar } from '@mui/material' import { Suspense } from 'react' import { useRecoilValue } from 'recoil' import { settingsState } from '../atoms/settings' @@ -34,13 +34,9 @@ const Footer: React.FC = () => { fontSize: 14, display: 'flex', gap: 1, justifyContent: 'space-between' }}> -
- {/* TODO: make it dynamic */} - - - - -
+ }> + +
{ - const version = useRecoilValue(ytdlpVersionState) + const version = useRecoilValue(ytdlpRpcVersionState) return ( - version - ? - : +
+ + +
) } diff --git a/frontend/src/types/index.ts b/frontend/src/types/index.ts index 9271f1b..6a845d6 100644 --- a/frontend/src/types/index.ts +++ b/frontend/src/types/index.ts @@ -115,4 +115,9 @@ export type LiveStreamProgress = Record \ No newline at end of file +}> + +export type RPCVersion = { + rpcVersion: string + ytdlpVersion: string +} \ No newline at end of file diff --git a/go.mod b/go.mod index b82a98a..b15f98d 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( golang.org/x/sync v0.8.0 golang.org/x/sys v0.25.0 gopkg.in/yaml.v3 v3.0.1 - modernc.org/sqlite v1.32.0 + modernc.org/sqlite v1.33.1 ) require ( @@ -32,9 +32,10 @@ require ( github.com/stretchr/objx v0.5.2 // indirect github.com/stretchr/testify v1.9.0 // indirect github.com/teivah/onecontext v1.3.0 // indirect - golang.org/x/crypto v0.26.0 // indirect + golang.org/x/crypto v0.27.0 // indirect + golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect modernc.org/gc/v3 v3.0.0-20240801135723-a856999a2e4a // indirect - modernc.org/libc v1.60.1 // indirect + modernc.org/libc v1.61.0 // indirect modernc.org/mathutil v1.6.0 // indirect modernc.org/memory v1.8.0 // indirect modernc.org/strutil v1.2.0 // indirect diff --git a/go.sum b/go.sum index cb55842..90834eb 100644 --- a/go.sum +++ b/go.sum @@ -61,10 +61,15 @@ go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw= golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54= +golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A= +golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70= +golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 h1:e66Fs6Z+fZTbFBAxKfP3PALWBtpfqks2bwGcexMxgtk= +golang.org/x/exp v0.0.0-20240909161429-701f63a606c0/go.mod h1:2TbTHSBQa924w8M6Xs1QcRcFwyucIwBGpK1p2f1YFFY= golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs= golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/mod v0.19.0 h1:fEdghXQSo20giMthA7cd28ZC+jts4amQ3YMXiP5oMQ8= golang.org/x/mod v0.19.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/oauth2 v0.22.0 h1:BzDx2FehcG7jJwgWLELCdmLuxk2i+x9UDpSiss2u0ZA= @@ -86,6 +91,7 @@ golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3 golang.org/x/tools v0.0.0-20191108193012-7d206e10da11/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.23.0 h1:SGsXPZ+2l4JsgaCKkx+FQ9YZ5XEtA1GZYuoDjenLjvg= golang.org/x/tools v0.23.0/go.mod h1:pnu6ufv6vQkll6szChhK3C3L/ruaIv5eBeztNG8wtsI= +golang.org/x/tools v0.25.0 h1:oFU9pkj/iJgs+0DT+VMHrx+oBKs/LJMV+Uvg78sl+fE= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= @@ -108,6 +114,8 @@ modernc.org/libc v1.59.9 h1:k+nNDDakwipimgmJ1D9H466LhFeSkaPPycAs1OZiDmY= modernc.org/libc v1.59.9/go.mod h1:EY/egGEU7Ju66eU6SBqCNYaFUDuc4npICkMWnU5EE3A= modernc.org/libc v1.60.1 h1:at373l8IFRTkJIkAU85BIuUoBM4T1b51ds0E1ovPG2s= modernc.org/libc v1.60.1/go.mod h1:xJuobKuNxKH3RUatS7GjR+suWj+5c2K7bi4m/S5arOY= +modernc.org/libc v1.61.0 h1:eGFcvWpqlnoGwzZeZe3PWJkkKbM/3SUGyk1DVZQ0TpE= +modernc.org/libc v1.61.0/go.mod h1:DvxVX89wtGTu+r72MLGhygpfi3aUGgZRdAYGCAVVud0= modernc.org/mathutil v1.6.0 h1:fRe9+AmYlaej+64JsEEhoWuAYBkOtQiMEU7n/XgfYi4= modernc.org/mathutil v1.6.0/go.mod h1:Ui5Q9q1TR2gFm0AQRqQUaBWFLAhQpCwNcuhBOSedWPo= modernc.org/memory v1.8.0 h1:IqGTL6eFMaDZZhEWwcREgeMXYwmW83LYW8cROZYkg+E= @@ -118,6 +126,8 @@ modernc.org/sortutil v1.2.0 h1:jQiD3PfS2REGJNzNCMMaLSp/wdMNieTbKX920Cqdgqc= modernc.org/sortutil v1.2.0/go.mod h1:TKU2s7kJMf1AE84OoiGppNHJwvB753OYfNl2WRb++Ss= modernc.org/sqlite v1.32.0 h1:6BM4uGza7bWypsw4fdLRsLxut6bHe4c58VeqjRgST8s= modernc.org/sqlite v1.32.0/go.mod h1:UqoylwmTb9F+IqXERT8bW9zzOWN8qwAIcLdzeBZs4hA= +modernc.org/sqlite v1.33.1 h1:trb6Z3YYoeM9eDL1O8do81kP+0ejv+YzgyFo+Gwy0nM= +modernc.org/sqlite v1.33.1/go.mod h1:pXV2xHxhzXZsgT/RtTFAPY6JJDEvOTcTdwADQCCWD4k= modernc.org/strutil v1.2.0 h1:agBi9dp1I+eOnxXeiZawM8F4LawKv4NzGWSaLfyeNZA= modernc.org/strutil v1.2.0/go.mod h1:/mdcBmfOibveCTBxUl5B5l6W+TTH1FXPLHZE6bTosX0= modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y= diff --git a/server/rest/handlers.go b/server/rest/handlers.go index c78e40a..95b14a4 100644 --- a/server/rest/handlers.go +++ b/server/rest/handlers.go @@ -243,18 +243,28 @@ func (h *Handler) DeleteTemplate() http.HandlerFunc { } func (h *Handler) GetVersion() http.HandlerFunc { + type Response struct { + RPCVersion string `json:"rpcVersion"` + YtdlpVersion string `json:"ytdlpVersion"` + } + return func(w http.ResponseWriter, r *http.Request) { defer r.Body.Close() w.Header().Set("Content-Type", "application/json") - version, err := h.service.GetVersion(r.Context()) + rpcVersion, ytdlpVersion, err := h.service.GetVersion(r.Context()) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } - if err := json.NewEncoder(w).Encode(version); err != nil { + res := Response{ + RPCVersion: rpcVersion, + YtdlpVersion: ytdlpVersion, + } + + if err := json.NewEncoder(w).Encode(res); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) } } diff --git a/server/rest/service.go b/server/rest/service.go index 0c1e5fa..ce82d95 100644 --- a/server/rest/service.go +++ b/server/rest/service.go @@ -146,22 +146,25 @@ func (s *Service) DeleteTemplate(ctx context.Context, id string) error { return err } -func (s *Service) GetVersion(ctx context.Context) (string, error) { - ch := make(chan string, 1) +func (s *Service) GetVersion(ctx context.Context) (string, string, error) { + //TODO: load from realease properties file, or anything else outside code + const CURRENT_RPC_VERSION = "3.2.1" - c, cancel := context.WithTimeout(ctx, time.Second*10) + result := make(chan string, 1) + + ctx, cancel := context.WithTimeout(ctx, time.Second*10) defer cancel() - cmd := exec.CommandContext(c, config.Instance().DownloaderPath, "--version") + cmd := exec.CommandContext(ctx, config.Instance().DownloaderPath, "--version") go func() { stdout, _ := cmd.Output() - ch <- string(stdout) + result <- string(stdout) }() select { - case <-c.Done(): - return "", errors.New("requesting yt-dlp version took too long") - case res := <-ch: - return res, nil + case <-ctx.Done(): + return CURRENT_RPC_VERSION, "", errors.New("requesting yt-dlp version took too long") + case res := <-result: + return CURRENT_RPC_VERSION, res, nil } }