Rex model
This commit is contained in:
parent
8dea74d4a0
commit
7b4fb82ab7
4 changed files with 93 additions and 1 deletions
3
rex_model/go.mod
Normal file
3
rex_model/go.mod
Normal file
|
@ -0,0 +1,3 @@
|
|||
module rex_model
|
||||
|
||||
go 1.23.5
|
35
rex_model/index.go
Normal file
35
rex_model/index.go
Normal file
|
@ -0,0 +1,35 @@
|
|||
package rex_model
|
||||
|
||||
// TODO: Remove
|
||||
var AddonIndex = []string{
|
||||
"AtlasLoot",
|
||||
"Bartender4",
|
||||
"Deadly Boss Mods",
|
||||
"Details! Damage Meter",
|
||||
"WeakAuras",
|
||||
"ElvUI",
|
||||
"BigWigs",
|
||||
"Recount",
|
||||
"GatherMate2",
|
||||
"TomTom",
|
||||
"Questie",
|
||||
"TradeSkillMaster",
|
||||
"HandyNotes",
|
||||
"Bagnon",
|
||||
"Threat Plates",
|
||||
"GTFO",
|
||||
"Plater Nameplates",
|
||||
"Rarity",
|
||||
"Pawn",
|
||||
"Auctioneer",
|
||||
"Shadowed Unit Frames",
|
||||
"SexyMap",
|
||||
"TidyPlates",
|
||||
"MoveAnything",
|
||||
"Postal",
|
||||
"OmniCC",
|
||||
"Leatrix Plus",
|
||||
"SimulationCraft",
|
||||
"VuhDo",
|
||||
"KuiNameplates",
|
||||
}
|
54
rex_model/repo.go
Normal file
54
rex_model/repo.go
Normal file
|
@ -0,0 +1,54 @@
|
|||
package rex_model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type Repo interface {
|
||||
GetLatestTag() (Tag, error)
|
||||
}
|
||||
|
||||
// Currently only for github
|
||||
type GithubRepo struct {
|
||||
Owner string `json:"owner"`
|
||||
Repo string `json:"repo"`
|
||||
}
|
||||
|
||||
func (r GithubRepo) GetLatestTag() (Tag, error) {
|
||||
url := fmt.Sprintf("https://api.github.com/repos/%s/%s/tags", r.Owner, r.Repo)
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
log.Printf("Failed to fetch releases for %s/%s: %v", r.Owner, r.Repo, err)
|
||||
return Tag{}, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
log.Printf("Unexpected response status for %s/%s: %d", r.Owner, r.Repo, resp.StatusCode)
|
||||
return Tag{}, fmt.Errorf("unexpected response status: %d", resp.StatusCode)
|
||||
}
|
||||
|
||||
var tags = []Tag{}
|
||||
if err := json.NewDecoder(resp.Body).Decode(&tags); err != nil {
|
||||
log.Printf("Failed to decode response for %s/%s: %v", r.Owner, r.Repo, err)
|
||||
return Tag{}, err
|
||||
}
|
||||
|
||||
return tags[0], nil
|
||||
}
|
||||
|
||||
type Commit struct {
|
||||
Sha string `json:"sha"`
|
||||
URL string `json:"url"`
|
||||
}
|
||||
|
||||
type Tag struct {
|
||||
Name string `json:"name"`
|
||||
ZipballURL string `json:"zipball_url"`
|
||||
TarballURL string `json:"tarball_url"`
|
||||
Commit Commit `json:"commit"`
|
||||
NodeID string `json:"node_id"`
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package model
|
||||
package rex_model
|
||||
|
||||
// Recieved from the client
|
||||
type UpdateCheck struct {
|
||||
|
|
Loading…
Add table
Reference in a new issue