Upgraded to latest aero version

This commit is contained in:
2019-06-01 13:55:49 +09:00
parent ae591e5e7e
commit 28db818c37
196 changed files with 645 additions and 593 deletions

View File

@ -1,10 +0,0 @@
package utils
import "github.com/aerogo/aero"
// AllowEmbed allows the page to be called by the browser extension.
func AllowEmbed(ctx *aero.Context, response string) string {
// This is a bit of a hack.
// ctx.SetResponseHeader("X-Frame-Options", "ALLOW-FROM chrome-extension://hjfcooigdelogjmniiahfiilcefdlpha/options.html")
return response
}

View File

@ -6,8 +6,8 @@ import (
// GetContainerClass returns the class for the "container" element.
// In the browser extension it will get the "embedded" class.
func GetContainerClass(ctx *aero.Context) string {
if ctx.URI() == "/extension/embed" {
func GetContainerClass(ctx aero.Context) string {
if ctx.Path() == "/extension/embed" {
return "embedded"
}

View File

@ -6,7 +6,7 @@ import (
)
// GetUser returns the logged in user for the given context.
func GetUser(ctx *aero.Context) *arn.User {
func GetUser(ctx aero.Context) *arn.User {
return arn.GetUserFromContext(ctx)
}

View File

@ -1,19 +1,20 @@
package utils
import (
"net/http"
"strings"
"github.com/aerogo/aero"
)
// SmartRedirect automatically adds the /_ prefix to the URI if required.
func SmartRedirect(ctx *aero.Context, uri string) string {
func SmartRedirect(ctx aero.Context, uri string) error {
// Redirect
prefix := ""
if strings.HasPrefix(ctx.URI(), "/_") {
if strings.HasPrefix(ctx.Path(), "/_") {
prefix = "/_"
}
return ctx.Redirect(prefix + uri)
return ctx.Redirect(http.StatusFound, prefix+uri)
}

View File

@ -9,8 +9,8 @@ import (
)
// Handler returns a function that renders the history of any object.
func Handler(render func(interface{}, []*arn.EditLogEntry, *arn.User) string, typeNames ...string) func(ctx *aero.Context) string {
return func(ctx *aero.Context) string {
func Handler(render func(interface{}, []*arn.EditLogEntry, *arn.User) string, typeNames ...string) func(ctx aero.Context) error {
return func(ctx aero.Context) error {
id := ctx.Get("id")
user := utils.GetUser(ctx)
obj, err := arn.DB.Get(typeNames[0], id)

View File

@ -7,7 +7,7 @@ import (
)
// NextIndex calculates the next index and sends HTTP header
func NextIndex(ctx *aero.Context, allElementsLength int, elementsPerScroll int, index int) int {
func NextIndex(ctx aero.Context, allElementsLength int, elementsPerScroll int, index int) int {
nextIndex := index + elementsPerScroll
if nextIndex >= allElementsLength {
@ -15,7 +15,7 @@ func NextIndex(ctx *aero.Context, allElementsLength int, elementsPerScroll int,
}
// Send the index for the next request
ctx.Response().Header().Set("X-LoadMore-Index", strconv.Itoa(nextIndex))
ctx.Response().SetHeader("X-LoadMore-Index", strconv.Itoa(nextIndex))
return nextIndex
}