feat: show version in admin page
This commit is contained in:
parent
c920eb94a0
commit
a0f12efd65
3 changed files with 41 additions and 14 deletions
|
@ -46,6 +46,7 @@ type TemplateData struct {
|
|||
Channels []*model.Channel
|
||||
Channel *model.Channel
|
||||
ChannelPlugin *model.ChannelPlugin
|
||||
Version string
|
||||
}
|
||||
|
||||
// Admin represents the admin interface
|
||||
|
@ -55,10 +56,11 @@ type Admin struct {
|
|||
store *sessions.CookieStore
|
||||
templates map[string]*template.Template
|
||||
baseTemplate *template.Template
|
||||
version string
|
||||
}
|
||||
|
||||
// New creates a new Admin instance
|
||||
func New(cfg *config.Config, database *db.Database) *Admin {
|
||||
func New(cfg *config.Config, database *db.Database, version string) *Admin {
|
||||
// Create session store with appropriate options
|
||||
store := sessions.NewCookieStore([]byte(cfg.SecretKey))
|
||||
store.Options = &sessions.Options{
|
||||
|
@ -126,6 +128,7 @@ func New(cfg *config.Config, database *db.Database) *Admin {
|
|||
store: store,
|
||||
templates: templates,
|
||||
baseTemplate: baseTemplate,
|
||||
version: version,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -264,6 +267,7 @@ func (a *Admin) render(w http.ResponseWriter, r *http.Request, templateName stri
|
|||
data.LoggedIn = a.isLoggedIn(r)
|
||||
data.Path = r.URL.Path
|
||||
data.Flash = a.getFlashes(w, r)
|
||||
data.Version = a.version
|
||||
|
||||
// Get template
|
||||
tmpl, ok := a.templates[templateName]
|
||||
|
|
|
@ -117,6 +117,19 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<footer class="footer footer-transparent d-print-none">
|
||||
<div class="container-xl">
|
||||
<div class="row text-center align-items-center flex-row-reverse">
|
||||
<div class="col-12 col-lg-auto mt-3 mt-lg-0">
|
||||
<ul class="list-inline list-inline-dots mb-0">
|
||||
<li class="list-inline-item">
|
||||
ButterRobot {{if .Version}}v{{.Version}}{{else}}(development){{end}}
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
<script src="https://unpkg.com/@tabler/core@latest/dist/js/tabler.min.js"></script>
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"runtime/debug"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
|
@ -26,12 +27,13 @@ import (
|
|||
|
||||
// App represents the application
|
||||
type App struct {
|
||||
config *config.Config
|
||||
logger *slog.Logger
|
||||
db *db.Database
|
||||
router *http.ServeMux
|
||||
queue *queue.Queue
|
||||
admin *admin.Admin
|
||||
config *config.Config
|
||||
logger *slog.Logger
|
||||
db *db.Database
|
||||
router *http.ServeMux
|
||||
queue *queue.Queue
|
||||
admin *admin.Admin
|
||||
version string
|
||||
}
|
||||
|
||||
// New creates a new App instance
|
||||
|
@ -48,16 +50,24 @@ func New(cfg *config.Config, logger *slog.Logger) (*App, error) {
|
|||
// Initialize message queue
|
||||
messageQueue := queue.New(logger)
|
||||
|
||||
// Get version information
|
||||
version := ""
|
||||
info, ok := debug.ReadBuildInfo()
|
||||
if ok {
|
||||
version = info.Main.Version
|
||||
}
|
||||
|
||||
// Initialize admin interface
|
||||
adminInterface := admin.New(cfg, database)
|
||||
adminInterface := admin.New(cfg, database, version)
|
||||
|
||||
return &App{
|
||||
config: cfg,
|
||||
logger: logger,
|
||||
db: database,
|
||||
router: router,
|
||||
queue: messageQueue,
|
||||
admin: adminInterface,
|
||||
config: cfg,
|
||||
logger: logger,
|
||||
db: database,
|
||||
router: router,
|
||||
queue: messageQueue,
|
||||
admin: adminInterface,
|
||||
version: version,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue