OSDN Git Service

a54d4dac286a7c4900d417942c7437c019c1a10e
[eos/zephyr.git] / server / api / noteInfo / index.js
1 'use strict';
2
3 var express = require('express'),
4     router  = express.Router(),
5     path    = require('path'),
6     fs      = require('fs'),
7     jb      = require('../../jb')
8
9 router.post('/', function(req, res) {
10     var note = req.body.note,
11         email = req.body.email,
12         dirPath
13
14
15     // Return file list at /note/*
16     if(note === 'root') {
17         jb.findOne('user', function(err, documents) {
18             var filesInfo = documents.notes.map(function(note) { 
19                 var notePath = path.normalize(__dirname+'/../../../notes/'+note)
20                 var stat = fs.statSync(notePath)
21                 stat.name = note.split('.')[0]
22
23                 return stat
24             })
25             res.send(filesInfo)
26         })
27
28
29         /*
30            var filesInfo = fs.readdirSync(dirPath).filter(function(file) {
31            return file.substring(0,1) !== '.' && file !== 'preview' 
32            })
33            .map(function(file) {
34            stat.name = file
35            return stat
36            })
37            .map(function(stat) {
38            stat.name = stat.name.split('.')[0]
39            return stat
40            })
41            res.send(filesInfo)
42            */
43         // Return content of the note
44     } else {
45         var noteJSON = require(path.normalize(__dirname+'/../../../notes/'+note+'.json'))
46             res.json(noteJSON)
47     }
48 })
49
50         module.exports = router;