mirror of
https://github.com/go-shiori/shiori.git
synced 2025-11-06 13:26:12 +08:00
* feat: Add login component JavaScript file * feat: Create login component and refactor login view * refactor: Convert login to single-page application with dynamic component rendering * feat: Enhance session validation and login form display logic * fix: Resolve Vue app mounting and method duplication issues * fix: Prevent null reference error when focusing username input * fix: Initialize `isLoggedIn` to true to show login form during async check * refactor: Improve session validation and login flow logic * fix: Adjust login component visibility and initial login state * feat: Add login form template to login component * feat: Update login template to match original login.html design * fix: Resolve login view rendering and state management issues * refactor: Remove login route from frontend routes * refactor: Remove login-footer from login component template * fix: Modify logout to show login form without redirecting * refactor: Remove /login route test for SPA architecture * refactor: delete login.html file * style: Remove extra blank line in frontend_test.go * chore: run make style changes
65 lines
1.5 KiB
Go
65 lines
1.5 KiB
Go
package routes
|
|
|
|
import (
|
|
"embed"
|
|
"net/http"
|
|
"path"
|
|
|
|
"github.com/gin-contrib/static"
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/go-shiori/shiori/internal/config"
|
|
"github.com/go-shiori/shiori/internal/model"
|
|
views "github.com/go-shiori/shiori/internal/view"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
type assetsFS struct {
|
|
http.FileSystem
|
|
logger *logrus.Logger
|
|
}
|
|
|
|
func (fs assetsFS) Exists(prefix string, path string) bool {
|
|
_, err := fs.Open(path)
|
|
if err != nil {
|
|
logrus.WithError(err).WithField("path", path).WithField("prefix", prefix).Error("requested frontend file not found")
|
|
}
|
|
return err == nil
|
|
}
|
|
|
|
func (fs assetsFS) Open(name string) (http.File, error) {
|
|
f, err := fs.FileSystem.Open(path.Join("assets", name))
|
|
if err != nil {
|
|
logrus.WithError(err).WithField("path", name).Error("requested frontend file not found")
|
|
}
|
|
return f, err
|
|
}
|
|
|
|
func newAssetsFS(logger *logrus.Logger, fs embed.FS) static.ServeFileSystem {
|
|
return assetsFS{
|
|
logger: logger,
|
|
FileSystem: http.FS(fs),
|
|
}
|
|
}
|
|
|
|
type FrontendRoutes struct {
|
|
logger *logrus.Logger
|
|
cfg *config.Config
|
|
}
|
|
|
|
func (r *FrontendRoutes) Setup(e *gin.Engine) {
|
|
group := e.Group("/")
|
|
group.GET("/", func(ctx *gin.Context) {
|
|
ctx.HTML(http.StatusOK, "index.html", gin.H{
|
|
"RootPath": r.cfg.Http.RootPath,
|
|
"Version": model.BuildVersion,
|
|
})
|
|
})
|
|
e.StaticFS("/assets", newAssetsFS(r.logger, views.Assets))
|
|
}
|
|
|
|
func NewFrontendRoutes(logger *logrus.Logger, cfg *config.Config) *FrontendRoutes {
|
|
return &FrontendRoutes{
|
|
logger: logger,
|
|
cfg: cfg,
|
|
}
|
|
}
|