From 58cbc3224d680773caf219c453d4bc1f02b90c3c Mon Sep 17 00:00:00 2001 From: himetani_cafe Date: Sat, 1 Aug 2015 04:25:15 +0900 Subject: [PATCH] modified dirInfo API --- client/app/app.js | 2 +- client/index.html | 2 +- server/api/dirInfo/index.js | 49 ++++++++++++++++++++++++++++++-------------- server/api/noteInfo/index.js | 5 ++--- server/jb.js | 3 ++- 5 files changed, 40 insertions(+), 21 deletions(-) diff --git a/client/app/app.js b/client/app/app.js index 7e19131..347f943 100644 --- a/client/app/app.js +++ b/client/app/app.js @@ -10,7 +10,7 @@ angular.module('zephyrApp', ['ui.bootstrap', 'ui.router', 'restangular','ngRoute $httpProvider.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest' // Debug - $urlRouterProvider.otherwise('/notes/504d41f91d2f81f02561b93a0e9ccde4') + $urlRouterProvider.otherwise('/workspace/504d41f91d2f81f02561b93a0e9ccde4') }) .run(function($rootScope, $state, Restangular, user) { diff --git a/client/index.html b/client/index.html index 62c4834..7b0ece5 100644 --- a/client/index.html +++ b/client/index.html @@ -48,9 +48,9 @@ - + diff --git a/server/api/dirInfo/index.js b/server/api/dirInfo/index.js index de70d56..a8ac719 100644 --- a/server/api/dirInfo/index.js +++ b/server/api/dirInfo/index.js @@ -3,23 +3,42 @@ var express = require('express'), router = express.Router(), path = require('path'), - fs = require('fs') + fs = require('fs'), + jb = require('../../jb.js') -router.get('/:dir', function(req, res) { - var dir = req.params.dir - var dirPath - if(dir === 'root') dirPath = path.normalize(__dirname+'/../../../workspace/') - else dirPath = path.normalize(__dirname+'/../../../workspace/'+dir) - var files = fs.readdirSync(dirPath) - var filesInfo = files.filter(function(file) { - return file.substring(0,1) !== '.' && file !== 'preview' - }) - .map(function(file) { - var stat = fs.statSync(dirPath+'/'+file) - stat.name = file - return stat +router.post('', function(req, res) { + var dir = req.body.dir, + email = req.body.email, + dirPath, + filePath + + if(dir === 'root') + dirPath = path.normalize(__dirname+'/../../../workspace/') + else + dirPath = path.normalize(__dirname+'/../../../workspace/'+dir+'/') + + jb.findOne('user', function(err, documents) { + var filesInfo = documents.workspaces.map(function(file) { + var filePath = dirPath + file + var stat = fs.statSync(filePath) + stat.name = file + + return stat + }) + res.send(filesInfo) }) - res.send(filesInfo) + + /* + var files = fs.readdirSync(dirPath) + var filesInfo = files.filter(function(file) { + return file.substring(0,1) !== '.' && file !== 'preview' + }) + .map(function(file) { + var stat = fs.statSync(dirPath+'/'+file) + stat.name = file + return stat + }) + */ }) module.exports = router; diff --git a/server/api/noteInfo/index.js b/server/api/noteInfo/index.js index a54d4da..635074f 100644 --- a/server/api/noteInfo/index.js +++ b/server/api/noteInfo/index.js @@ -11,7 +11,6 @@ router.post('/', function(req, res) { email = req.body.email, dirPath - // Return file list at /note/* if(note === 'root') { jb.findOne('user', function(err, documents) { @@ -43,8 +42,8 @@ router.post('/', function(req, res) { // Return content of the note } else { var noteJSON = require(path.normalize(__dirname+'/../../../notes/'+note+'.json')) - res.json(noteJSON) + res.json(noteJSON) } }) - module.exports = router; +module.exports = router; diff --git a/server/jb.js b/server/jb.js index 77e0e18..fbf9776 100644 --- a/server/jb.js +++ b/server/jb.js @@ -12,7 +12,8 @@ if(process.env.DB_ZEPHYR === 'drop') { email: 'fumifumi@yasunaga-lab.bio.kyutech.ac.jp', password: 'secret', role: ['expert','amature'], // admin | expert | amature - notes: ['namae.json', 'sample_1.json'] + notes: ['namae.json', 'sample_1.json'], + workspaces: ['leaf', 'shokubutu'] } var users = [user1] -- 2.11.0