123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- package controller
- import (
- "fmt"
- "strings"
- "os"
- "git.aetherial.dev/aeth/keiji/pkg/helpers"
- "github.com/gin-gonic/gin"
- )
- func (c *Controller) ServeCss(ctx *gin.Context) {
- f, exist := ctx.Params.Get("file")
- if !exist {
- ctx.JSON(404, map[string]string{
- "Error": "the requested file could not be found",
- })
- }
- css := fmt.Sprintf("%s/css/bootstrap-5.0.2/dist/css/%s", c.WebRoot, f)
- b, err := os.ReadFile(css)
- if err != nil {
- ctx.JSON(500, map[string]string{
- "Error": "Could not serve the requested file",
- "msg": err.Error(),
- })
- }
- ctx.Data(200, "text/css", b)
- }
- func (c *Controller) ServeJs(ctx *gin.Context) {
- f, exist := ctx.Params.Get("file")
- if !exist {
- ctx.JSON(404, map[string]string{
- "Error": "the requested file could not be found",
- })
- }
- css := fmt.Sprintf("%s/css/bootstrap-5.0.2/dist/js/%s", c.WebRoot, f)
- b, err := os.ReadFile(css)
- if err != nil {
- ctx.JSON(500, map[string]string{
- "Error": "Could not serve the requested file",
- "msg": err.Error(),
- })
- }
- ctx.Data(200, "text/javascript", b)
- }
- func (c *Controller) ServeMdbCss(ctx *gin.Context) {
- f, exist := ctx.Params.Get("file")
- if !exist {
- ctx.JSON(404, map[string]string{
- "Error": "the requested file could not be found",
- })
- }
- css := fmt.Sprintf("%s/css/MDB5-STANDARD-UI-KIT-Free-7.1.0/css/%s", c.WebRoot, f)
- b, err := os.ReadFile(css)
- if err != nil {
- ctx.JSON(500, map[string]string{
- "Error": "Could not serve the requested file",
- "msg": err.Error(),
- })
- }
- ctx.Data(200, "text/css", b)
- }
- func (c *Controller) ServeHtmx(ctx *gin.Context) {
- f, exist := ctx.Params.Get("file")
- if !exist {
- ctx.JSON(404, map[string]string{
- "Error": "the requested file could not be found",
- })
- }
- css := fmt.Sprintf("%s/htmx/%s", c.WebRoot, f)
- b, err := os.ReadFile(css)
- if err != nil {
- ctx.JSON(500, map[string]string{
- "Error": "Could not serve the requested file",
- "msg": err.Error(),
- })
- }
- ctx.Data(200, "text/javascript", b)
- }
- func (c *Controller) ServeAsset(ctx *gin.Context) {
- f, exist := ctx.Params.Get("file")
- if !exist {
- ctx.JSON(404, map[string]string{
- "Error": "the requested file could not be found",
- })
- }
- css := fmt.Sprintf("%s/assets/%s", c.WebRoot, f)
- b, err := os.ReadFile(css)
- if err != nil {
- ctx.JSON(500, map[string]string{
- "Error": "Could not serve the requested file",
- "msg": err.Error(),
- })
- }
- ctx.Data(200, "image/jpeg", b)
- }
- func (c *Controller) ServeImage(ctx *gin.Context) {
- f, exist := ctx.Params.Get("file")
- if !exist {
- ctx.JSON(404, map[string]string{
- "Error": "the requested file could not be found",
- })
- }
- css := fmt.Sprintf("%s/%s", helpers.GetImageStore(), f)
- b, err := os.ReadFile(css)
- if err != nil {
- ctx.JSON(500, map[string]string{
- "Error": "Could not serve the requested file",
- "msg": err.Error(),
- })
- }
- ctx.Data(200, "image/jpeg", b)
- }
- func (c *Controller) ServeGeneric(ctx *gin.Context) {
- f, exist := ctx.Params.Get("file")
- if !exist {
- ctx.JSON(404, map[string]string{
- "Error": "the requested file could not be found",
- })
- return
- }
- fext := strings.Split(f, ".")[len(strings.Split(f, "."))-1]
- var ctype string
- switch {
- case fext == "css":
- ctype = "text/css"
- case fext == "js":
- ctype = "text/javascript"
- case fext == "json":
- ctype = "application/json"
- default:
- ctype = "text"
- }
- b, err := os.ReadFile(f)
- if err != nil {
- ctx.JSON(500, map[string]string{
- "Error": "Could not serve the requested file",
- "msg": err.Error(),
- })
- return
- }
- ctx.Data(200, ctype, b)
- }
|