mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +00:00
OnBlur throws exceptions if the notetype is snippet -> Fixes #1962
This commit is contained in:
@@ -232,39 +232,41 @@ 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) {
|
||||||
const targetStorage = findStorage.findStorage(storageKey)
|
if (storageKey && noteKey && markdownContent !== null && typeof markdownContent !== 'undefined') {
|
||||||
const attachmentFolder = path.join(targetStorage.path, DESTINATION_FOLDER, noteKey)
|
const targetStorage = findStorage.findStorage(storageKey)
|
||||||
const attachmentsInNote = getAttachmentsInContent(markdownContent)
|
const attachmentFolder = path.join(targetStorage.path, DESTINATION_FOLDER, noteKey)
|
||||||
const attachmentsInNoteOnlyFileNames = []
|
const attachmentsInNote = getAttachmentsInContent(markdownContent)
|
||||||
if (attachmentsInNote) {
|
const attachmentsInNoteOnlyFileNames = []
|
||||||
for (let i = 0; i < attachmentsInNote.length; i++) {
|
if (attachmentsInNote) {
|
||||||
attachmentsInNoteOnlyFileNames.push(attachmentsInNote[i].replace(new RegExp(STORAGE_FOLDER_PLACEHOLDER + escapeStringRegexp(path.sep) + noteKey + escapeStringRegexp(path.sep), 'g'), ''))
|
for (let i = 0; i < attachmentsInNote.length; i++) {
|
||||||
}
|
attachmentsInNoteOnlyFileNames.push(attachmentsInNote[i].replace(new RegExp(STORAGE_FOLDER_PLACEHOLDER + escapeStringRegexp(path.sep) + noteKey + escapeStringRegexp(path.sep), 'g'), ''))
|
||||||
}
|
|
||||||
|
|
||||||
if (fs.existsSync(attachmentFolder)) {
|
|
||||||
fs.readdir(attachmentFolder, (err, files) => {
|
|
||||||
if (err) {
|
|
||||||
console.error("Error reading directory '" + attachmentFolder + "'. Error:")
|
|
||||||
console.error(err)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
files.forEach(file => {
|
}
|
||||||
if (!attachmentsInNoteOnlyFileNames.includes(file)) {
|
|
||||||
const absolutePathOfFile = path.join(targetStorage.path, DESTINATION_FOLDER, noteKey, file)
|
if (fs.existsSync(attachmentFolder)) {
|
||||||
fs.unlink(absolutePathOfFile, (err) => {
|
fs.readdir(attachmentFolder, (err, files) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error("Could not delete '%s'", absolutePathOfFile)
|
console.error("Error reading directory '" + attachmentFolder + "'. Error:")
|
||||||
console.error(err)
|
console.error(err)
|
||||||
return
|
return
|
||||||
}
|
|
||||||
console.info("File '" + absolutePathOfFile + "' deleted because it was not included in the content of the note")
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
files.forEach(file => {
|
||||||
|
if (!attachmentsInNoteOnlyFileNames.includes(file)) {
|
||||||
|
const absolutePathOfFile = path.join(targetStorage.path, DESTINATION_FOLDER, noteKey, file)
|
||||||
|
fs.unlink(absolutePathOfFile, (err) => {
|
||||||
|
if (err) {
|
||||||
|
console.error("Could not delete '%s'", absolutePathOfFile)
|
||||||
|
console.error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
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.info("Attachment folder ('" + attachmentFolder + "') did not exist..")
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user