diff --git a/routes/api.js b/routes/api.js index 741bcaa..8d0244e 100644 --- a/routes/api.js +++ b/routes/api.js @@ -1406,37 +1406,47 @@ api.post('/addNote', function(req, res) { api.get('/notes', function(req, res) { console.log("getNotes username = ", req.session.username); + res.header('Access-Control-Allow-Origin', '*'); + res.header('Access-Control-Allow-Headers', 'Content-Type'); + res.header('Access-Control-Allow-Methods', '*'); + var params = req.query; if (!params.shareNote && !req.session.user) { res.send(401); return; } if (params.shareNote) { - db.getNote(params.shareNote) - .then((data) => res.send(` - - - - - -
-
\n\n${data}\n\n
-
- `)) - .catch((err) => console.log('notes', err)); - } else { - params.user_id = req.session.user.id; - db.getNotes(params) - .then((data) => res.json(data)) + if(params.json) { + db.getNote(params.shareNote) + .then((data) => res.json(data)) + .catch((err) => console.log('notes', err)); + } else { + db.getNote(params.shareNote) + .then((data) => res.send(` + + + + + +
+
\n\n${data}\n\n
+
+ `)) .catch((err) => console.log('notes', err)); + } + } else { + params.user_id = req.session.user.id; + db.getNotes(params) + .then((data) => res.json(data)) + .catch((err) => console.log('notes', err)); } }); diff --git a/schema.sql b/schema.sql index e5b482e..a6deabf 100644 --- a/schema.sql +++ b/schema.sql @@ -89,7 +89,7 @@ drop table if exists notes; CREATE TABLE `notes` ( `id` int(11) NOT NULL AUTO_INCREMENT, -- id `user_id` int(11) NOT NULL, -- 用户id - `content` varchar(8092) DEFAULT NULL, -- 备忘内容 + `content` text DEFAULT NULL, -- 备忘内容 `tag_id` int(11) DEFAULT NULL, -- 分类id `created_at` datetime DEFAULT now(), -- 创建时间 `public` tinyint(4) DEFAULT '1', -- 是否公开 1 公开,0 不公开