prevent extra submissions and improve feedback

user feedback logic was updated to report if zero posts were found in a
zip and form submissions disable the submit button until the form input
for files changes again, preventing possible duplicate submissions on
large zip uploads.

updated to v0.2.1 wfimport to prevent early error returns when an
invalid file is present in a zip.
import-zips
Rob Loranger 5 years ago
parent 0b95b16e3c
commit 02fb828934
No known key found for this signature in database
GPG Key ID: D6F1633A4F0903B8
  1. 11
      account_import.go
  2. 2
      go.mod
  3. 2
      go.sum
  4. 12
      static/js/import.js

@ -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 {

@ -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

@ -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=

@ -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;
}
}
}
}
submitElem.addEventListener("click", (e) => {
e.preventDefault();
submitElem.disabled = true;
fileForm.submit();
});
Loading…
Cancel
Save