OSDN Git Service

Modified: Upload, Command execution
[eos/zephyr.git] / server / api / dirInfo / index.js
1 'use strict';
2
3 var express = require('express'),
4     router  = express.Router(),
5     path    = require('path'),
6     fs      = require('fs');
7
8 router.post('', function(req, res) {
9     var dir = req.body.dir,
10         email = req.body.email,
11         dirPath, filesInfo
12
13     if(dir === 'workspace') {
14         dirPath = path.normalize(__dirname+'/../../../workspace/')
15         /*
16         jb.findOne('user', function(err, documents) {
17             filesInfo = documents.workspaces.map(function(file) {
18                 var filePath = dirPath + file
19                 var stat = fs.statSync(filePath)
20                 stat.name = file
21                 stat.isDir = stat.isDirectory()
22                 return stat
23             })
24             res.send(filesInfo)
25         })
26         */
27
28     } else {
29         dirPath = path.normalize(__dirname+'/../../../workspace/'+dir.replace('workspace/',''))
30         var files = fs.readdirSync(dirPath)
31         var filesInfo = files.filter(function(file) {
32             return file.substring(0,1) !== '.' && file !== 'preview' 
33         })
34         .map(function(file) {
35             var stat = fs.statSync(dirPath+'/'+file)
36             stat.name = file
37             stat.isDir = stat.isDirectory()
38             return stat
39         })
40         res.send(filesInfo)
41     }
42 })
43
44 module.exports = router;