From 2efe6cc0d0bdf37276f4d8444ce00853fe2aeba1 Mon Sep 17 00:00:00 2001 From: Maxence Lallemand Date: Sun, 18 Aug 2024 16:27:26 +0200 Subject: [PATCH 1/2] feat: add marquee reader from server --- common/config.go | 1 + config-example.xml | 1 + first/addition.go | 22 ++++++++++++++++++++-- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/common/config.go b/common/config.go index f3648f0..3a2b99b 100644 --- a/common/config.go +++ b/common/config.go @@ -13,6 +13,7 @@ type Config struct { DatabaseName string `xml:"databaseName"` Address string `xml:"address"` AssetsPath string `xml:"assetsPath"` + ServerURL string `xml:"serverURL"` } func CheckError(err error) { diff --git a/config-example.xml b/config-example.xml index 243bada..30150ed 100644 --- a/config-example.xml +++ b/config-example.xml @@ -12,4 +12,5 @@ mc-assets + http://localhost:9011 \ No newline at end of file diff --git a/first/addition.go b/first/addition.go index 5e1a60c..7c121d0 100644 --- a/first/addition.go +++ b/first/addition.go @@ -5,8 +5,11 @@ import ( _ "embed" "encoding/json" "fmt" - "github.com/WiiLink24/MiiContestChannel/common" + "io" "math" + "net/http" + + "github.com/WiiLink24/MiiContestChannel/common" ) type Root struct { @@ -123,7 +126,22 @@ func (l *Languages) GetLanguageFromJSON(language uint32) *Entry { } func MakeAddition() error { - marqueeText := []byte("WiiLink Mii Contest Channel!!!!") + var marqueeText []byte + + resp, error := http.Get(common.GetConfig().ServerURL + "/assets/marquee/marquee.txt") + if error != nil { + marqueeText = []byte("WiiLink Mii Contest Channel!!!!") + } else { + defer resp.Body.Close() + + body, err := io.ReadAll(resp.Body) + if err != nil { + marqueeText = []byte("WiiLink Mii Contest Channel!!!!") + } else { + marqueeText = body + } + } + var actual [1536]byte copy(actual[:], marqueeText) From ab00691921741548aff6c32c082e43bd2af78a56 Mon Sep 17 00:00:00 2001 From: Maxence Lallemand Date: Tue, 20 Aug 2024 10:22:39 +0200 Subject: [PATCH 2/2] refactor: add a global variable for failed marquee fetching --- first/addition.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/first/addition.go b/first/addition.go index 7c121d0..28016ea 100644 --- a/first/addition.go +++ b/first/addition.go @@ -127,16 +127,17 @@ func (l *Languages) GetLanguageFromJSON(language uint32) *Entry { func MakeAddition() error { var marqueeText []byte + var baseText = []byte("WiiLink Mii Contest Channel!!!!") resp, error := http.Get(common.GetConfig().ServerURL + "/assets/marquee/marquee.txt") if error != nil { - marqueeText = []byte("WiiLink Mii Contest Channel!!!!") + marqueeText = baseText } else { defer resp.Body.Close() body, err := io.ReadAll(resp.Body) if err != nil { - marqueeText = []byte("WiiLink Mii Contest Channel!!!!") + marqueeText = baseText } else { marqueeText = body }