diff --git a/api/controllers/favorite.go b/api/controllers/favorite.go index 8105554..8c89c91 100644 --- a/api/controllers/favorite.go +++ b/api/controllers/favorite.go @@ -2,8 +2,7 @@ package controllers import ( "database/sql" - "github.com/Redume/EveryNasa/api/utils" - "github.com/Redume/EveryNasa/functions" + "github.com/Redume/EveryNasa/utils" "github.com/gofiber/fiber/v2" ) @@ -21,25 +20,25 @@ var GetFavorites = func(c *fiber.Ctx) error { } var title, explanation, copyright, date, url, hdurl, media_type string - db := functions.GetDatabase() + db := utils.GetDatabase() if FavoriteTitle != "" { queryFavorites, err := db.Query("SELECT * FROM favorite WHERE title LIKE ?", FavoriteTitle) if err != nil { - functions.Logger(err.Error()) + utils.Logger(err.Error()) } defer func(query *sql.Rows) { err := query.Close() if err != nil { - functions.Logger(err.Error()) + utils.Logger(err.Error()) } }(queryFavorites) for queryFavorites.Next() { err := queryFavorites.Scan(&title, &explanation, ©right, &date, &url, &hdurl, &media_type) if err != nil { - functions.Logger(err.Error()) + utils.Logger(err.Error()) } return c.JSON(fiber.Map{ @@ -55,13 +54,13 @@ var GetFavorites = func(c *fiber.Ctx) error { } else { queryFavorite, err := db.Query("SELECT * FROM favorite") if err != nil { - functions.Logger(err.Error()) + utils.Logger(err.Error()) } defer func(query *sql.Rows) { err := query.Close() if err != nil { - functions.Logger(err.Error()) + utils.Logger(err.Error()) } }(queryFavorite) @@ -69,7 +68,7 @@ var GetFavorites = func(c *fiber.Ctx) error { for queryFavorite.Next() { err := queryFavorite.Scan(&title, &explanation, ©right, &date, &url, &hdurl, &media_type) if err != nil { - functions.Logger(err.Error()) + utils.Logger(err.Error()) } favorites = append(favorites, Favorite{ @@ -102,7 +101,7 @@ var AddFavorite = func(c *fiber.Ctx) error { return nil } - db := functions.GetDatabase() + db := utils.GetDatabase() _, err := db.Exec("INSERT INTO favorite (title, explanation, copyright, date, url, hdurl, media_type) VALUES (?, ?, ?, ?, ?, ?, ?)", title, @@ -114,7 +113,7 @@ var AddFavorite = func(c *fiber.Ctx) error { media_type) if err != nil { - functions.Logger(err.Error()) + utils.Logger(err.Error()) } utils.Respond(c, utils.Message(true, "Favorite added")) @@ -124,11 +123,11 @@ var AddFavorite = func(c *fiber.Ctx) error { var DeleteFavorite = func(c *fiber.Ctx) error { title := c.FormValue("title") - db := functions.GetDatabase() + db := utils.GetDatabase() _, err := db.Exec("DELETE FROM favorite WHERE title = ?", title) if err != nil { - functions.Logger(err.Error()) + utils.Logger(err.Error()) } utils.Respond(c, utils.Message(true, "Favorite deleted")) diff --git a/api/controllers/settings.go b/api/controllers/settings.go index 8ba7a82..4482c00 100644 --- a/api/controllers/settings.go +++ b/api/controllers/settings.go @@ -2,8 +2,7 @@ package controllers import ( "database/sql" - "github.com/Redume/EveryNasa/api/utils" - "github.com/Redume/EveryNasa/functions" + "github.com/Redume/EveryNasa/utils" "github.com/gofiber/fiber/v2" _ "github.com/mattn/go-sqlite3" ) @@ -11,35 +10,35 @@ import ( var SettingsGet = func(c *fiber.Ctx) error { db, err := sql.Open("sqlite3", "EveryNasa.db") if err != nil { - functions.Logger(err.Error()) + utils.Logger(err.Error()) } querySettings, err := db.Query("SELECT * FROM settings") if err != nil { - functions.Logger(err.Error()) + utils.Logger(err.Error()) } defer func(query *sql.Rows) { err := query.Close() if err != nil { - functions.Logger(err.Error()) + utils.Logger(err.Error()) } }(querySettings) - var startup, wallpaper, save_logg, analytics int + var startup, wallpaper, save_logg int for querySettings.Next() { - err := querySettings.Scan(&startup, &wallpaper, &save_logg, &analytics) + err := querySettings.Scan(&startup, &wallpaper, &save_logg) if err != nil { - functions.Logger(err.Error()) + utils.Logger(err.Error()) } var data = map[string]interface{}{ "startup": startup, "wallpaper": wallpaper, "save_logg": save_logg, - "analytics": analytics} + } utils.Respond(c, data) } @@ -50,15 +49,14 @@ var SettingsGet = func(c *fiber.Ctx) error { var SettingsUpdate = func(c *fiber.Ctx) error { db, err := sql.Open("sqlite3", "EveryNasa.db") if err != nil { - functions.Logger(err.Error()) + utils.Logger(err.Error()) } startup := c.FormValue("startup") wallpaper := c.FormValue("wallpaper") save_logg := c.FormValue("save_logg") - analytics := c.FormValue("analytics") - if startup == "" && wallpaper == "" && save_logg == "" && analytics == "" { + if startup == "" && wallpaper == "" && save_logg == "" { utils.Respond(c, utils.Message(false, "All fields are required.")) return nil } @@ -66,32 +64,25 @@ var SettingsUpdate = func(c *fiber.Ctx) error { if wallpaper != "" { _, err := db.Exec("UPDATE settings SET wallpaper = ?", wallpaper) if err != nil { - functions.Logger(err.Error()) + utils.Logger(err.Error()) } if wallpaper == "1" { - go functions.StartWallpaper() + go utils.StartWallpaper() } } if startup != "" { _, err := db.Exec("UPDATE settings SET startup = ?", startup) if err != nil { - functions.Logger(err.Error()) + utils.Logger(err.Error()) } } if save_logg != "" { _, err := db.Exec("UPDATE settings SET save_logg = ?", save_logg) if err != nil { - functions.Logger(err.Error()) - } - } - - if analytics != "" { - _, err := db.Exec("UPDATE settings SET analytics = ?", analytics) - if err != nil { - functions.Logger(err.Error()) + utils.Logger(err.Error()) } } diff --git a/api/controllers/startup.go b/api/controllers/startup.go index 749dab7..e31b0f2 100644 --- a/api/controllers/startup.go +++ b/api/controllers/startup.go @@ -6,8 +6,7 @@ import ( "os/user" "strings" - "github.com/Redume/EveryNasa/api/utils" - "github.com/Redume/EveryNasa/functions" + "github.com/Redume/EveryNasa/utils" ) var Startup = func(c *fiber.Ctx) error { @@ -32,19 +31,19 @@ var Startup = func(c *fiber.Ctx) error { var SetStartup = func(c *fiber.Ctx) error { u, err := user.Current() if err != nil { - functions.Logger(err.Error()) + utils.Logger(err.Error()) } dir, err := os.Getwd() if err != nil { - functions.Logger(err.Error()) + utils.Logger(err.Error()) } dir = strings.Replace(dir, "\\", "\\\\", -1) + "\\EveryNasa.exe" - err = functions.CreateLnk(dir, strings.Replace(u.HomeDir, "\\", "\\\\", -1)+"\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\EveryNasa.lnk") + err = utils.CreateLnk(dir, strings.Replace(u.HomeDir, "\\", "\\\\", -1)+"\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\EveryNasa.lnk") if err != nil { - functions.Logger(err.Error()) + utils.Logger(err.Error()) } utils.Respond(c, utils.Message(true, "The settings have been applied successfully.")) @@ -54,12 +53,12 @@ var SetStartup = func(c *fiber.Ctx) error { var RemoveStartup = func(c *fiber.Ctx) error { u, err := user.Current() if err != nil { - functions.Logger(err.Error()) + utils.Logger(err.Error()) } err = os.Remove(strings.Replace(u.HomeDir, "\\", "\\\\", -1) + "\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\EveryNasa.lnk") if err != nil { - functions.Logger(err.Error()) + utils.Logger(err.Error()) } utils.Respond(c, utils.Message(true, "The settings have been applied successfully.")) diff --git a/api/controllers/wallpaper.go b/api/controllers/wallpaper.go index 4f4a73a..026c657 100644 --- a/api/controllers/wallpaper.go +++ b/api/controllers/wallpaper.go @@ -1,8 +1,7 @@ package controllers import ( - "github.com/Redume/EveryNasa/api/utils" - "github.com/Redume/EveryNasa/functions" + "github.com/Redume/EveryNasa/utils" "github.com/gofiber/fiber/v2" "github.com/reujab/wallpaper" ) @@ -17,7 +16,7 @@ var WallpaperUpdate = func(c *fiber.Ctx) error { err := wallpaper.SetFromURL(url) if err != nil { - functions.Logger(err.Error()) + utils.Logger(err.Error()) utils.Respond(c, utils.Message(false, "An error occurred while setting the wallpaper")) return nil } diff --git a/functions/connect.go b/utils/connect.go similarity index 90% rename from functions/connect.go rename to utils/connect.go index 8e955d3..8a49a20 100644 --- a/functions/connect.go +++ b/utils/connect.go @@ -1,4 +1,4 @@ -package functions +package utils import "net/http" diff --git a/functions/createLnk.go b/utils/createLnk.go similarity index 98% rename from functions/createLnk.go rename to utils/createLnk.go index 1ba2ed0..88e4cd7 100644 --- a/functions/createLnk.go +++ b/utils/createLnk.go @@ -1,4 +1,4 @@ -package functions +package utils import ( "os" diff --git a/functions/database.go b/utils/database.go similarity index 88% rename from functions/database.go rename to utils/database.go index f24e5e9..616051a 100644 --- a/functions/database.go +++ b/utils/database.go @@ -1,4 +1,4 @@ -package functions +package utils import ( "database/sql" @@ -16,8 +16,7 @@ func Database() { CREATE TABLE IF NOT EXISTS settings ( startup INTEGER DEFAULT 0, wallpaper INTEGER DEFAULT 0, - save_logg INTEGER DEFAULT 1, - analytics INTEGER DEFAULT 1 + save_logg INTEGER DEFAULT 1 );` _, err = db.Exec(sqlTable) @@ -25,12 +24,12 @@ func Database() { Logger(err.Error()) } - stmt, err := db.Prepare("INSERT INTO settings(startup, wallpaper, save_logg, analytics) values(?,?,?,?)") + stmt, err := db.Prepare("INSERT INTO settings(startup, wallpaper, save_logg) values(?,?,?)") if err != nil { Logger(err.Error()) } - _, err = stmt.Exec(0, 0, 1, 1) + _, err = stmt.Exec(0, 0, 1) if err != nil { Logger(err.Error()) } diff --git a/api/utils/utils.go b/utils/respondAPI.go similarity index 83% rename from api/utils/utils.go rename to utils/respondAPI.go index aad7ac4..3a9f6ff 100644 --- a/api/utils/utils.go +++ b/utils/respondAPI.go @@ -3,7 +3,6 @@ package utils import ( "encoding/json" - "github.com/Redume/EveryNasa/functions" "github.com/gofiber/fiber/v2" ) @@ -15,6 +14,6 @@ func Respond(c *fiber.Ctx, data map[string]interface{}) { c.Set("Content-Type", "application/json") err := json.NewEncoder(c).Encode(data) if err != nil { - functions.Logger(err.Error()) + Logger(err.Error()) } } diff --git a/functions/wallpaper.go b/utils/wallpaper.go similarity index 99% rename from functions/wallpaper.go rename to utils/wallpaper.go index f376b41..8afeb9d 100644 --- a/functions/wallpaper.go +++ b/utils/wallpaper.go @@ -1,4 +1,4 @@ -package functions +package utils import ( "encoding/json"