1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-17 11:41:44 +00:00

Merge pull request #1217 from SCdF/use-file-metadata-on-import

Use existing file metadata for created and modified dates
This commit is contained in:
Kazz Yokomizo
2017-12-16 14:29:19 +09:00
committed by GitHub
2 changed files with 33 additions and 22 deletions

View File

@@ -584,12 +584,18 @@ class NoteList extends React.Component {
filepaths.forEach((filepath) => { filepaths.forEach((filepath) => {
fs.readFile(filepath, (err, data) => { fs.readFile(filepath, (err, data) => {
if (err) throw Error('File reading error: ', err) if (err) throw Error('File reading error: ', err)
fs.stat(filepath, (err, {mtime, birthtime}) => {
if (err) throw Error('File stat reading error: ', err)
const content = data.toString() const content = data.toString()
const newNote = { const newNote = {
content: content, content: content,
folder: folder.key, folder: folder.key,
title: markdown.strip(findNoteTitle(content)), title: markdown.strip(findNoteTitle(content)),
type: 'MARKDOWN_NOTE' type: 'MARKDOWN_NOTE',
createdAt: birthtime,
updatedAt: mtime
} }
dataApi.createNote(storage.key, newNote) dataApi.createNote(storage.key, newNote)
.then((note) => { .then((note) => {
@@ -604,6 +610,7 @@ class NoteList extends React.Component {
}) })
}) })
}) })
})
} }
getTargetIndex () { getTargetIndex () {

View File

@@ -66,10 +66,14 @@ function createNote (storageKey, input) {
} }
} }
} }
const noteData = Object.assign({}, input, { const noteData = Object.assign({},
key, {
createdAt: new Date(), createdAt: new Date(),
updatedAt: new Date(), updatedAt: new Date()
},
input, // input may contain more accurate dates
{
key,
storage: storageKey storage: storageKey
}) })