mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 09:46:22 +00:00
fixing identation and regex
This commit is contained in:
committed by
Junyoung Choi
parent
85cb94d99d
commit
65926fea73
@@ -896,33 +896,32 @@ class NoteList extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add notes to the current folder
|
// Add notes to the current folder
|
||||||
addNotesFromFiles (filepaths) {
|
addNotesFromFiles (filepaths) {
|
||||||
const { dispatch, location } = this.props
|
const { dispatch, location } = this.props
|
||||||
const { storage, folder } = this.resolveTargetFolder()
|
const { storage, folder } = this.resolveTargetFolder()
|
||||||
|
|
||||||
if (filepaths === undefined) return
|
if (filepaths === undefined) return
|
||||||
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}) => {
|
fs.stat(filepath, (err, {mtime, birthtime}) => {
|
||||||
if (err) throw Error('File stat reading error: ', err)
|
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: path.basename(filepath, path.extname(filepath)),
|
title: path.basename(filepath, path.extname(filepath)),
|
||||||
type: 'MARKDOWN_NOTE',
|
type: 'MARKDOWN_NOTE',
|
||||||
createdAt: birthtime,
|
createdAt: birthtime,
|
||||||
updatedAt: mtime
|
updatedAt: mtime
|
||||||
}
|
}
|
||||||
dataApi.createNote(storage.key, newNote)
|
dataApi.createNote(storage.key, newNote)
|
||||||
.then((note) => {
|
.then((note) => {
|
||||||
|
attachmentManagement.importAttachments(note.content, filepath, storage.key, note.key)
|
||||||
attachmentManagement.importAttachments(note.content, filepath, storage.key, note.key)
|
.then((newcontent) => {
|
||||||
.then((newcontent) => {
|
note.content = newcontent
|
||||||
note.content = newcontent;
|
|
||||||
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: 'UPDATE_NOTE',
|
type: 'UPDATE_NOTE',
|
||||||
@@ -932,13 +931,12 @@ class NoteList extends React.Component {
|
|||||||
pathname: location.pathname,
|
pathname: location.pathname,
|
||||||
query: {key: getNoteKey(note)}
|
query: {key: getNoteKey(note)}
|
||||||
})
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
}
|
||||||
}
|
|
||||||
|
|
||||||
getTargetIndex () {
|
getTargetIndex () {
|
||||||
const { location } = this.props
|
const { location } = this.props
|
||||||
|
|||||||
@@ -458,33 +458,27 @@ function getAbsolutePathsOfAttachmentsInContent (markdownContent, storagePath) {
|
|||||||
*/
|
*/
|
||||||
function importAttachments (markDownContent, filepath, storageKey, noteKey) {
|
function importAttachments (markDownContent, filepath, storageKey, noteKey) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let attach_names = markDownContent.match(/!\[.+?]\((?:.+?\..+?\))/g);
|
const nameRegex = /(!\[.+?]\()(.+?\..+?)(\))/g
|
||||||
|
let attachName = nameRegex.exec(markDownContent)
|
||||||
|
const promiseArray = []
|
||||||
|
const beginPath = filepath.match(/\/.+\//)[0]
|
||||||
|
const endPath = []
|
||||||
|
const groupIndex = 2
|
||||||
|
|
||||||
if (!attach_names)
|
while (attachName) {
|
||||||
resolve(markDownContent);
|
endPath.push(attachName[groupIndex])
|
||||||
|
const finalPath = path.join(beginPath, attachName[groupIndex])
|
||||||
else {
|
promiseArray.push(this.copyAttachment(finalPath, storageKey, noteKey))
|
||||||
let promise_array = [];
|
attachName = nameRegex.exec(markDownContent)
|
||||||
let end_path = []
|
|
||||||
|
|
||||||
for (let i = 0; i < attach_names.length; i++){
|
|
||||||
end_path[i] = attach_names[i].match(/(?<=]\()(?:.+?\..+?)(?=\))/)[0];
|
|
||||||
let begin_path = filepath.match(/\/.+\//)[0];
|
|
||||||
let final_path = path.join(begin_path, end_path[i]);
|
|
||||||
|
|
||||||
promise_array.push(this.copyAttachment(final_path, storageKey, noteKey));
|
|
||||||
}
|
|
||||||
|
|
||||||
Promise.all(promise_array).then((file_names) => {
|
|
||||||
|
|
||||||
for (let j = 0; j < file_names.length; j++) {
|
|
||||||
let new_path = path.join(STORAGE_FOLDER_PLACEHOLDER, noteKey, file_names[j]);
|
|
||||||
markDownContent = markDownContent.replace(end_path[j], new_path);
|
|
||||||
}
|
|
||||||
|
|
||||||
resolve(markDownContent);
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Promise.all(promiseArray).then((fileNames) => {
|
||||||
|
for (let j = 0; j < fileNames.length; j++) {
|
||||||
|
const newPath = path.join(STORAGE_FOLDER_PLACEHOLDER, noteKey, fileNames[j])
|
||||||
|
markDownContent = markDownContent.replace(endPath[j], newPath)
|
||||||
|
}
|
||||||
|
resolve(markDownContent)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user