mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +00:00
36 lines
986 B
JavaScript
36 lines
986 B
JavaScript
const resolveStorageData = require('./resolveStorageData')
|
|
const path = require('path')
|
|
const sander = require('sander')
|
|
const attachmentManagement = require('./attachmentManagement')
|
|
const { findStorage } = require('browser/lib/findStorage')
|
|
|
|
function deleteNote (storageKey, noteKey) {
|
|
let targetStorage
|
|
try {
|
|
targetStorage = findStorage(storageKey)
|
|
} catch (e) {
|
|
return Promise.reject(e)
|
|
}
|
|
|
|
return resolveStorageData(targetStorage)
|
|
.then(function deleteNoteFile (storage) {
|
|
const notePath = path.join(storage.path, 'notes', noteKey + '.cson')
|
|
|
|
try {
|
|
sander.unlinkSync(notePath)
|
|
} catch (err) {
|
|
console.warn('Failed to delete note cson', err)
|
|
}
|
|
return {
|
|
noteKey,
|
|
storageKey
|
|
}
|
|
})
|
|
.then(function deleteAttachments (storageInfo) {
|
|
attachmentManagement.deleteAttachmentFolder(storageInfo.storageKey, storageInfo.noteKey)
|
|
return storageInfo
|
|
})
|
|
}
|
|
|
|
module.exports = deleteNote
|