Delete api directory

This commit is contained in:
Данил 2022-11-02 20:53:09 +03:00 committed by GitHub
parent ef26347bc5
commit 853ab9bd8a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 0 additions and 226 deletions

View file

@ -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
}

View file

@ -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
}

View file

@ -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
}

View file

@ -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
}

View file

@ -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())
}
}