1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-16 03:06:27 +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,22 +584,29 @@ 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)
const content = data.toString()
const newNote = { fs.stat(filepath, (err, {mtime, birthtime}) => {
content: content, if (err) throw Error('File stat reading error: ', err)
folder: folder.key,
title: markdown.strip(findNoteTitle(content)), const content = data.toString()
type: 'MARKDOWN_NOTE' const newNote = {
} content: content,
dataApi.createNote(storage.key, newNote) folder: folder.key,
.then((note) => { title: markdown.strip(findNoteTitle(content)),
dispatch({ type: 'MARKDOWN_NOTE',
type: 'UPDATE_NOTE', createdAt: birthtime,
note: note updatedAt: mtime
}) }
hashHistory.push({ dataApi.createNote(storage.key, newNote)
pathname: location.pathname, .then((note) => {
query: {key: getNoteKey(note)} dispatch({
type: 'UPDATE_NOTE',
note: note
})
hashHistory.push({
pathname: location.pathname,
query: {key: getNoteKey(note)}
})
}) })
}) })
}) })

View File

@@ -66,12 +66,16 @@ 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()
storage: storageKey },
}) input, // input may contain more accurate dates
{
key,
storage: storageKey
})
CSON.writeFileSync(path.join(storage.path, 'notes', key + '.cson'), _.omit(noteData, ['key', 'storage'])) CSON.writeFileSync(path.join(storage.path, 'notes', key + '.cson'), _.omit(noteData, ['key', 'storage']))