server: add read only mode (#92)
In read only mode the endpoint to save new effects or add new versions is deactivated. Also in the gallery the create button is deactivated and there is a notice that says: The server is in maintenance mode. You can not create or modify effects. The button to save effects in the editor is not deactivated as it will take a bit more time and wanted to have the page up as soon as possible.
This commit is contained in:
parent
b0a0012cda
commit
1f3f7dd3d8
|
@ -123,7 +123,13 @@ gallery by <a href="https://twitter.com/thevaw">@thevaw</a>, <a href="https://tw
|
||||||
<a href="https://twitter.com/mrdoob">@mrdoob</a><br/>
|
<a href="https://twitter.com/mrdoob">@mrdoob</a><br/>
|
||||||
editor by <a href="https://twitter.com/mrdoob">@mrdoob</a>, <a href="https://twitter.com/mrkishi">@mrkishi</a>, <a href="https://twitter.com/p01">@p01</a>, <a href="https://twitter.com/alteredq">@alteredq</a>, <a href="https://twitter.com/kusmabite">@kusmabite</a> and <a href="https://twitter.com/emackey">@emackey</a>
|
editor by <a href="https://twitter.com/mrdoob">@mrdoob</a>, <a href="https://twitter.com/mrkishi">@mrkishi</a>, <a href="https://twitter.com/p01">@p01</a>, <a href="https://twitter.com/alteredq">@alteredq</a>, <a href="https://twitter.com/kusmabite">@kusmabite</a> and <a href="https://twitter.com/emackey">@emackey</a>
|
||||||
<br/><br/>
|
<br/><br/>
|
||||||
|
|
||||||
|
{{ if .ReadOnly }}
|
||||||
|
<h2 style="color:#ff6961">The server is in maintenance mode. You can not create or modify effects.</h2>
|
||||||
|
{{ else }}
|
||||||
<a href="/e"><button>new shader</button></a>
|
<a href="/e"><button>new shader</button></a>
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
<div id="gallery">
|
<div id="gallery">
|
||||||
|
|
||||||
{{ if .Admin }}
|
{{ if .Admin }}
|
||||||
|
|
|
@ -25,6 +25,7 @@ type Config struct {
|
||||||
TLSAddr string `envconfig:"TLS_ADDR"`
|
TLSAddr string `envconfig:"TLS_ADDR"`
|
||||||
Domains string `envconfig:"DOMAINS" default:"www.glslsandbox.com,glslsandbox.com"`
|
Domains string `envconfig:"DOMAINS" default:"www.glslsandbox.com,glslsandbox.com"`
|
||||||
Dev bool `envconfig:"DEV" default:"true"`
|
Dev bool `envconfig:"DEV" default:"true"`
|
||||||
|
ReadOnly bool `envconfig:"READ_ONLY" default:"false"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -82,6 +83,7 @@ func start() error {
|
||||||
auth,
|
auth,
|
||||||
cfg.DataPath,
|
cfg.DataPath,
|
||||||
cfg.Dev,
|
cfg.Dev,
|
||||||
|
cfg.ReadOnly,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not create server: %w", err)
|
return fmt.Errorf("could not create server: %w", err)
|
||||||
|
|
|
@ -27,9 +27,7 @@ const (
|
||||||
perPage = 50
|
perPage = 50
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var ErrInvalidData = fmt.Errorf("invalid data")
|
||||||
ErrInvalidData = fmt.Errorf("invalid data")
|
|
||||||
)
|
|
||||||
|
|
||||||
type Template struct {
|
type Template struct {
|
||||||
templates *template.Template
|
templates *template.Template
|
||||||
|
@ -80,6 +78,7 @@ type Server struct {
|
||||||
effects *store.Effects
|
effects *store.Effects
|
||||||
auth *Auth
|
auth *Auth
|
||||||
dataPath string
|
dataPath string
|
||||||
|
readOnly bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(
|
func New(
|
||||||
|
@ -90,6 +89,7 @@ func New(
|
||||||
auth *Auth,
|
auth *Auth,
|
||||||
dataPath string,
|
dataPath string,
|
||||||
dev bool,
|
dev bool,
|
||||||
|
readOnly bool,
|
||||||
) (*Server, error) {
|
) (*Server, error) {
|
||||||
var tpl *template.Template
|
var tpl *template.Template
|
||||||
if !dev {
|
if !dev {
|
||||||
|
@ -115,6 +115,7 @@ func New(
|
||||||
effects: e,
|
effects: e,
|
||||||
auth: auth,
|
auth: auth,
|
||||||
dataPath: dataPath,
|
dataPath: dataPath,
|
||||||
|
readOnly: readOnly,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,7 +164,10 @@ func (s *Server) routes() {
|
||||||
s.echo.GET("/", s.indexHandler)
|
s.echo.GET("/", s.indexHandler)
|
||||||
s.echo.GET("/e", s.effectHandler)
|
s.echo.GET("/e", s.effectHandler)
|
||||||
s.echo.GET("/e_", s.effectHandler_)
|
s.echo.GET("/e_", s.effectHandler_)
|
||||||
s.echo.POST("/e", s.saveHandler)
|
|
||||||
|
if !s.readOnly {
|
||||||
|
s.echo.POST("/e", s.saveHandler)
|
||||||
|
}
|
||||||
|
|
||||||
cors := middleware.CORSWithConfig(middleware.CORSConfig{
|
cors := middleware.CORSWithConfig(middleware.CORSConfig{
|
||||||
Skipper: middleware.DefaultSkipper,
|
Skipper: middleware.DefaultSkipper,
|
||||||
|
@ -228,6 +232,8 @@ type galleryData struct {
|
||||||
NextPage string
|
NextPage string
|
||||||
// Admin is true when accessing "/admin" path.
|
// Admin is true when accessing "/admin" path.
|
||||||
Admin bool
|
Admin bool
|
||||||
|
// ReadOnly tells the server is in read only mode.
|
||||||
|
ReadOnly bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) indexRender(c echo.Context, admin bool) error {
|
func (s *Server) indexRender(c echo.Context, admin bool) error {
|
||||||
|
@ -290,6 +296,7 @@ func (s *Server) indexRender(c echo.Context, admin bool) error {
|
||||||
IsPrevious: page > 0,
|
IsPrevious: page > 0,
|
||||||
PreviousPage: previousPage,
|
PreviousPage: previousPage,
|
||||||
Admin: admin,
|
Admin: admin,
|
||||||
|
ReadOnly: s.readOnly,
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.Render(http.StatusOK, "gallery", d)
|
return c.Render(http.StatusOK, "gallery", d)
|
||||||
|
|
Loading…
Reference in New Issue