diff --git a/src/controller/api.js b/src/controller/api.js index c5ec2c6..7c7d498 100644 --- a/src/controller/api.js +++ b/src/controller/api.js @@ -12,6 +12,10 @@ function md5(str) { module.exports = class extends Base { async __before() { if (['userRegister', 'userLogin', 'noteShare', 'bookmarkDownload', 'hotBookmarks', 'hotBookmarksRandom'].indexOf(this.ctx.action) >= 0) { + this.header("Access-Control-Allow-Origin", this.header("origin") || "*"); + this.header("Access-Control-Allow-Headers", "x-requested-with"); + this.header("Access-Control-Allow-Methods", "GET,POST,OPTIONS,PUT,DELETE"); + this.header('Access-Control-Allow-Credentials', true); return; } try { @@ -804,24 +808,29 @@ module.exports = class extends Base { async noteShareAction() { let id = this.get("id"); + let json = this.get("json"); let note = await this.model('notes').where({ id, public: 1 }).find(); - let body = think.isEmpty(note) ? "备忘为非公开或者已删除!" : note.content; - this.body = ` - - - - -
-
\n\n${body}\n\n
-
- `; + if (json) { + this.json(JSON.parse(note.content)) + } else { + let body = think.isEmpty(note) ? "备忘为非公开或者已删除!" : note.content; + this.body = ` + + + + +
+
\n\n${body}\n\n
+
+ `; + } } };