e87e8513bc
* Cleaned up unused things * Updated squire which had a comment typo update...thats it * Background color picker has matching colors and styles to text color picker * Added new black theme * Moved search to main page, show it on mobile and added options to push things to notes from search with experimental tag searching * Added active note menu buttons based on cursor location in text * Added more instant updating if app is open in two locations for the same user Scratch Pad and home page update with new notes and new text in real time
127 lines
3.0 KiB
JavaScript
127 lines
3.0 KiB
JavaScript
var express = require('express')
|
|
var router = express.Router()
|
|
|
|
let Notes = require('@models/Note')
|
|
let User = require('@models/User')
|
|
let ShareNote = require('@models/ShareNote')
|
|
|
|
let userId = null
|
|
let masterKey = null
|
|
|
|
// middleware that is specific to this router
|
|
router.use(function setUserId (req, res, next) {
|
|
if(req.headers.userId){
|
|
userId = req.headers.userId
|
|
masterKey = req.headers.masterKey
|
|
}
|
|
|
|
next()
|
|
})
|
|
|
|
//
|
|
// Note actions
|
|
//
|
|
router.post('/get', function (req, res) {
|
|
Notes.get(userId, req.body.noteId, masterKey)
|
|
.then( data => {
|
|
res.send(data)
|
|
})
|
|
})
|
|
|
|
router.post('/delete', function (req, res) {
|
|
Notes.delete(userId, req.body.noteId)
|
|
.then( data => res.send(data) )
|
|
})
|
|
|
|
router.post('/create', function (req, res) {
|
|
Notes.create(req.io, userId, req.body.title, req.body.text, masterKey)
|
|
.then( id => res.send({id}) )
|
|
})
|
|
|
|
router.post('/update', function (req, res) {
|
|
Notes.update(req.io, userId, req.body.noteId, req.body.text, req.body.title, req.body.color, req.body.pinned, req.body.archived, req.body.hash, masterKey)
|
|
.then( id => res.send({id}) )
|
|
})
|
|
|
|
router.post('/search', function (req, res) {
|
|
Notes.search(userId, req.body.searchQuery, req.body.searchTags, req.body.fastFilters, masterKey)
|
|
.then( notesAndTags => {
|
|
res.send(notesAndTags)
|
|
})
|
|
})
|
|
|
|
router.post('/difftext', function (req, res) {
|
|
Notes.getDiffText(userId, req.body.noteId, req.body.text, req.body.updated)
|
|
.then( fullDiffText => {
|
|
//Response should be full diff text
|
|
res.send(fullDiffText)
|
|
})
|
|
})
|
|
|
|
router.post('/reindex', function (req, res) {
|
|
Notes.reindex(userId, masterKey)
|
|
.then( data => {
|
|
res.send(data)
|
|
})
|
|
})
|
|
|
|
|
|
//
|
|
// Update single note attributes
|
|
//
|
|
router.post('/setpinned', function (req, res) {
|
|
Notes.setPinned(userId, req.body.noteId, req.body.pinned)
|
|
.then( results => {
|
|
res.send(results)
|
|
})
|
|
})
|
|
router.post('/setarchived', function (req, res) {
|
|
Notes.setArchived(userId, req.body.noteId, req.body.archived)
|
|
.then( results => {
|
|
res.send(results)
|
|
})
|
|
})
|
|
|
|
//
|
|
// Share Note Actions
|
|
//
|
|
router.post('/getshareusers', function (req, res) {
|
|
ShareNote.getUsers(userId, req.body.rawTextId)
|
|
.then(results => res.send(results))
|
|
})
|
|
|
|
router.post('/shareadduser', function (req, res) {
|
|
// ShareNote.addUser(userId, req.body.noteId, req.body.rawTextId, req.body.username, masterKey)
|
|
User.getByUserName(req.body.username)
|
|
.then( user => {
|
|
return ShareNote.migrateNoteToShared(userId, req.body.noteId, user.id, masterKey)
|
|
})
|
|
.then( ({success, shareUserId}) => {
|
|
|
|
//Emit update count event to user shared with - so they see the note in real time
|
|
req.io.to(shareUserId).emit('update_counts')
|
|
|
|
res.send(success)
|
|
})
|
|
})
|
|
|
|
router.post('/shareremoveuser', function (req, res) {
|
|
ShareNote.removeUser(userId, req.body.noteId)
|
|
.then(results => res.send(results))
|
|
})
|
|
|
|
|
|
//
|
|
// Testing Action
|
|
//
|
|
//Reindex all notes. Not a very good function, not public
|
|
router.get('/reindex5yu43prchuj903mrc', function (req, res) {
|
|
|
|
Notes.migrateNoteTextToNewTable().then(status => {
|
|
return res.send(status)
|
|
})
|
|
|
|
})
|
|
|
|
|
|
module.exports = router |