From 853ab9bd8aae178b32cc2191d49352895df4a541 Mon Sep 17 00:00:00 2001 From: Redume Date: Wed, 2 Nov 2022 20:53:09 +0300 Subject: [PATCH] Delete api directory --- api/controllers/label.go | 33 --------------- api/controllers/settings.go | 78 ------------------------------------ api/controllers/startup.go | 67 ------------------------------- api/controllers/wallpaper.go | 28 ------------- api/utils/utils.go | 20 --------- 5 files changed, 226 deletions(-) delete mode 100644 api/controllers/label.go delete mode 100644 api/controllers/settings.go delete mode 100644 api/controllers/startup.go delete mode 100644 api/controllers/wallpaper.go delete mode 100644 api/utils/utils.go diff --git a/api/controllers/label.go b/api/controllers/label.go deleted file mode 100644 index 4e1b18e..0000000 --- a/api/controllers/label.go +++ /dev/null @@ -1,33 +0,0 @@ -package controllers - -import ( - "os" - "os/user" - "strings" - - "github.com/Redume/EveryNasa/api/utils" - "github.com/Redume/EveryNasa/functions" - "github.com/gofiber/fiber/v2" -) - -var CreateLabel = func(c *fiber.Ctx) error { - u, err := user.Current() - if err != nil { - functions.Logger(err.Error()) - } - - dir, err := os.Getwd() - if err != nil { - functions.Logger(err.Error()) - } - - dir = strings.Replace(dir, "\\", "\\\\", -1) + "\\EveryNasa.exe" - - err = functions.CreateLnk(dir, strings.Replace(u.HomeDir, "\\", "\\\\", -1)+"\\Desktop\\EveryNasa.lnk") - if err != nil { - functions.Logger(err.Error()) - } - - utils.Respond(c, utils.Message(true, "The shortcut was successfully created")) - return nil -} diff --git a/api/controllers/settings.go b/api/controllers/settings.go deleted file mode 100644 index 63270f2..0000000 --- a/api/controllers/settings.go +++ /dev/null @@ -1,78 +0,0 @@ -package controllers - -import ( - "database/sql" - "github.com/Redume/EveryNasa/api/utils" - "github.com/Redume/EveryNasa/functions" - "github.com/gofiber/fiber/v2" - _ "github.com/mattn/go-sqlite3" -) - -var SettingsGet = func(c *fiber.Ctx) error { - db, err := sql.Open("sqlite3", "EveryNasa.db") - if err != nil { - functions.Logger(err.Error()) - } - - querySettings, err := db.Query("SELECT * FROM settings") - - if err != nil { - functions.Logger(err.Error()) - } - - defer func(query *sql.Rows) { - err := query.Close() - if err != nil { - functions.Logger(err.Error()) - } - }(querySettings) - - var startup, wallpaper int - - for querySettings.Next() { - err := querySettings.Scan(&startup, &wallpaper) - if err != nil { - functions.Logger(err.Error()) - } - var data = map[string]interface{}{"startup": startup, "wallpaper": wallpaper} - utils.Respond(c, data) - } - - return nil -} - -var SettingsUpdate = func(c *fiber.Ctx) error { - db, err := sql.Open("sqlite3", "EveryNasa.db") - if err != nil { - functions.Logger(err.Error()) - } - - startup := c.FormValue("startup") - wallpaper := c.FormValue("wallpaper") - - if startup == "" && wallpaper == "" { - utils.Respond(c, utils.Message(false, "All fields are required.")) - return nil - } - - if wallpaper != "" { - _, err := db.Exec("UPDATE settings SET wallpaper = ?", wallpaper) - if err != nil { - functions.Logger(err.Error()) - } - - if wallpaper == "1" { - go functions.StartWallpaper() - } - } - - if startup != "" { - _, err := db.Exec("UPDATE settings SET startup = ?", startup) - if err != nil { - functions.Logger(err.Error()) - } - } - - utils.Respond(c, utils.Message(true, "The settings have been applied successfully.")) - return nil -} diff --git a/api/controllers/startup.go b/api/controllers/startup.go deleted file mode 100644 index 749dab7..0000000 --- a/api/controllers/startup.go +++ /dev/null @@ -1,67 +0,0 @@ -package controllers - -import ( - "github.com/gofiber/fiber/v2" - "os" - "os/user" - "strings" - - "github.com/Redume/EveryNasa/api/utils" - "github.com/Redume/EveryNasa/functions" -) - -var Startup = func(c *fiber.Ctx) error { - startup := c.FormValue("startup") - if startup == "" { - utils.Respond(c, utils.Message(false, "All fields are required.")) - return nil - } - - if startup == "1" { - SetStartup(c) - } else if startup == "0" { - RemoveStartup(c) - } else { - utils.Respond(c, utils.Message(false, "Invalid field.")) - return nil - } - - return nil -} - -var SetStartup = func(c *fiber.Ctx) error { - u, err := user.Current() - if err != nil { - functions.Logger(err.Error()) - } - - dir, err := os.Getwd() - if err != nil { - functions.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") - if err != nil { - functions.Logger(err.Error()) - } - - utils.Respond(c, utils.Message(true, "The settings have been applied successfully.")) - return nil -} - -var RemoveStartup = func(c *fiber.Ctx) error { - u, err := user.Current() - if err != nil { - functions.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.Respond(c, utils.Message(true, "The settings have been applied successfully.")) - return nil -} diff --git a/api/controllers/wallpaper.go b/api/controllers/wallpaper.go deleted file mode 100644 index 4f4a73a..0000000 --- a/api/controllers/wallpaper.go +++ /dev/null @@ -1,28 +0,0 @@ -package controllers - -import ( - "github.com/Redume/EveryNasa/api/utils" - "github.com/Redume/EveryNasa/functions" - "github.com/gofiber/fiber/v2" - "github.com/reujab/wallpaper" -) - -var WallpaperUpdate = func(c *fiber.Ctx) error { - var url string - url = c.FormValue("url") - if url == "" { - utils.Respond(c, utils.Message(false, "URL is required")) - return nil - } - - err := wallpaper.SetFromURL(url) - if err != nil { - functions.Logger(err.Error()) - utils.Respond(c, utils.Message(false, "An error occurred while setting the wallpaper")) - return nil - } - - utils.Respond(c, utils.Message(true, "Wallpaper successfully updated")) - - return nil -} diff --git a/api/utils/utils.go b/api/utils/utils.go deleted file mode 100644 index aad7ac4..0000000 --- a/api/utils/utils.go +++ /dev/null @@ -1,20 +0,0 @@ -package utils - -import ( - "encoding/json" - - "github.com/Redume/EveryNasa/functions" - "github.com/gofiber/fiber/v2" -) - -func Message(status bool, message string) map[string]interface{} { - return map[string]interface{}{"status": status, "message": message} -} - -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()) - } -}