fixes imported post times
changes the client side to round the unix time to avoid floats alters the time to match the client time zone on the server side
This commit is contained in:
parent
75e2b60328
commit
0766e6cb36
2 changed files with 12 additions and 1 deletions
|
@ -9,6 +9,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -85,6 +86,7 @@ func handleImport(app *App, u *User, w http.ResponseWriter, r *http.Request) err
|
||||||
log.Error("invalid form data for file dates: %v", err)
|
log.Error("invalid form data for file dates: %v", err)
|
||||||
return impart.HTTPError{http.StatusBadRequest, "form data for file dates was invalid"}
|
return impart.HTTPError{http.StatusBadRequest, "form data for file dates was invalid"}
|
||||||
}
|
}
|
||||||
|
fileTZ := r.FormValue("tz")
|
||||||
files := r.MultipartForm.File["files"]
|
files := r.MultipartForm.File["files"]
|
||||||
var fileErrs []error
|
var fileErrs []error
|
||||||
filesSubmitted := len(files)
|
filesSubmitted := len(files)
|
||||||
|
@ -147,6 +149,12 @@ func handleImport(app *App, u *User, w http.ResponseWriter, r *http.Request) err
|
||||||
post.Collection = collAlias
|
post.Collection = collAlias
|
||||||
}
|
}
|
||||||
dateTime := time.Unix(fileDates[formFile.Filename], 0)
|
dateTime := time.Unix(fileDates[formFile.Filename], 0)
|
||||||
|
offset, err := strconv.Atoi(fileTZ)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("form time zone offset not a valid integer: %v", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
dateTime = dateTime.Add(time.Minute * time.Duration(offset))
|
||||||
post.Created = &dateTime
|
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{
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
<input id="fileInput" 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/>
|
<input id="fileDates" name="fileDates" hidden/>
|
||||||
|
<input id="tzInput" name="tz" hidden/>
|
||||||
<label>
|
<label>
|
||||||
Import these posts to:
|
Import these posts to:
|
||||||
<select name="collection">
|
<select name="collection">
|
||||||
|
@ -42,13 +43,15 @@
|
||||||
</select>
|
</select>
|
||||||
</label>
|
</label>
|
||||||
<script>
|
<script>
|
||||||
|
const tzInput = document.getElementById('tzInput');
|
||||||
|
tzInput.value = new Date().getTimezoneOffset();
|
||||||
const fileInput = document.getElementById('fileInput');
|
const fileInput = document.getElementById('fileInput');
|
||||||
const fileDates = document.getElementById('fileDates');
|
const fileDates = document.getElementById('fileDates');
|
||||||
fileInput.addEventListener('change', (e) => {
|
fileInput.addEventListener('change', (e) => {
|
||||||
const files = e.target.files;
|
const files = e.target.files;
|
||||||
let dateMap = {};
|
let dateMap = {};
|
||||||
for (let file of files) {
|
for (let file of files) {
|
||||||
dateMap[file.name] = file.lastModified / 1000;
|
dateMap[file.name] = Math.round(file.lastModified / 1000);
|
||||||
}
|
}
|
||||||
fileDates.value = JSON.stringify(dateMap);
|
fileDates.value = JSON.stringify(dateMap);
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Reference in a new issue