• R/O
  • HTTP
  • SSH
  • HTTPS

zephyr: Commit

This repository is for zephyr, which is implemented for a GUI of Eos.


Commit MetaInfo

Revision8f360a329165aef599b31786bab75dcc5b6d112f (tree)
Time2016-01-25 21:55:28
Authorhimetani_cafe <fumifumi@yasu...>
Commiterhimetani_cafe

Log Message

[Develop] zephyr debug command for /api/v1/fileUpload

Change Summary

Incremental Difference

--- a/cli/zephyr
+++ b/cli/zephyr
@@ -5,6 +5,7 @@ const chalk = require('chalk');
55
66 zephyr
77 .command('serve', 'start web server')
8+.command('debug', 'serve with debug mode')
89 .command('parse', 'create json file of OptionControlFile from Eos directory')
910 .on('--help', function() {
1011 console.log('Environment variables:');
--- /dev/null
+++ b/cli/zephyr-debug
@@ -0,0 +1,27 @@
1+#!/usr/bin/env node
2+
3+const zephyr = require('commander');
4+const chalk = require('chalk');
5+const cp = require('child_process').spawn;
6+
7+zephyr
8+.usage('[action]')
9+
10+process.env.NODE_ENV = 'production';
11+process.env.ZEPHYR_MODE = 'DEBUG';
12+const npm = cp('node', ['--harmony', process.env.ZEPHYR_HOME + '/server/app/']);
13+
14+npm.stdout.on('data', function (data) {
15+ console.log(data.toString().trim());
16+});
17+
18+npm.stderr.on('data', function (data) {
19+ console.log(data.toString().trim());
20+});
21+
22+zephyr.on('--help', function() {
23+ console.log(('Documentation can be found at ' + chalk.blue('http://www.yasunaga-lab.bio.kyutech.ac.jp/EosJ/index.php/zephyr')));
24+ console.log('');
25+});
26+
27+zephyr.parse(process.argv);
--- a/cli/zephyr-serve
+++ b/cli/zephyr-serve
@@ -7,6 +7,7 @@ const cp = require('child_process').spawn;
77 zephyr
88 .usage('[action]')
99
10+process.env.NODE_ENV = 'production';
1011 const npm = cp('node', ['--harmony', process.env.ZEPHYR_HOME + '/server/app/']);
1112
1213 npm.stdout.on('data', function (data) {
--- a/package.json
+++ b/package.json
@@ -19,6 +19,7 @@
1919 "co": "^4.6.0",
2020 "commander": "^2.9.0",
2121 "express": "^4.13.3",
22+ "formidable": "^1.0.17",
2223 "node-uuid": "^1.4.7",
2324 "sequelize": "^3.18.0",
2425 "socket.io": "^1.3.7",
--- a/server/api/v1/fileUpload/index.js
+++ b/server/api/v1/fileUpload/index.js
@@ -1,17 +1,29 @@
11 'use strict';
22
3-var express = require('express'),
4- router = express.Router(),
5- path = require('path'),
6- formidable = require('formidable');
3+var express = require('express');
4+var router = express.Router()
5+var path = require('path')
6+var formidable = require('formidable')
7+var DB = require(__dirname + '/../../../../server/class/DB');
78
89 router.post('/', function(req, res) {
9- var form = new formidable.IncomingForm();
10- form.uploadDir = __dirname + '/../../../../user-specific-files/workspace';
11- form.parse(req, function(err, fields, files) {
12- var keys = Object.keys(files);
13- console.log(keys);
14- res.send("done");
10+ DB()
11+ .then(function(db) {
12+ var form = new formidable.IncomingForm();
13+ form.uploadDir = __dirname + '/../../../../user-specific-files/workspace';
14+
15+ form.parse(req, function(err, fields, files) {
16+ var parentDirectory = fields['parentDirectory'];
17+ var keys = Object.keys(files);
18+ keys.forEach(function(f) {
19+ db.createFile(files[f].name, parentDirectory)
20+ .then(function(path) {
21+ files[f].path = form.uploadDir + '/' + path;
22+ console.log(files[f].path);
23+ });
24+ });
25+ res.send("done");
26+ });
1527 });
1628 });
1729
--- a/server/app.js
+++ b/server/app.js
@@ -15,6 +15,7 @@ require('./routes')(app)
1515 var server = app.listen(config.port, config.ip, function () {
1616 console.log('Zephyr listening at http://%s:%s', config.ip, config.port);
1717 console.log(app.get('env'))
18+ console.log(process.env.ZEPHYR_MODE);
1819 });
1920
2021 var io = require('socket.io').listen(server)
--- a/server/class/DB.js
+++ b/server/class/DB.js
@@ -25,7 +25,8 @@ function DB() {
2525 */
2626 function sync() {
2727 return new Promise(function(resolve) {
28- Files.sync()
28+ var force = process.env.NODE_ENV !== 'production';
29+ Files.sync({force: force})
2930 .then(function() {
3031 var root = {
3132 fileId: '1f83f620-c1ed-11e5-9657-7942989daa00', // rootのuuidは固定値
@@ -33,7 +34,9 @@ function DB() {
3334 parentId: '',
3435 fileType: 0
3536 };
36- return Files.create(root);
37+ if(process.env.ZEPHYR_MODE === 'DEBUG') {
38+ return Files.create(root);
39+ }
3740 })
3841 .then(function() {
3942 var c = {
--- a/test/mocha/DB.test.js
+++ b/test/mocha/DB.test.js
@@ -230,9 +230,12 @@
230230 })
231231 });
232232
233- it('should be rejected when does not exist directory', function() {
233+ it('should be rejected when does not exist directory(1)', function() {
234234 return db.existDirectory('/one/two/four').should.be.rejectedWith(Error, '"/one/two/four" directory doesn\'t exist.');
235235 });
236+ it('should be rejected when does not exist directory(2)', function() {
237+ return db.existDirectory('hoge').should.be.rejectedWith(Error, 'directory name should start "/" so that it is absolute path including root.');
238+ });
236239 it('should be resolved when exists directory(1)', function() {
237240 return expect(db.existDirectory('/')).to.eventually.equal('1f83f620-c1ed-11e5-9657-7942989daa00');
238241 });
@@ -242,6 +245,9 @@
242245 it('should be resolved when exists directory(3)', function() {
243246 return expect(db.existDirectory('/one/two')).to.eventually.be.a('string');
244247 });
248+ it('should be rejected when call with no parameter', function() {
249+ return db.existDirectory().should.be.rejectedWith(Error, 'parameter "directory" is undefined');
250+ });
245251 });
246252
247253
@@ -277,6 +283,12 @@
277283 it('should be rejected when exists directory(3)', function() {
278284 return db.notExistDirectory('/one/two').should.be.rejectedWith(Error,'"/one/two" directory exists.');
279285 });
286+ it('should be resolved(1)', function() {
287+ return expect(db.notExistDirectory()).to.eventually.equal();
288+ });
289+ it('should be resolved(2)', function() {
290+ return expect(db.notExistDirectory('hoge')).to.eventually.equal();
291+ });
280292
281293 });
282294
@@ -314,6 +326,16 @@
314326 it('should be resolved when file creation successed.', function() {
315327 return expect(db.existFile('tarou.txt', '/')).to.eventually.be.a('string');
316328 });
329+ it('should be rejected(1)', function() {
330+ return db.createFile().should.be.rejectedWith(Error, 'filename is required.');
331+ });
332+ it('should be rejected(2)', function() {
333+ return db.createFile('hoge.txt', '').should.be.rejectedWith(Error, 'parameter "directory" is undefined');
334+ });
335+ it('should be rejected(3)', function() {
336+ return db.createFile(null, '/').should.be.rejectedWith(Error, 'filename is required.');
337+ });
338+
317339 });
318340
319341
@@ -391,6 +413,12 @@
391413 it('should be rejected when the /one/hoge directory has already existed', function() {
392414 return db.notExistDirectory('/one/hoge').should.be.rejectedWith(Error, '"/one/hoge" directory exists.');
393415 });
416+ it('should be rejected(1)', function() {
417+ return db.createDirectory('hoge').should.be.rejectedWith(Error, 'directory name should start "/" so that it is absolute path including root.');
418+ });
419+ it('should be rejected(2)', function() {
420+ return db.createDirectory().should.be.rejectedWith(Error, 'directory name should start "/" so that it is absolute path including root.');
421+ });
394422
395423 });
396424
Show on old repository browser