it just works
This commit is contained in:
45
server/updater/forced_update.go
Normal file
45
server/updater/forced_update.go
Normal 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
6
server/updater/types.go
Normal 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
17
server/updater/update.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user