@ -7,12 +7,41 @@ import (
"github.com/gin-gonic/gin"
)
var css = [ ] string { "base.css" , "a17t.css" , "remixicon.css" , "modal.css" , "dark.css" , "tooltip.css" , "loader.css" }
var cssHeader = func ( ) string {
l := len ( css )
h := ""
for i , f := range css {
h += "</css/" + f + ">; rel=preload; as=style"
if l > 1 && i != ( l - 1 ) {
h += ", "
}
}
return h
} ( )
func gcHTML ( gc * gin . Context , code int , file string , templ gin . H ) {
gc . Header ( "Cache-Control" , "no-cache" )
gc . HTML ( code , file , templ )
}
func ( app * appContext ) pushResources ( gc * gin . Context , admin bool ) {
if pusher := gc . Writer . Pusher ( ) ; pusher != nil {
app . debug . Println ( "Using HTTP2 Server push" )
if admin {
toPush := [ ] string { "/js/admin.js" , "/js/theme.js" , "/js/lang.js" , "/js/modal.js" , "/js/tabs.js" , "/js/invites.js" , "/js/accounts.js" , "/js/settings.js" , "/js/profiles.js" , "/js/common.js" }
for _ , f := range toPush {
if err := pusher . Push ( f , nil ) ; err != nil {
app . debug . Printf ( "Failed HTTP2 ServerPush of \"%s\": %+v" , f , err )
}
}
}
}
gc . Header ( "Link" , cssHeader )
}
func ( app * appContext ) AdminPage ( gc * gin . Context ) {
app . pushResources ( gc , true )
lang := gc . Query ( "lang" )
if lang == "" {
lang = app . storage . lang . chosenAdminLang
@ -22,14 +51,6 @@ func (app *appContext) AdminPage(gc *gin.Context) {
emailEnabled , _ := app . config . Section ( "invite_emails" ) . Key ( "enabled" ) . Bool ( )
notificationsEnabled , _ := app . config . Section ( "notifications" ) . Key ( "enabled" ) . Bool ( )
ombiEnabled := app . config . Section ( "ombi" ) . Key ( "enabled" ) . MustBool ( false )
if pusher := gc . Writer . Pusher ( ) ; pusher != nil {
toPush := [ ] string { "/js/admin.js" , "/js/theme.js" , "/js/lang.js" , "/js/modal.js" , "/js/tabs.js" , "/js/invites.js" , "/js/accounts.js" , "/js/settings.js" , "/js/profiles.js" , "/js/common.js" }
for _ , f := range toPush {
if err := pusher . Push ( f , nil ) ; err != nil {
app . debug . Printf ( "Failed HTTP2 ServerPush of \"%s\": %+v" , f , err )
}
}
}
gcHTML ( gc , http . StatusOK , "admin.html" , gin . H {
"urlBase" : app . URLBase ,
"cssClass" : app . cssClass ,
@ -47,6 +68,7 @@ func (app *appContext) AdminPage(gc *gin.Context) {
}
func ( app * appContext ) InviteProxy ( gc * gin . Context ) {
app . pushResources ( gc , false )
code := gc . Param ( "invCode" )
lang := gc . Query ( "lang" )
if lang == "" {
@ -84,6 +106,7 @@ func (app *appContext) InviteProxy(gc *gin.Context) {
}
func ( app * appContext ) NoRouteHandler ( gc * gin . Context ) {
app . pushResources ( gc , false )
gcHTML ( gc , 404 , "404.html" , gin . H {
"cssClass" : app . cssClass ,
"contactMessage" : app . config . Section ( "ui" ) . Key ( "contact_message" ) . String ( ) ,