diff --git a/account_import.go b/account_import.go index 579770b..3cd1624 100644 --- a/account_import.go +++ b/account_import.go @@ -72,7 +72,7 @@ func handleImport(app *App, u *User, w http.ResponseWriter, r *http.Request) err if len(errs) != 0 { _ = addSessionFlash(app, w, r, multierror.ListFormatFunc(errs), nil) } - if filesImported == filesSubmitted { + if filesImported == filesSubmitted && filesSubmitted != 0 { postAdj := "posts" if filesSubmitted == 1 { postAdj = "post" @@ -92,6 +92,8 @@ func handleImport(app *App, u *User, w http.ResponseWriter, r *http.Request) err } else { _ = addSessionFlash(app, w, r, fmt.Sprintf("SUCCESS: Import complete, %d %s imported.", filesImported, postAdj), nil) } + } else if filesImported == 0 && filesSubmitted == 0 { + _ = addSessionFlash(app, w, r, "INFO: 0 valid posts found", nil) } else if filesImported > 0 { _ = addSessionFlash(app, w, r, fmt.Sprintf("INFO: %d of %d posts imported, see details below.", filesImported, filesSubmitted), nil) } @@ -184,9 +186,10 @@ func importZipPosts(app *App, w http.ResponseWriter, r *http.Request, file *mult } for collKey, posts := range postMap { - // TODO: will posts ever be 0? should skip if so + if len(posts) == 0 { + continue + } collObj := CollectionObj{} - importedColls++ if collKey != wfimport.DraftsKey { coll, err := app.db.GetCollection(collKey) if err == ErrCollectionNotFound { @@ -202,6 +205,7 @@ func importZipPosts(app *App, w http.ResponseWriter, r *http.Request, file *mult continue } collObj.Collection = *coll + importedColls++ } for _, post := range posts { @@ -217,6 +221,7 @@ func importZipPosts(app *App, w http.ResponseWriter, r *http.Request, file *mult rp, err := app.db.CreatePost(u.ID, collObj.Collection.ID, &submittedPost) if err != nil { errs = append(errs, fmt.Errorf("create post: %v", err)) + continue } if collObj.Collection.ID != 0 && app.cfg.App.Federation { diff --git a/go.mod b/go.mod index 0d7d865..382cc6d 100644 --- a/go.mod +++ b/go.mod @@ -57,7 +57,7 @@ require ( github.com/writeas/go-webfinger v0.0.0-20190106002315-85cf805c86d2 github.com/writeas/httpsig v1.0.0 github.com/writeas/impart v1.1.0 - github.com/writeas/import v0.2.0 + github.com/writeas/import v0.2.1 github.com/writeas/monday v0.0.0-20181024183321-54a7dd579219 github.com/writeas/nerds v1.0.0 github.com/writeas/openssl-go v1.0.0 // indirect diff --git a/go.sum b/go.sum index 64400b9..b63b9e9 100644 --- a/go.sum +++ b/go.sum @@ -176,6 +176,8 @@ github.com/writeas/import v0.1.1 h1:SbYltT+nxrJBUe0xQWJqeKMHaupbxV0a6K3RtwcE4yY= github.com/writeas/import v0.1.1/go.mod h1:gFe0Pl7ZWYiXbI0TJxeMMyylPGZmhVvCfQxhMEc8CxM= github.com/writeas/import v0.2.0 h1:Ov23JW9Rnjxk06rki1Spar45bNX647HhwhAZj3flJiY= github.com/writeas/import v0.2.0/go.mod h1:gFe0Pl7ZWYiXbI0TJxeMMyylPGZmhVvCfQxhMEc8CxM= +github.com/writeas/import v0.2.1 h1:3k+bDNCyqaWdZinyUZtEO4je3mR6fr/nE4ozTh9/9Wg= +github.com/writeas/import v0.2.1/go.mod h1:gFe0Pl7ZWYiXbI0TJxeMMyylPGZmhVvCfQxhMEc8CxM= github.com/writeas/monday v0.0.0-20181024183321-54a7dd579219 h1:baEp0631C8sT2r/hqwypIw2snCFZa6h7U6TojoLHu/c= github.com/writeas/monday v0.0.0-20181024183321-54a7dd579219/go.mod h1:NyM35ayknT7lzO6O/1JpfgGyv+0W9Z9q7aE0J8bXxfQ= github.com/writeas/nerds v1.0.0 h1:ZzRcCN+Sr3MWID7o/x1cr1ZbLvdpej9Y1/Ho+JKlqxo= diff --git a/static/js/import.js b/static/js/import.js index 9e6b460..8019b63 100644 --- a/static/js/import.js +++ b/static/js/import.js @@ -1,4 +1,4 @@ - +const fileForm = document.querySelector('form.import-form'); const selectElem = document.querySelector('select[name="collection"]'); const submitElem = document.querySelector('input[type="submit"]'); const zipInfo = document.querySelector('span.zip > ul.info'); @@ -21,7 +21,7 @@ fileInput.onchange = function() { submitElem.disabled = false; zipInfo.hidden = false; zipWarning.hidden = true; - } else if ( this.files[0].type.match('text.*')) { + } else { selectElem.disabled = false; submitElem.disabled = false; zipInfo.hidden = true; @@ -46,4 +46,10 @@ fileInput.onchange = function() { zipWarning.hidden = true; } } -} \ No newline at end of file +} + +submitElem.addEventListener("click", (e) => { + e.preventDefault(); + submitElem.disabled = true; + fileForm.submit(); +}); \ No newline at end of file