diff --git a/internal/router/ui.go b/internal/router/ui.go index bbb48e55..49042712 100644 --- a/internal/router/ui.go +++ b/internal/router/ui.go @@ -3,15 +3,17 @@ package router import ( "embed" "fmt" - "github.com/gin-gonic/gin" - "github.com/segmentfault/answer/ui" - "github.com/segmentfault/pacman/log" "io/fs" "net/http" "os" + + "github.com/gin-gonic/gin" + "github.com/segmentfault/answer/ui" + "github.com/segmentfault/pacman/log" ) const UIIndexFilePath = "build/index.html" +const UIRootFilePath = "build" const UIStaticPath = "build/static" // UIRouter is an interface that provides ui static file routers @@ -66,14 +68,28 @@ func (a *UIRouter) Register(r *gin.Engine) { // specify the not router for default routes and redirect r.NoRoute(func(c *gin.Context) { - index, err := ui.Build.ReadFile(UIIndexFilePath) + name := c.Request.URL.Path + filePath := "" + var file []byte + var err error + switch name { + case "/favicon.ico": + c.Header("content-type", "image/vnd.microsoft.icon") + filePath = UIRootFilePath + name + case "/logo192.png": + filePath = UIRootFilePath + name + case "/logo512.png": + filePath = UIRootFilePath + name + default: + filePath = UIIndexFilePath + c.Header("content-type", "text/html;charset=utf-8") + } + file, err = ui.Build.ReadFile(filePath) if err != nil { log.Error(err) c.Status(http.StatusNotFound) return } - - c.Header("content-type", "text/html;charset=utf-8") - c.String(http.StatusOK, string(index)) + c.String(http.StatusOK, string(file)) }) } diff --git a/internal/service/collection_service.go b/internal/service/collection_service.go index 2dcec893..5b18fdd7 100644 --- a/internal/service/collection_service.go +++ b/internal/service/collection_service.go @@ -61,13 +61,11 @@ func (cs *CollectionService) CollectionSwitch(ctx context.Context, dto *schema.C return nil, err } if !has { - - defaultGroup, err := cs.collectionGroupRepo.AddCollectionDefaultGroup(ctx, dto.UserID) + dbdefaultGroup, err := cs.collectionGroupRepo.AddCollectionDefaultGroup(ctx, dto.UserID) if err != nil { return nil, err } - dto.GroupID = defaultGroup.ID - + dto.GroupID = dbdefaultGroup.ID } else { dto.GroupID = defaultGroup.ID }