fixes #4 for real
* Deleting a link deletes the thumbnails * Joining thumbnails now ignores not visible
This commit is contained in:
1 parent
ad91218359
commit
623d094d7b
3 files changed
+14
-45
No files matched your search
+12
-41
@@ -123,16 +123,6 @@ Attachment.delete = (userId, attachmentId, urlDelete = false) => {
|
||||
let url = row.url
|
||||
const noteId = row.note_id
|
||||
|
||||
//Do not delete link attachments, just hide them. They will be deleted if removed from note
|
||||
if(row.attachment_type == 1 && !urlDelete){
|
||||
db.promise()
|
||||
.query(`UPDATE attachment SET visible = 0 WHERE id = ?`, [attachmentId])
|
||||
.then((rows, fields) => { })
|
||||
.catch(console.log)
|
||||
|
||||
return resolve(true)
|
||||
}
|
||||
|
||||
//Try to delete file and thumbnail
|
||||
try {
|
||||
fs.unlinkSync(filePath+row.file_location)
|
||||
@@ -141,41 +131,22 @@ Attachment.delete = (userId, attachmentId, urlDelete = false) => {
|
||||
fs.unlinkSync(filePath+'thumb_'+row.file_location)
|
||||
} catch(err) { console.error('Thumbnail Does not exist') }
|
||||
|
||||
db.promise()
|
||||
.query(`DELETE FROM attachment WHERE id = ?`, [attachmentId])
|
||||
.then((rows, fields) => { })
|
||||
.catch(console.log)
|
||||
//Do not delete link attachments, just hide them. They will be deleted if removed from note
|
||||
if(row.attachment_type == 1 && !urlDelete){
|
||||
db.promise()
|
||||
.query(`UPDATE attachment SET visible = 0 WHERE id = ?`, [attachmentId])
|
||||
.then((rows, fields) => { })
|
||||
.catch(console.log)
|
||||
|
||||
//Normal notes are done, for links, remove the link from the note
|
||||
// if(row.attachment_type != 1){
|
||||
return resolve(true)
|
||||
// }
|
||||
}
|
||||
|
||||
//The code below will delete URL text for note
|
||||
db.promise().query('SELECT text FROM note WHERE id = ? AND user_id = ?', [noteId, userId])
|
||||
.then((rows, fields) => {
|
||||
|
||||
//Grab note text
|
||||
let text = rows[0][0]['text']
|
||||
//Remove URL from text, then remove A tags with empty hrefs
|
||||
let newText = text.replace(url, '').replace(/<a href="">[^<]*<\/a>/g, '')
|
||||
db.promise()
|
||||
.query(`DELETE FROM attachment WHERE id = ?`, [attachmentId])
|
||||
.then((rows, fields) => { })
|
||||
.catch(console.log)
|
||||
|
||||
db.promise().query('UPDATE note SET text = ? WHERE id = ? AND user_id = ? LIMIT 1 ', [newText, noteId, userId])
|
||||
.then((rows, fields) => {
|
||||
|
||||
//Only reindex if note was deleted from menu
|
||||
if(reindex){
|
||||
const Note = require('@models/Note')
|
||||
//Reindex Note after updating text
|
||||
Note.reindex(userId, noteId)
|
||||
}
|
||||
|
||||
|
||||
return resolve(true)
|
||||
})
|
||||
|
||||
|
||||
})
|
||||
return resolve(true)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user