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/>
|
||||
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/>
|
||||
|
||||
{{ 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>
|
||||
{{ end }}
|
||||
|
||||
<div id="gallery">
|
||||
|
||||
{{ if .Admin }}
|
||||
|
|
|
@ -25,6 +25,7 @@ type Config struct {
|
|||
TLSAddr string `envconfig:"TLS_ADDR"`
|
||||
Domains string `envconfig:"DOMAINS" default:"www.glslsandbox.com,glslsandbox.com"`
|
||||
Dev bool `envconfig:"DEV" default:"true"`
|
||||
ReadOnly bool `envconfig:"READ_ONLY" default:"false"`
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
@ -82,6 +83,7 @@ func start() error {
|
|||
auth,
|
||||
cfg.DataPath,
|
||||
cfg.Dev,
|
||||
cfg.ReadOnly,
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not create server: %w", err)
|
||||
|
|
|
@ -27,9 +27,7 @@ const (
|
|||
perPage = 50
|
||||
)
|
||||
|
||||
var (
|
||||
ErrInvalidData = fmt.Errorf("invalid data")
|
||||
)
|
||||
var ErrInvalidData = fmt.Errorf("invalid data")
|
||||
|
||||
type Template struct {
|
||||
templates *template.Template
|
||||
|
@ -80,6 +78,7 @@ type Server struct {
|
|||
effects *store.Effects
|
||||
auth *Auth
|
||||
dataPath string
|
||||
readOnly bool
|
||||
}
|
||||
|
||||
func New(
|
||||
|
@ -90,6 +89,7 @@ func New(
|
|||
auth *Auth,
|
||||
dataPath string,
|
||||
dev bool,
|
||||
readOnly bool,
|
||||
) (*Server, error) {
|
||||
var tpl *template.Template
|
||||
if !dev {
|
||||
|
@ -115,6 +115,7 @@ func New(
|
|||
effects: e,
|
||||
auth: auth,
|
||||
dataPath: dataPath,
|
||||
readOnly: readOnly,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -163,7 +164,10 @@ func (s *Server) routes() {
|
|||
s.echo.GET("/", s.indexHandler)
|
||||
s.echo.GET("/e", s.effectHandler)
|
||||
s.echo.GET("/e_", s.effectHandler_)
|
||||
|
||||
if !s.readOnly {
|
||||
s.echo.POST("/e", s.saveHandler)
|
||||
}
|
||||
|
||||
cors := middleware.CORSWithConfig(middleware.CORSConfig{
|
||||
Skipper: middleware.DefaultSkipper,
|
||||
|
@ -228,6 +232,8 @@ type galleryData struct {
|
|||
NextPage string
|
||||
// Admin is true when accessing "/admin" path.
|
||||
Admin bool
|
||||
// ReadOnly tells the server is in read only mode.
|
||||
ReadOnly bool
|
||||
}
|
||||
|
||||
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,
|
||||
PreviousPage: previousPage,
|
||||
Admin: admin,
|
||||
ReadOnly: s.readOnly,
|
||||
}
|
||||
|
||||
return c.Render(http.StatusOK, "gallery", d)
|
||||
|
|
Loading…
Reference in New Issue