660f24acff
Experimenting with better cache busting for static resources. HTTPSRedirect requests are now counted in the route analytics. More scripts are loaded asynchronously now. Upped the default ReadTimeout to eight seconds. Reduce the number of unneccesary NewAcc calls. Added panel_before_head as an injection point for themes. Themes can now declare scripts to be loaded asynchronously. Tweaked the WS resumption algorithm to mae the backoffs a little less aggressive. Fixed an ordering issue in the WS resumption algorithm where backoffs weren't expiring as fast as they should have. Fixed a bug where template logs weren't being written due to a panic. You can now use byte slices in more places in the transpiled templates. Fixed a bug where Cosora's misc.js seemed to be erroring out. Fixed a bug where YT embeds were getting blocked by the CSP. Added the panel_back_to_site phrase. Added the panel_welcome phrase.
46 lines
1.4 KiB
Go
46 lines
1.4 KiB
Go
package panel
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/Azareal/Gosora/common"
|
|
"github.com/Azareal/Gosora/common/phrases"
|
|
)
|
|
|
|
// A blank list to fill out that parameter in Page for routes which don't use it
|
|
var tList []interface{}
|
|
var successJSONBytes = []byte(`{"success":"1"}`)
|
|
|
|
// We're trying to reduce the amount of boilerplate in here, so I added these two functions, they might wind up circulating outside this file in the future
|
|
func successRedirect(dest string, w http.ResponseWriter, r *http.Request, isJs bool) common.RouteError {
|
|
if !isJs {
|
|
http.Redirect(w, r, dest, http.StatusSeeOther)
|
|
} else {
|
|
w.Write(successJSONBytes)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func renderTemplate(tmplName string, w http.ResponseWriter, r *http.Request, header *common.Header, pi interface{}) common.RouteError {
|
|
header.AddScript("global.js")
|
|
if common.RunPreRenderHook("pre_render_"+tmplName, w, r, &header.CurrentUser, pi) {
|
|
return nil
|
|
}
|
|
// TODO: Prepend this with panel_?
|
|
err := header.Theme.RunTmpl(tmplName, pi, w)
|
|
if err != nil {
|
|
return common.InternalError(err, w, r)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func buildBasePage(w http.ResponseWriter, r *http.Request, user *common.User, titlePhrase string, zone string) (*common.BasePanelPage, common.RouteError) {
|
|
header, stats, ferr := common.PanelUserCheck(w, r, user)
|
|
if ferr != nil {
|
|
return nil, ferr
|
|
}
|
|
header.Title = phrases.GetTitlePhrase("panel_" + titlePhrase)
|
|
|
|
return &common.BasePanelPage{header, stats, zone, common.ReportForumID}, nil
|
|
}
|