1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 09:46:22 +00:00

Deleting a note should also delete the attachments -> fixes #1900

This commit is contained in:
ehhc
2018-05-10 21:36:58 +02:00
parent 90e8dd038d
commit 73ba8b8b13
4 changed files with 42 additions and 0 deletions

View File

@@ -4,6 +4,7 @@ const path = require('path')
const findStorage = require('browser/lib/findStorage')
const mdurl = require('mdurl')
const escapeStringRegexp = require('escape-string-regexp')
const sander = require('sander')
const STORAGE_FOLDER_PLACEHOLDER = ':storage'
const DESTINATION_FOLDER = 'attachments'
@@ -190,6 +191,17 @@ function removeStorageAndNoteReferences (input, noteKey) {
return input.replace(new RegExp(mdurl.encode(path.sep), 'g'), path.sep).replace(new RegExp(STORAGE_FOLDER_PLACEHOLDER + escapeStringRegexp(path.sep) + noteKey, 'g'), DESTINATION_FOLDER)
}
/**
* @description Deletes the attachment folder specified by the given storageKey and noteKey
* @param storageKey Key of the storage of the note to be deleted
* @param noteKey Key of the note to be deleted
*/
function deleteAttachmentFolder (storageKey, noteKey) {
const storagePath = findStorage.findStorage(storageKey)
const noteAttachmentPath = path.join(storagePath.path, DESTINATION_FOLDER, noteKey)
sander.rimraf(noteAttachmentPath)
}
module.exports = {
copyAttachment,
fixLocalURLS,
@@ -199,6 +211,7 @@ module.exports = {
getAttachmentsInContent,
getAbsolutePathsOfAttachmentsInContent,
removeStorageAndNoteReferences,
deleteAttachmentFolder,
STORAGE_FOLDER_PLACEHOLDER,
DESTINATION_FOLDER
}