pass original file modified date for imports
This commit is contained in:
parent
f5d21c8c1a
commit
aae2f28bb6
|
@ -1,6 +1,7 @@
|
||||||
package writefreely
|
package writefreely
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"io"
|
"io"
|
||||||
|
@ -9,6 +10,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/hashicorp/go-multierror"
|
"github.com/hashicorp/go-multierror"
|
||||||
"github.com/writeas/impart"
|
"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
|
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"]
|
files := r.MultipartForm.File["files"]
|
||||||
var fileErrs []error
|
var fileErrs []error
|
||||||
filesSubmitted := len(files)
|
filesSubmitted := len(files)
|
||||||
|
@ -138,6 +146,8 @@ func handleImport(app *App, u *User, w http.ResponseWriter, r *http.Request) err
|
||||||
if collAlias != "" {
|
if collAlias != "" {
|
||||||
post.Collection = collAlias
|
post.Collection = collAlias
|
||||||
}
|
}
|
||||||
|
dateTime := time.Unix(fileDates[formFile.Filename], 0)
|
||||||
|
post.Created = &dateTime
|
||||||
created := post.Created.Format("2006-01-02T15:04:05Z")
|
created := post.Created.Format("2006-01-02T15:04:05Z")
|
||||||
submittedPost := SubmittedPost{
|
submittedPost := SubmittedPost{
|
||||||
Title: &post.Title,
|
Title: &post.Title,
|
||||||
|
|
|
@ -29,8 +29,9 @@
|
||||||
<div class="formContainer">
|
<div class="formContainer">
|
||||||
<form id="importPosts" class="prominent" enctype="multipart/form-data" action="/api/me/import" method="POST">
|
<form id="importPosts" class="prominent" enctype="multipart/form-data" action="/api/me/import" method="POST">
|
||||||
<label>Select some files to import:
|
<label>Select some files to import:
|
||||||
<input class="fileInput" name="files" type="file" multiple accept="text/markdown, text/plain"/>
|
<input id="fileInput" class="fileInput" name="files" type="file" multiple accept="text/markdown, text/plain"/>
|
||||||
</label>
|
</label>
|
||||||
|
<input id="fileDates" name="fileDates" hidden/>
|
||||||
<label>
|
<label>
|
||||||
Import these posts to:
|
Import these posts to:
|
||||||
<select name="collection">
|
<select name="collection">
|
||||||
|
@ -40,10 +41,21 @@
|
||||||
<option value="">Drafts</option>
|
<option value="">Drafts</option>
|
||||||
</select>
|
</select>
|
||||||
</label>
|
</label>
|
||||||
|
<script>
|
||||||
|
const fileInput = document.getElementById('fileInput');
|
||||||
|
const fileDates = document.getElementById('fileDates');
|
||||||
|
fileInput.addEventListener('change', (e) => {
|
||||||
|
const files = e.target.files;
|
||||||
|
let dateMap = {};
|
||||||
|
for (let file of files) {
|
||||||
|
dateMap[file.name] = file.lastModified;
|
||||||
|
}
|
||||||
|
fileDates.value = JSON.stringify(dateMap);
|
||||||
|
})
|
||||||
|
</script>
|
||||||
<input type="submit" value="Import" />
|
<input type="submit" value="Import" />
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{template "footer" .}}
|
{{template "footer" .}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
Loading…
Reference in New Issue