it just works

This commit is contained in:
2023-01-12 12:05:53 +01:00
parent 4c7faa1b46
commit 733e2ab006
54 changed files with 336 additions and 3608 deletions

View File

@@ -0,0 +1,45 @@
package updater
import (
"io"
"log"
"net/http"
"github.com/goccy/go-json"
)
const (
gitHubAPILatest = "https://api.github.com/repos/yt-dlp/yt-dlp/releases/latest"
gitHubAPIDownload = "https://api.github.com/repos/yt-dlp/yt-dlp/releases/download"
)
var (
client = &http.Client{
CheckRedirect: http.DefaultClient.CheckRedirect,
}
)
func getLatestReleaseTag() (string, error) {
res, err := client.Get(gitHubAPILatest)
if err != nil {
log.Println("Cannot get release tag from GitHub API")
return "", err
}
defer res.Body.Close()
body, err := io.ReadAll(res.Body)
if err != nil {
log.Println("Cannot parse response from GitHub API")
return "", err
}
tag := ReleaseLatestResponse{}
json.Unmarshal(body, &tag)
return tag.TagName, nil
}
func ForceUpdate() {
getLatestReleaseTag()
}

6
server/updater/types.go Normal file
View File

@@ -0,0 +1,6 @@
package updater
type ReleaseLatestResponse struct {
Name string `json:"name"`
TagName string `json:"tag_name"`
}

17
server/updater/update.go Normal file
View File

@@ -0,0 +1,17 @@
package updater
import (
"os/exec"
"github.com/marcopeocchi/yt-dlp-web-ui/server/config"
)
var path = config.Instance().GetConfig().DownloaderPath
func UpdateExecutable() error {
cmd := exec.Command(path, "-U")
cmd.Start()
err := cmd.Wait()
return err
}