fixes #4 for real

* Deleting a link deletes the thumbnails
* Joining thumbnails now ignores not visible
This commit is contained in:
Max G 2020-02-10 21:09:09 +00:00
parent d2c1dedffb
commit 7f93925f74
3 changed files with 14 additions and 45 deletions

View File

@ -377,7 +377,6 @@
//If greater than 80 of the way down the page, load the next batch
if(percentageDown >= 80){
console.log('loading next batch')
this.search(false, this.batchSize, true)
}

View File

@ -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) => {
db.promise()
.query(`DELETE FROM attachment WHERE id = ?`, [attachmentId])
.then((rows, fields) => { })
.catch(console.log)
//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('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)
})
})
}

View File

@ -451,10 +451,9 @@ Note.search = (userId, searchQuery, searchTags, fastFilters) => {
JOIN note_raw_text ON (note_raw_text.id = note.note_raw_text_id)
LEFT JOIN note_tag ON (note.id = note_tag.note_id)
LEFT JOIN tag ON (tag.id = note_tag.tag_id)
LEFT JOIN attachment ON (note.id = attachment.note_id)
LEFT JOIN attachment ON (note.id = attachment.note_id AND attachment.visible = 1)
LEFT JOIN user as shareUser ON (note.share_user_id = shareUser.id)
WHERE note.user_id = ?
AND attachment.visible = 1
`
//Show shared notes