2022-09-18 19:28:56 +03:00
|
|
|
package controllers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
2023-06-05 18:54:14 +03:00
|
|
|
"github.com/Redume/Starlio/utils"
|
2022-10-23 15:27:36 +03:00
|
|
|
"github.com/gofiber/fiber/v2"
|
2022-09-18 19:28:56 +03:00
|
|
|
_ "github.com/mattn/go-sqlite3"
|
|
|
|
)
|
|
|
|
|
2022-10-23 15:27:36 +03:00
|
|
|
var SettingsGet = func(c *fiber.Ctx) error {
|
2023-06-05 18:54:14 +03:00
|
|
|
db, err := sql.Open("sqlite3", "Starlio.db")
|
2022-09-25 11:04:32 +03:00
|
|
|
if err != nil {
|
2023-03-18 16:40:05 +03:00
|
|
|
utils.Logger(err.Error())
|
2022-09-18 19:28:56 +03:00
|
|
|
}
|
|
|
|
|
2022-10-23 15:27:36 +03:00
|
|
|
querySettings, err := db.Query("SELECT * FROM settings")
|
|
|
|
|
2022-09-25 11:04:32 +03:00
|
|
|
if err != nil {
|
2023-03-18 16:40:05 +03:00
|
|
|
utils.Logger(err.Error())
|
2022-09-18 19:28:56 +03:00
|
|
|
}
|
|
|
|
|
2022-09-19 02:07:40 +03:00
|
|
|
defer func(query *sql.Rows) {
|
|
|
|
err := query.Close()
|
|
|
|
if err != nil {
|
2023-03-18 16:40:05 +03:00
|
|
|
utils.Logger(err.Error())
|
2022-09-19 02:07:40 +03:00
|
|
|
}
|
2022-10-23 15:27:36 +03:00
|
|
|
}(querySettings)
|
2022-09-18 19:28:56 +03:00
|
|
|
|
2023-03-18 16:40:05 +03:00
|
|
|
var startup, wallpaper, save_logg int
|
2022-09-18 19:28:56 +03:00
|
|
|
|
2022-10-23 15:27:36 +03:00
|
|
|
for querySettings.Next() {
|
2023-03-18 16:40:05 +03:00
|
|
|
err := querySettings.Scan(&startup, &wallpaper, &save_logg)
|
2022-09-18 19:28:56 +03:00
|
|
|
if err != nil {
|
2023-03-18 16:40:05 +03:00
|
|
|
utils.Logger(err.Error())
|
2022-09-18 19:28:56 +03:00
|
|
|
}
|
2022-12-15 21:10:57 +03:00
|
|
|
|
|
|
|
var data = map[string]interface{}{
|
|
|
|
"startup": startup,
|
2022-11-22 21:36:35 +03:00
|
|
|
"wallpaper": wallpaper,
|
|
|
|
"save_logg": save_logg,
|
2023-03-18 16:40:05 +03:00
|
|
|
}
|
2022-12-15 21:10:57 +03:00
|
|
|
|
2022-10-23 15:27:36 +03:00
|
|
|
utils.Respond(c, data)
|
2022-09-18 19:28:56 +03:00
|
|
|
}
|
2022-10-23 15:27:36 +03:00
|
|
|
|
|
|
|
return nil
|
2022-09-18 19:28:56 +03:00
|
|
|
}
|
|
|
|
|
2022-10-23 15:27:36 +03:00
|
|
|
var SettingsUpdate = func(c *fiber.Ctx) error {
|
2023-06-05 18:54:14 +03:00
|
|
|
db, err := sql.Open("sqlite3", "Starlio.db")
|
2022-09-25 11:04:32 +03:00
|
|
|
if err != nil {
|
2023-03-18 16:40:05 +03:00
|
|
|
utils.Logger(err.Error())
|
2022-09-18 19:28:56 +03:00
|
|
|
}
|
|
|
|
|
2022-10-23 15:27:36 +03:00
|
|
|
startup := c.FormValue("startup")
|
|
|
|
wallpaper := c.FormValue("wallpaper")
|
2022-11-21 22:22:00 +03:00
|
|
|
save_logg := c.FormValue("save_logg")
|
2022-09-18 19:28:56 +03:00
|
|
|
|
2023-03-18 16:40:05 +03:00
|
|
|
if startup == "" && wallpaper == "" && save_logg == "" {
|
2022-10-23 15:27:36 +03:00
|
|
|
utils.Respond(c, utils.Message(false, "All fields are required."))
|
|
|
|
return nil
|
2022-09-18 19:28:56 +03:00
|
|
|
}
|
|
|
|
|
2022-10-02 12:21:17 +03:00
|
|
|
if wallpaper != "" {
|
|
|
|
_, err := db.Exec("UPDATE settings SET wallpaper = ?", wallpaper)
|
2022-09-19 16:55:29 +03:00
|
|
|
if err != nil {
|
2023-03-18 16:40:05 +03:00
|
|
|
utils.Logger(err.Error())
|
2022-09-19 16:55:29 +03:00
|
|
|
}
|
|
|
|
|
2022-10-02 12:21:17 +03:00
|
|
|
if wallpaper == "1" {
|
2023-03-18 16:40:05 +03:00
|
|
|
go utils.StartWallpaper()
|
2022-09-19 16:55:29 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-25 11:04:32 +03:00
|
|
|
if startup != "" {
|
|
|
|
_, err := db.Exec("UPDATE settings SET startup = ?", startup)
|
|
|
|
if err != nil {
|
2023-03-18 16:40:05 +03:00
|
|
|
utils.Logger(err.Error())
|
2022-09-25 11:04:32 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-21 22:22:00 +03:00
|
|
|
if save_logg != "" {
|
|
|
|
_, err := db.Exec("UPDATE settings SET save_logg = ?", save_logg)
|
|
|
|
if err != nil {
|
2023-03-18 16:40:05 +03:00
|
|
|
utils.Logger(err.Error())
|
2022-11-22 21:36:35 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-23 15:27:36 +03:00
|
|
|
utils.Respond(c, utils.Message(true, "The settings have been applied successfully."))
|
|
|
|
return nil
|
2022-09-18 19:28:56 +03:00
|
|
|
}
|