mirror of https://github.com/perkeep/perkeep.git
importer: start of automatic recurring imports
Change-Id: Ib39e6bbf0295df963441d3ebd388558e94581ffb
This commit is contained in:
parent
bf9b0ea332
commit
bff4e7cbbb
|
@ -161,6 +161,7 @@ var tmpl = template.Must(template.New("root").Parse(`
|
||||||
<li>Import root permanode: {{if .Acct.RootObject}}{{.Acct.RootObject.PermanodeRef}}{{else}}(none){{end}}</li>
|
<li>Import root permanode: {{if .Acct.RootObject}}{{.Acct.RootObject.PermanodeRef}}{{else}}(none){{end}}</li>
|
||||||
<li>Configured: {{.Acct.IsAccountReady}}</li>
|
<li>Configured: {{.Acct.IsAccountReady}}</li>
|
||||||
<li>Summary: {{.Acct.AccountLinkSummary}}</li>
|
<li>Summary: {{.Acct.AccountLinkSummary}}</li>
|
||||||
|
<li>Import interval: {{if .Acct.RefreshInterval}}{{.Acct.RefreshInterval}}{{else}}(manual){{end}}</li>
|
||||||
<li>Running: {{.Running}}</li>
|
<li>Running: {{.Running}}</li>
|
||||||
{{if .Running}}
|
{{if .Running}}
|
||||||
<li>Started: {{.StartedAgo}} ago</li>
|
<li>Started: {{.StartedAgo}} ago</li>
|
||||||
|
@ -189,6 +190,11 @@ var tmpl = template.Must(template.New("root").Parse(`
|
||||||
<input type='submit' value='Re-login'>
|
<input type='submit' value='Re-login'>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
<form method='post' style='display: inline'>
|
||||||
|
<input type='hidden' name='mode' value='toggleauto'>
|
||||||
|
<input type='submit' value='Toggle auto'>
|
||||||
|
</form>
|
||||||
|
|
||||||
<form method='post' style='display: inline'>
|
<form method='post' style='display: inline'>
|
||||||
<input type='hidden' name='mode' value='delete'>
|
<input type='hidden' name='mode' value='delete'>
|
||||||
<input type='submit' value='Delete Account' onclick='return confirm("Delete account?")'>
|
<input type='submit' value='Delete Account' onclick='return confirm("Delete account?")'>
|
||||||
|
|
|
@ -49,6 +49,7 @@ const (
|
||||||
attrClientID = "authClientID"
|
attrClientID = "authClientID"
|
||||||
attrClientSecret = "authClientSecret"
|
attrClientSecret = "authClientSecret"
|
||||||
attrImportRoot = "importRoot"
|
attrImportRoot = "importRoot"
|
||||||
|
attrImportAuto = "importAuto" // => time.Duration value ("30m") or "" for off
|
||||||
)
|
)
|
||||||
|
|
||||||
// An Importer imports from a third-party site.
|
// An Importer imports from a third-party site.
|
||||||
|
@ -675,6 +676,15 @@ func (ia *importerAcct) delete() error {
|
||||||
return nil
|
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) {
|
func (ia *importerAcct) IsAccountReady() (bool, error) {
|
||||||
return ia.im.impl.IsAccountReady(ia.acct)
|
return ia.im.impl.IsAccountReady(ia.acct)
|
||||||
}
|
}
|
||||||
|
@ -694,6 +704,15 @@ func (ia *importerAcct) AccountLinkSummary() string {
|
||||||
return ia.im.impl.SummarizeAccount(ia.acct)
|
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) {
|
func (ia *importerAcct) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.Method == "POST" {
|
if r.Method == "POST" {
|
||||||
ia.serveHTTPPost(w, r)
|
ia.serveHTTPPost(w, r)
|
||||||
|
@ -742,6 +761,11 @@ func (ia *importerAcct) serveHTTPPost(w http.ResponseWriter, r *http.Request) {
|
||||||
case "login":
|
case "login":
|
||||||
ia.setup(w, r)
|
ia.setup(w, r)
|
||||||
return
|
return
|
||||||
|
case "toggleauto":
|
||||||
|
if err := ia.toggleAuto(); err != nil {
|
||||||
|
http.Error(w, err.Error(), 500)
|
||||||
|
return
|
||||||
|
}
|
||||||
case "delete":
|
case "delete":
|
||||||
ia.stop() // can't hurt
|
ia.stop() // can't hurt
|
||||||
if err := ia.delete(); err != nil {
|
if err := ia.delete(); err != nil {
|
||||||
|
|
Loading…
Reference in New Issue