ready for 3.2.1
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user