mirror of
https://github.com/Starlio-app/Starlio-web.git
synced 2024-11-24 01:26:22 +03:00
Logs added
This commit is contained in:
parent
35adbe07ff
commit
3b8e630d4a
2 changed files with 33 additions and 34 deletions
|
@ -2,15 +2,14 @@ package controllers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/Redume/EveryNasa/api/utils"
|
"github.com/Redume/EveryNasa/api/utils"
|
||||||
|
"github.com/Redume/EveryNasa/functions"
|
||||||
"github.com/reujab/wallpaper"
|
"github.com/reujab/wallpaper"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
var WallpaperUpdate = func(w http.ResponseWriter, r *http.Request) {
|
var WallpaperUpdate = func(w http.ResponseWriter, r *http.Request) {
|
||||||
var url string
|
var url string
|
||||||
|
|
||||||
url = r.FormValue("url")
|
url = r.FormValue("url")
|
||||||
|
|
||||||
if url == "" {
|
if url == "" {
|
||||||
utils.Respond(w, utils.Message(false, "URL is required"))
|
utils.Respond(w, utils.Message(false, "URL is required"))
|
||||||
return
|
return
|
||||||
|
@ -18,6 +17,6 @@ var WallpaperUpdate = func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
err := wallpaper.SetFromURL(url)
|
err := wallpaper.SetFromURL(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
functions.Logger(err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,24 +2,25 @@ package functions
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/jasonlvhit/gocron"
|
"github.com/jasonlvhit/gocron"
|
||||||
"github.com/reujab/wallpaper"
|
"github.com/reujab/wallpaper"
|
||||||
"github.com/rodkranz/fetch"
|
"github.com/rodkranz/fetch"
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
"os"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetWallpaper() string {
|
func GetWallpaper() string {
|
||||||
file, readErr := os.ReadFile("config.yaml")
|
file, err := os.ReadFile("config.yaml")
|
||||||
if readErr != nil {
|
if err != nil {
|
||||||
panic(readErr)
|
Logger(err.Error())
|
||||||
}
|
}
|
||||||
data := make(map[interface{}]interface{})
|
data := make(map[interface{}]interface{})
|
||||||
|
|
||||||
marshalErr := yaml.Unmarshal(file, &data)
|
err = yaml.Unmarshal(file, &data)
|
||||||
if marshalErr != nil {
|
if err != nil {
|
||||||
panic(marshalErr)
|
Logger(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
type WallpaperStruct struct {
|
type WallpaperStruct struct {
|
||||||
|
@ -29,21 +30,20 @@ func GetWallpaper() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
client := fetch.NewDefault()
|
client := fetch.NewDefault()
|
||||||
res, getErr := client.Get("https://api.nasa.gov/planetary/apod?api_key="+data["apiKey"].(string), nil)
|
res, err := client.Get("https://api.nasa.gov/planetary/apod?api_key="+data["apiKey"].(string), nil)
|
||||||
if getErr != nil {
|
if err != nil {
|
||||||
panic(getErr)
|
Logger(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
body, StringErr := res.ToString()
|
body, err := res.ToString()
|
||||||
if StringErr != nil {
|
if err != nil {
|
||||||
panic(StringErr)
|
Logger(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
var Wallpaper WallpaperStruct
|
var Wallpaper WallpaperStruct
|
||||||
jsonErr := json.Unmarshal([]byte(body), &Wallpaper)
|
err = json.Unmarshal([]byte(body), &Wallpaper)
|
||||||
|
if err != nil {
|
||||||
if jsonErr != nil {
|
Logger(err.Error())
|
||||||
panic(jsonErr)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if Wallpaper.Media_type == "video" {
|
if Wallpaper.Media_type == "video" {
|
||||||
|
@ -57,7 +57,7 @@ func GetWallpaper() string {
|
||||||
func SetWallpaper() {
|
func SetWallpaper() {
|
||||||
err := wallpaper.SetFromURL(GetWallpaper())
|
err := wallpaper.SetFromURL(GetWallpaper())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
Logger(err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,21 +67,20 @@ func StartWallpaper() {
|
||||||
}
|
}
|
||||||
|
|
||||||
client := fetch.NewDefault()
|
client := fetch.NewDefault()
|
||||||
res, getErr := client.Get("http://localhost:8080/api/get/settings", nil)
|
res, err := client.Get("http://localhost:8080/api/get/settings", nil)
|
||||||
if getErr != nil {
|
if err != nil {
|
||||||
panic(getErr)
|
Logger(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
body, StringErr := res.ToString()
|
body, err := res.ToString()
|
||||||
if StringErr != nil {
|
if err != nil {
|
||||||
panic(StringErr)
|
Logger(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
var AutostartSetWallpaper Autostart
|
var AutostartSetWallpaper Autostart
|
||||||
jsonErr := json.Unmarshal([]byte(body), &AutostartSetWallpaper)
|
err = json.Unmarshal([]byte(body), &AutostartSetWallpaper)
|
||||||
|
if err != nil {
|
||||||
if jsonErr != nil {
|
Logger(err.Error())
|
||||||
panic(jsonErr)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if AutostartSetWallpaper.Autochangewallpaper == 1 {
|
if AutostartSetWallpaper.Autochangewallpaper == 1 {
|
||||||
|
@ -90,10 +89,11 @@ func StartWallpaper() {
|
||||||
|
|
||||||
SetWallpaper()
|
SetWallpaper()
|
||||||
|
|
||||||
err := gocron.Every(1).Day().From(&t).Do(SetWallpaper)
|
err = gocron.Every(1).Day().From(&t).Do(SetWallpaper)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
Logger(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
gocron.Start()
|
gocron.Start()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue