Add News widget and integrate NewsAPI for live updates

This commit is contained in:
2025-12-29 21:19:05 +01:00
parent d638a8ae97
commit 9b5afc3d7c
9 changed files with 260 additions and 38 deletions

View File

@@ -4,7 +4,6 @@ import (
"ArinDash/config"
"encoding/json"
"io"
"log"
"net/http"
"strings"
)
@@ -50,7 +49,7 @@ func (ph *PiHConnector) do(method string, endpoint string, body io.Reader) []byt
req, err := http.NewRequest(method, requestString, body)
if err != nil {
log.Fatal(err)
return make([]byte, 0)
}
req.Header.Add("X-FTL-SID", ph.Session.SID)
@@ -58,13 +57,13 @@ func (ph *PiHConnector) do(method string, endpoint string, body io.Reader) []byt
resp, err := client.Do(req)
if err != nil {
log.Fatal(err)
return make([]byte, 0)
}
defer resp.Body.Close()
respBody, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
return make([]byte, 0)
}
return respBody
@@ -82,24 +81,24 @@ func Connect() PiHConnector {
req, err := http.NewRequest("POST", "http://"+cfg.Pihole.Host+"/api/auth", strings.NewReader("{\"password\": \""+cfg.Pihole.Password+"\"}"))
if err != nil {
log.Fatal(err)
panic(err)
}
resp, err := client.Do(req)
if err != nil {
log.Fatal(err)
panic(err)
}
defer resp.Body.Close()
respBody, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
panic(err)
}
s := &PiHAuth{}
err = json.Unmarshal(respBody, s)
if err != nil {
log.Fatal(err)
panic(err)
}
connector = &PiHConnector{
Host: cfg.Pihole.Host,