Adding button to cache content

Adding server-side support for disabling manifest exports
This commit is contained in:
John Donaldson 2019-10-28 15:50:49 +00:00
parent 95bcc860e0
commit 8e6d58b643
3 changed files with 25 additions and 0 deletions

View File

@ -313,6 +313,10 @@ func (ctx *Instance) dehydrateHandler(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 = append(manifest, "puzzles.json")
manifest = append(manifest, "points.json")

View File

@ -15,6 +15,10 @@ import (
"time"
)
type RuntimeConfig struct {
export_manifest bool
}
type Instance struct {
Base string
MothballDir string
@ -22,6 +26,8 @@ type Instance struct {
ThemeDir string
AttemptInterval time.Duration
Runtime RuntimeConfig
categories map[string]*Mothball
update chan bool
jPuzzleList []byte

View File

@ -124,6 +124,9 @@ func (ctx *Instance) tidy() {
// Do they want to reset everything?
ctx.MaybeInitialize()
// Check set config
ctx.UpdateConfig()
// Refresh all current categories
for categoryName, mb := range ctx.categories {
if err := mb.Refresh(); err != nil {
@ -286,6 +289,18 @@ func (ctx *Instance) isEnabled() bool {
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
func (ctx *Instance) Maintenance(maintenanceInterval time.Duration) {
for {