From 178a8c47702f973f36debb8f8b29437db82b34da Mon Sep 17 00:00:00 2001 From: Redume Date: Mon, 1 May 2023 20:50:02 +0300 Subject: [PATCH] Improved version of wallpaper installation --- api/controllers/set_wallpaper.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 api/controllers/set_wallpaper.go diff --git a/api/controllers/set_wallpaper.go b/api/controllers/set_wallpaper.go new file mode 100644 index 0000000..ededfd2 --- /dev/null +++ b/api/controllers/set_wallpaper.go @@ -0,0 +1,26 @@ +package controllers + +import ( + "github.com/Redume/EveryNASA/api/utils" + utils2 "github.com/Redume/EveryNASA/utils" + "github.com/gofiber/fiber/v2" + "github.com/reujab/wallpaper" +) + +var SetWallpaper = func(c *fiber.Ctx) error { + url := c.FormValue("url") + if url == "" { + utils.Respond(c, utils.Message(false, "URL`s required.")) + return nil + } + + err := wallpaper.SetFromURL(url) + if err != nil { + utils2.Log(err.Error()) + utils.Respond(c, utils.Message(false, "An error occurred while setting the wallpaper.")) + return err + } + + utils.Respond(c, utils.Message(true, "The wallpaper was successfully installed.")) + return nil +}