2022-09-18 19:29:08 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/Redume/EveryNasa/api/controllers"
|
|
|
|
"github.com/Redume/EveryNasa/functions"
|
2022-10-23 15:26:51 +03:00
|
|
|
"github.com/Redume/EveryNasa/web/page"
|
2022-09-19 13:23:39 +03:00
|
|
|
"github.com/getlantern/systray"
|
2022-10-23 15:26:51 +03:00
|
|
|
"github.com/gofiber/fiber/v2"
|
|
|
|
"github.com/gofiber/fiber/v2/middleware/cors"
|
2022-09-18 19:29:08 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
go functions.Database()
|
|
|
|
go systray.Run(functions.Tray, functions.Quit)
|
|
|
|
go functions.StartWallpaper()
|
|
|
|
|
2022-10-23 15:26:51 +03:00
|
|
|
app := fiber.New()
|
2022-10-30 20:12:26 +03:00
|
|
|
app = fiber.New(fiber.Config{
|
|
|
|
ErrorHandler: func(ctx *fiber.Ctx, err error) error {
|
|
|
|
code := fiber.StatusInternalServerError
|
|
|
|
|
|
|
|
if e, ok := err.(*fiber.Error); ok {
|
|
|
|
code = e.Code
|
|
|
|
}
|
|
|
|
|
|
|
|
if code == fiber.StatusNotFound {
|
|
|
|
return ctx.SendFile("./web/errors/404.html")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2022-10-23 15:26:51 +03:00
|
|
|
app.Static("/static", "./web/static")
|
|
|
|
app.Use(cors.New())
|
2022-10-02 12:24:00 +03:00
|
|
|
|
2022-10-23 15:26:51 +03:00
|
|
|
app.Get("/", func(c *fiber.Ctx) error {
|
|
|
|
return page.Gallery(c)
|
|
|
|
})
|
|
|
|
app.Get("/settings", func(c *fiber.Ctx) error {
|
|
|
|
return page.Settings(c)
|
|
|
|
})
|
|
|
|
app.Get("/about", func(c *fiber.Ctx) error {
|
|
|
|
return page.About(c)
|
|
|
|
})
|
2022-10-02 12:24:00 +03:00
|
|
|
|
2022-10-30 20:12:26 +03:00
|
|
|
api := app.Group("/api")
|
|
|
|
|
|
|
|
update := api.Group("/update")
|
|
|
|
get := api.Group("/get")
|
|
|
|
create := api.Group("/create")
|
|
|
|
|
|
|
|
update.Post("/settings", func(c *fiber.Ctx) error {
|
2022-10-23 15:26:51 +03:00
|
|
|
return controllers.SettingsUpdate(c)
|
|
|
|
})
|
2022-10-30 20:12:26 +03:00
|
|
|
update.Post("/wallpaper", func(c *fiber.Ctx) error {
|
2022-10-23 15:26:51 +03:00
|
|
|
return controllers.WallpaperUpdate(c)
|
|
|
|
})
|
2022-10-30 20:12:26 +03:00
|
|
|
update.Post("/startup", func(c *fiber.Ctx) error {
|
2022-10-23 15:26:51 +03:00
|
|
|
return controllers.Startup(c)
|
|
|
|
})
|
2022-10-30 20:12:26 +03:00
|
|
|
|
|
|
|
create.Post("/label", func(c *fiber.Ctx) error {
|
2022-10-23 15:26:51 +03:00
|
|
|
return controllers.CreateLabel(c)
|
|
|
|
})
|
2022-10-02 12:24:00 +03:00
|
|
|
|
2022-10-30 20:12:26 +03:00
|
|
|
get.Get("/settings", func(c *fiber.Ctx) error {
|
2022-10-23 15:26:51 +03:00
|
|
|
return controllers.SettingsGet(c)
|
|
|
|
})
|
2022-09-18 19:29:08 +03:00
|
|
|
|
2022-10-30 20:12:26 +03:00
|
|
|
get.Get("/settings", func(c *fiber.Ctx) error {
|
|
|
|
return controllers.SettingsGet(c)
|
2022-10-23 15:26:51 +03:00
|
|
|
})
|
2022-09-18 19:29:08 +03:00
|
|
|
|
2022-10-23 15:26:51 +03:00
|
|
|
err := app.Listen(":3000")
|
2022-09-18 19:29:08 +03:00
|
|
|
if err != nil {
|
2022-10-23 15:26:51 +03:00
|
|
|
return
|
2022-09-18 19:29:08 +03:00
|
|
|
}
|
|
|
|
}
|