mirror of https://github.com/dirtbags/moth.git
Adding button to cache content
Adding server-side support for disabling manifest exports
This commit is contained in:
parent
95bcc860e0
commit
8e6d58b643
|
@ -313,6 +313,10 @@ func (ctx *Instance) dehydrateHandler(w http.ResponseWriter, req *http.Request)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ctx *Instance) manifestHandler(w http.ResponseWriter, req *http.Request) {
|
func (ctx *Instance) manifestHandler(w http.ResponseWriter, req *http.Request) {
|
||||||
|
if (! ctx.Runtime.export_manifest) {
|
||||||
|
http.Error(w, "Endpoint disabled", http.StatusForbidden)
|
||||||
|
return
|
||||||
|
}
|
||||||
manifest := make([]string, 0)
|
manifest := make([]string, 0)
|
||||||
manifest = append(manifest, "puzzles.json")
|
manifest = append(manifest, "puzzles.json")
|
||||||
manifest = append(manifest, "points.json")
|
manifest = append(manifest, "points.json")
|
||||||
|
|
|
@ -15,6 +15,10 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type RuntimeConfig struct {
|
||||||
|
export_manifest bool
|
||||||
|
}
|
||||||
|
|
||||||
type Instance struct {
|
type Instance struct {
|
||||||
Base string
|
Base string
|
||||||
MothballDir string
|
MothballDir string
|
||||||
|
@ -22,6 +26,8 @@ type Instance struct {
|
||||||
ThemeDir string
|
ThemeDir string
|
||||||
AttemptInterval time.Duration
|
AttemptInterval time.Duration
|
||||||
|
|
||||||
|
Runtime RuntimeConfig
|
||||||
|
|
||||||
categories map[string]*Mothball
|
categories map[string]*Mothball
|
||||||
update chan bool
|
update chan bool
|
||||||
jPuzzleList []byte
|
jPuzzleList []byte
|
||||||
|
|
|
@ -124,6 +124,9 @@ func (ctx *Instance) tidy() {
|
||||||
// Do they want to reset everything?
|
// Do they want to reset everything?
|
||||||
ctx.MaybeInitialize()
|
ctx.MaybeInitialize()
|
||||||
|
|
||||||
|
// Check set config
|
||||||
|
ctx.UpdateConfig()
|
||||||
|
|
||||||
// Refresh all current categories
|
// Refresh all current categories
|
||||||
for categoryName, mb := range ctx.categories {
|
for categoryName, mb := range ctx.categories {
|
||||||
if err := mb.Refresh(); err != nil {
|
if err := mb.Refresh(); err != nil {
|
||||||
|
@ -286,6 +289,18 @@ func (ctx *Instance) isEnabled() bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ctx *Instance) UpdateConfig() {
|
||||||
|
// Handle export manifest
|
||||||
|
if _, err := os.Stat(ctx.StatePath("export_manifest")); err == nil {
|
||||||
|
log.Print("Enabling manifest export")
|
||||||
|
ctx.Runtime.export_manifest = true
|
||||||
|
} else {
|
||||||
|
log.Print("Disabling manifest export")
|
||||||
|
ctx.Runtime.export_manifest = false
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// maintenance is the goroutine that runs a periodic maintenance task
|
// maintenance is the goroutine that runs a periodic maintenance task
|
||||||
func (ctx *Instance) Maintenance(maintenanceInterval time.Duration) {
|
func (ctx *Instance) Maintenance(maintenanceInterval time.Duration) {
|
||||||
for {
|
for {
|
||||||
|
|
Loading…
Reference in New Issue