#1 - Created request to check newest version of the app
All checks were successful
Build / build (push) Successful in 2m35s
All checks were successful
Build / build (push) Successful in 2m35s
#2 - Added request to download the newest version of the app #3 - Added request to check progress during sync #4 - Now blocking all request while sync is in progress #5 - Implemented ants for thread pooling #6 - Changed the sync request to now only start the sync
This commit is contained in:
106
internal/backend/download.go
Normal file
106
internal/backend/download.go
Normal file
@@ -0,0 +1,106 @@
|
||||
package backend
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type giteaResponse struct {
|
||||
Id int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Assets []assetResponse `json:"assets"`
|
||||
}
|
||||
|
||||
type assetResponse struct {
|
||||
Id int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
DownloadUrl string `json:"browser_download_url"`
|
||||
}
|
||||
|
||||
func CheckLatest() string {
|
||||
resp, err := http.Get("https://gitea.sanplex.tech/api/v1/repos/sansan/MusicPlayer/releases/latest")
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
//Create a variable of the same type as our model
|
||||
var cResp giteaResponse
|
||||
//Decode the data
|
||||
if err := json.NewDecoder(resp.Body).Decode(&cResp); err != nil {
|
||||
fmt.Println(err)
|
||||
log.Fatal("ooopsss! an error occurred, please try again")
|
||||
}
|
||||
log.Printf("Id: %v, Name: %v", cResp.Id, cResp.Name)
|
||||
return cResp.Name
|
||||
}
|
||||
|
||||
func ListAssetsOfLatest() []string {
|
||||
resp, err := http.Get("https://gitea.sanplex.tech/api/v1/repos/sansan/MusicPlayer/releases/latest")
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
//Create a variable of the same type as our model
|
||||
var cResp giteaResponse
|
||||
//Decode the data
|
||||
if err := json.NewDecoder(resp.Body).Decode(&cResp); err != nil {
|
||||
fmt.Println(err)
|
||||
log.Fatal("ooopsss! an error occurred, please try again")
|
||||
}
|
||||
log.Printf("Id: %v, Name: %v", cResp.Id, cResp.Name)
|
||||
var assets []string
|
||||
for _, asset := range cResp.Assets {
|
||||
log.Printf("Id: %v, Name: %v, Asset: %v", cResp.Id, cResp.Name, asset.Name)
|
||||
assets = append(assets, asset.Name)
|
||||
}
|
||||
return assets
|
||||
}
|
||||
|
||||
func DownloadLatestWindows() string {
|
||||
resp, err := http.Get("https://gitea.sanplex.tech/api/v1/repos/sansan/MusicPlayer/releases/latest")
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
//Create a variable of the same type as our model
|
||||
var cResp giteaResponse
|
||||
//Decode the data
|
||||
if err := json.NewDecoder(resp.Body).Decode(&cResp); err != nil {
|
||||
fmt.Println(err)
|
||||
log.Fatal("ooopsss! an error occurred, please try again")
|
||||
}
|
||||
log.Printf("Id: %v, Name: %v", cResp.Id, cResp.Name)
|
||||
for _, asset := range cResp.Assets {
|
||||
log.Printf("Id: %v, Name: %v, Asset: %v", cResp.Id, cResp.Name, asset.Name)
|
||||
if strings.HasSuffix(asset.Name, ".exe") {
|
||||
return asset.DownloadUrl
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func DownloadLatestLinux() string {
|
||||
resp, err := http.Get("https://gitea.sanplex.tech/api/v1/repos/sansan/MusicPlayer/releases/latest")
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
//Create a variable of the same type as our model
|
||||
var cResp giteaResponse
|
||||
//Decode the data
|
||||
if err := json.NewDecoder(resp.Body).Decode(&cResp); err != nil {
|
||||
fmt.Println(err)
|
||||
log.Fatal("ooopsss! an error occurred, please try again")
|
||||
}
|
||||
log.Printf("Id: %v, Name: %v", cResp.Id, cResp.Name)
|
||||
for _, asset := range cResp.Assets {
|
||||
log.Printf("Id: %v, Name: %v, Asset: %v", cResp.Id, cResp.Name, asset.Name)
|
||||
if strings.HasSuffix(asset.Name, ".x86_64") {
|
||||
return asset.DownloadUrl
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
Reference in New Issue
Block a user