SolidScribe/server/routes/noteController.js
Max G 6bb856689d * Adjusted theme colors to add more contrast on white theme while making black more OLED friendly
* Links now get an underline on hover
* Cleaned up CSS variable names, added another theme color for more control
* Cleaned up unused CSS, removed scrollbars popping up, tons of other little UI tweaks
* Renamed shared notes to inbox
* Tweaked form display, seperated login and create accouts
* Put login/sign up form on home page
* Created more legitimate marketing for home page
* Tons up updates to note page and note input panel
* Better support for two users editing a note
* MUCH better diff handling, web sockets restore notes with unsaved diffs
* Moved all squire text modifier functions into a mixin class
* It now says saving when closing a note
* Lots of cleanup and better handiling of events on mount and destroy
* Scroll behavior modified to load notes when closer to bottom of page
* Pretty decent shared notes and sharable link support
* Updated help text
* Search now includes tag suggestions and attachment suggestions
* Cleaned up scratch pad a ton, allow for users to create new scratch pads
* Created a 404 Page and a Shared note page
* So many other small improvements. Oh my god, what is wrong with me, not doing commits!?
2020-06-07 20:57:35 +00:00

154 lines
3.8 KiB
JavaScript

var express = require('express')
var router = express.Router()
let Note = 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) {
Note.get(userId, req.body.noteId, masterKey)
.then( noteObject => {
delete noteObject.snippet_salt
delete noteObject.salt
delete noteObject.encrypted_share_password_key
res.send(noteObject)
})
})
router.post('/delete', function (req, res) {
Note.delete(userId, req.body.noteId, masterKey)
.then( data => res.send(data) )
})
router.post('/create', function (req, res) {
Note.create(userId, req.body.title, req.body.text, masterKey)
.then( id => res.send({id}) )
})
router.post('/update', function (req, res) {
Note.update(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) {
Note.search(userId, req.body.searchQuery, req.body.searchTags, req.body.fastFilters, masterKey)
.then( NoteAndTags => {
res.send(NoteAndTags)
})
})
router.post('/difftext', function (req, res) {
Note.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) {
Note.reindex(userId, masterKey)
.then( data => {
res.send(data)
})
})
//
// Update single note attributes
//
router.post('/setpinned', function (req, res) {
Note.setPinned(userId, req.body.noteId, req.body.pinned)
.then( results => {
res.send(results)
})
})
router.post('/setarchived', function (req, res) {
Note.setArchived(userId, req.body.noteId, req.body.archived)
.then( results => {
res.send(results)
})
})
router.post('/settrashed', function (req, res) {
Note.setTrashed(userId, req.body.noteId, req.body.trashed, masterKey)
.then( results => {
res.send(results)
})
})
//
// Share Note Actions
//
router.post('/getshareinfo', function (req, res) {
ShareNote.getShareInfo(userId, req.body.noteId, 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.addUserToSharedNote(userId, req.body.noteId, user.id, masterKey)
})
.then( ({success, shareUserId}) => {
res.send(success)
})
})
router.post('/shareremoveuser', function (req, res) {
// (userId, noteId, shareNoteUserId, shareUserId, masterKey)
ShareNote.removeUserFromSharedNote(userId, req.body.noteId, req.body.shareUserNoteId, masterKey)
.then(results => res.send(results))
})
router.post('/enableshare', function (req, res) {
//Create Shared Encryption Key for Note
ShareNote.migrateToShared(userId, req.body.noteId, masterKey)
.then(results => res.send(true))
})
router.post('/getsharekey', function (req, res) {
//Get Shared Key for a note
ShareNote.decryptSharedKey(userId, req.body.noteId, masterKey)
.then(results => res.send(results))
})
router.post('/disableshare', function (req, res) {
//Removed shared encryption key from note
ShareNote.migrateToNormal(userId, req.body.noteId, masterKey)
.then(results => res.send(true))
})
//
// Testing Action
//
//Reindex all Note. Not a very good function, not public
router.get('/reindex5yu43prchuj903mrc', function (req, res) {
Note.migrateNoteTextToNewTable().then(status => {
return res.send(status)
})
})
module.exports = router