diff --git a/pkg/importer/html.go b/pkg/importer/html.go index d62451bc5..6dbae9f86 100644 --- a/pkg/importer/html.go +++ b/pkg/importer/html.go @@ -161,6 +161,7 @@ var tmpl = template.Must(template.New("root").Parse(`
  • Import root permanode: {{if .Acct.RootObject}}{{.Acct.RootObject.PermanodeRef}}{{else}}(none){{end}}
  • Configured: {{.Acct.IsAccountReady}}
  • Summary: {{.Acct.AccountLinkSummary}}
  • +
  • Import interval: {{if .Acct.RefreshInterval}}{{.Acct.RefreshInterval}}{{else}}(manual){{end}}
  • Running: {{.Running}}
  • {{if .Running}}
  • Started: {{.StartedAgo}} ago
  • @@ -189,6 +190,11 @@ var tmpl = template.Must(template.New("root").Parse(` +
    + + +
    +
    diff --git a/pkg/importer/importer.go b/pkg/importer/importer.go index 3f2ea8617..d9027d066 100644 --- a/pkg/importer/importer.go +++ b/pkg/importer/importer.go @@ -49,6 +49,7 @@ const ( attrClientID = "authClientID" attrClientSecret = "authClientSecret" attrImportRoot = "importRoot" + attrImportAuto = "importAuto" // => time.Duration value ("30m") or "" for off ) // An Importer imports from a third-party site. @@ -675,6 +676,15 @@ func (ia *importerAcct) delete() error { return nil } +func (ia *importerAcct) toggleAuto() error { + old := ia.acct.Attr(attrImportAuto) + var new string + if old == "" { + new = "30m" // TODO: configurable? + } + return ia.acct.SetAttrs(attrImportAuto, new) +} + func (ia *importerAcct) IsAccountReady() (bool, error) { return ia.im.impl.IsAccountReady(ia.acct) } @@ -694,6 +704,15 @@ func (ia *importerAcct) AccountLinkSummary() string { return ia.im.impl.SummarizeAccount(ia.acct) } +func (ia *importerAcct) RefreshInterval() time.Duration { + ds := ia.acct.Attr(attrImportAuto) + if ds == "" { + return 0 + } + d, _ := time.ParseDuration(ds) + return d +} + func (ia *importerAcct) ServeHTTP(w http.ResponseWriter, r *http.Request) { if r.Method == "POST" { ia.serveHTTPPost(w, r) @@ -742,6 +761,11 @@ func (ia *importerAcct) serveHTTPPost(w http.ResponseWriter, r *http.Request) { case "login": ia.setup(w, r) return + case "toggleauto": + if err := ia.toggleAuto(); err != nil { + http.Error(w, err.Error(), 500) + return + } case "delete": ia.stop() // can't hurt if err := ia.delete(); err != nil {