mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-14 02:06:29 +00:00
CodeReview
This commit is contained in:
@@ -245,7 +245,9 @@ function deleteAttachmentFolder (storageKey, noteKey) {
|
|||||||
* @param noteKey NoteKey of the current note. Is used to determine the belonging attachment folder.
|
* @param noteKey NoteKey of the current note. Is used to determine the belonging attachment folder.
|
||||||
*/
|
*/
|
||||||
function deleteAttachmentsNotPresentInNote (markdownContent, storageKey, noteKey) {
|
function deleteAttachmentsNotPresentInNote (markdownContent, storageKey, noteKey) {
|
||||||
if (storageKey != null && noteKey != null && markdownContent != null) {
|
if (storageKey == null || noteKey == null || markdownContent == null) {
|
||||||
|
return
|
||||||
|
}
|
||||||
const targetStorage = findStorage.findStorage(storageKey)
|
const targetStorage = findStorage.findStorage(storageKey)
|
||||||
const attachmentFolder = path.join(targetStorage.path, DESTINATION_FOLDER, noteKey)
|
const attachmentFolder = path.join(targetStorage.path, DESTINATION_FOLDER, noteKey)
|
||||||
const attachmentsInNote = getAttachmentsInContent(markdownContent)
|
const attachmentsInNote = getAttachmentsInContent(markdownContent)
|
||||||
@@ -255,11 +257,10 @@ function deleteAttachmentsNotPresentInNote (markdownContent, storageKey, noteKey
|
|||||||
attachmentsInNoteOnlyFileNames.push(attachmentsInNote[i].replace(new RegExp(STORAGE_FOLDER_PLACEHOLDER + escapeStringRegexp(path.sep) + noteKey + escapeStringRegexp(path.sep), 'g'), ''))
|
attachmentsInNoteOnlyFileNames.push(attachmentsInNote[i].replace(new RegExp(STORAGE_FOLDER_PLACEHOLDER + escapeStringRegexp(path.sep) + noteKey + escapeStringRegexp(path.sep), 'g'), ''))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fs.existsSync(attachmentFolder)) {
|
if (fs.existsSync(attachmentFolder)) {
|
||||||
fs.readdir(attachmentFolder, (err, files) => {
|
fs.readdir(attachmentFolder, (err, files) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error("Error reading directory '" + attachmentFolder + "'. Error:")
|
console.error('Error reading directory \'' + attachmentFolder + '\'. Error:')
|
||||||
console.error(err)
|
console.error(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -268,18 +269,17 @@ function deleteAttachmentsNotPresentInNote (markdownContent, storageKey, noteKey
|
|||||||
const absolutePathOfFile = path.join(targetStorage.path, DESTINATION_FOLDER, noteKey, file)
|
const absolutePathOfFile = path.join(targetStorage.path, DESTINATION_FOLDER, noteKey, file)
|
||||||
fs.unlink(absolutePathOfFile, (err) => {
|
fs.unlink(absolutePathOfFile, (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error("Could not delete '%s'", absolutePathOfFile)
|
console.error('Could not delete \'%s\'', absolutePathOfFile)
|
||||||
console.error(err)
|
console.error(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
console.info("File '" + absolutePathOfFile + "' deleted because it was not included in the content of the note")
|
console.info('File \'' + absolutePathOfFile + '\' deleted because it was not included in the content of the note')
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
console.info("Attachment folder ('" + attachmentFolder + "') did not exist..")
|
console.debug('Attachment folder (\'' + attachmentFolder + '\') did not exist..')
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user