diff --git a/account_import.go b/account_import.go index abd38f1..b34f3a7 100644 --- a/account_import.go +++ b/account_import.go @@ -1,6 +1,7 @@ package writefreely import ( + "encoding/json" "fmt" "html/template" "io" @@ -9,6 +10,7 @@ import ( "os" "path/filepath" "strings" + "time" "github.com/hashicorp/go-multierror" "github.com/writeas/impart" @@ -77,6 +79,12 @@ func handleImport(app *App, u *User, w http.ResponseWriter, r *http.Request) err coll.hostName = app.cfg.App.Host } + fileDates := make(map[string]int64) + err = json.Unmarshal([]byte(r.FormValue("fileDates")), &fileDates) + if err != nil { + log.Error("invalid form data for file dates: %v", err) + return impart.HTTPError{http.StatusBadRequest, "form data for file dates was invalid"} + } files := r.MultipartForm.File["files"] var fileErrs []error filesSubmitted := len(files) @@ -138,6 +146,8 @@ func handleImport(app *App, u *User, w http.ResponseWriter, r *http.Request) err if collAlias != "" { post.Collection = collAlias } + dateTime := time.Unix(fileDates[formFile.Filename], 0) + post.Created = &dateTime created := post.Created.Format("2006-01-02T15:04:05Z") submittedPost := SubmittedPost{ Title: &post.Title, diff --git a/templates/user/import.tmpl b/templates/user/import.tmpl index 2b6a4c3..7642023 100644 --- a/templates/user/import.tmpl +++ b/templates/user/import.tmpl @@ -29,8 +29,9 @@
+ +
- {{template "footer" .}} {{end}}