최동원

Merge branch 'share,favorite' of http://khuhub.khu.ac.kr/2020-1-CloudComputing/D…

…_Team_Khuloud into share,favorite
...@@ -33,7 +33,7 @@ router.get('/show', function(req, res, next) { ...@@ -33,7 +33,7 @@ router.get('/show', function(req, res, next) {
33 connection.query(checkfolder, [curPath, user_id], function(err, rows, fields) { 33 connection.query(checkfolder, [curPath, user_id], function(err, rows, fields) {
34 if (err) { 34 if (err) {
35 console.log('select error'); 35 console.log('select error');
36 - res.status(404).send() 36 + res.status(400).send({ err: err });
37 } else { 37 } else {
38 res.status(200).send({ 38 res.status(200).send({
39 folders: rows, 39 folders: rows,
...@@ -62,12 +62,13 @@ router.post('/makefolder', function(req, res, next) { ...@@ -62,12 +62,13 @@ router.post('/makefolder', function(req, res, next) {
62 console.log(req.body) 62 console.log(req.body)
63 connection.query(checksql, [cur, folder_name], function(err, rows, fields) { 63 connection.query(checksql, [cur, folder_name], function(err, rows, fields) {
64 if (err) { 64 if (err) {
65 - 65 + res.status(400).send({ err: err });
66 } else { 66 } else {
67 if (rows.length == 0) { 67 if (rows.length == 0) {
68 s3.putObject(params, function(err, data) { 68 s3.putObject(params, function(err, data) {
69 if (err) { 69 if (err) {
70 console.log('s3 error'); 70 console.log('s3 error');
71 + res.status(400).send({ err: err });
71 } else { 72 } else {
72 console.log(data); 73 console.log(data);
73 let sql = 'INSERT INTO folders (folder_name,location,user_id,created) values (?,?,?,?);'; 74 let sql = 'INSERT INTO folders (folder_name,location,user_id,created) values (?,?,?,?);';
...@@ -75,7 +76,7 @@ router.post('/makefolder', function(req, res, next) { ...@@ -75,7 +76,7 @@ router.post('/makefolder', function(req, res, next) {
75 connection.query(sql, values, function(err, result, field) { 76 connection.query(sql, values, function(err, result, field) {
76 if (err) { 77 if (err) {
77 console.log('insert error'); 78 console.log('insert error');
78 - throw err; 79 + res.status(400).send({ err: err });
79 } else { 80 } else {
80 let checkfolder = 'SELECT * FROM folders WHERE location = ? AND user_id = ?;'; 81 let checkfolder = 'SELECT * FROM folders WHERE location = ? AND user_id = ?;';
81 connection.query(checkfolder, [cur, user_id], function(err, rows, fields) { 82 connection.query(checkfolder, [cur, user_id], function(err, rows, fields) {
...@@ -116,13 +117,13 @@ router.post('/delfolder', function(req, res, next) { ...@@ -116,13 +117,13 @@ router.post('/delfolder', function(req, res, next) {
116 s3.deleteObject(params, function(err, data) { 117 s3.deleteObject(params, function(err, data) {
117 if (err) { 118 if (err) {
118 console.log('s3 error'); 119 console.log('s3 error');
119 - //throw err; 120 + res.status(400).send({ err: err });
120 } else { 121 } else {
121 console.log(data); 122 console.log(data);
122 let sql = 'DELETE FROM folders WHERE location = ? AND folder_name = ? AND user_id = ?;'; 123 let sql = 'DELETE FROM folders WHERE location = ? AND folder_name = ? AND user_id = ?;';
123 connection.query(sql, values, function(err, result, field) { 124 connection.query(sql, values, function(err, result, field) {
124 if (err) { 125 if (err) {
125 - //throw err; 126 + res.status(400).send({ err: err });
126 } else { 127 } else {
127 console.log(cur); 128 console.log(cur);
128 console.log(user_id); 129 console.log(user_id);
......
...@@ -4,6 +4,7 @@ var async = require('async'); ...@@ -4,6 +4,7 @@ var async = require('async');
4 const AWS = require("aws-sdk"); 4 const AWS = require("aws-sdk");
5 AWS.config.loadFromPath(__dirname + "/../modules/awsconfig.json"); 5 AWS.config.loadFromPath(__dirname + "/../modules/awsconfig.json");
6 var cryptoM = require('./../../routes/modules/cryptoM.js'); 6 var cryptoM = require('./../../routes/modules/cryptoM.js');
7 +const moment = require("moment");
7 8
8 const BUCKET_NAME = "hong-s3-cloud"; 9 const BUCKET_NAME = "hong-s3-cloud";
9 const s3 = new AWS.S3(); 10 const s3 = new AWS.S3();
...@@ -34,7 +35,7 @@ router.post('/', function(req, res, next) { ...@@ -34,7 +35,7 @@ router.post('/', function(req, res, next) {
34 connection.query(sql, values, function(err) { 35 connection.query(sql, values, function(err) {
35 if (err) { 36 if (err) {
36 console.log("inserting user failed"); 37 console.log("inserting user failed");
37 - throw err; 38 + res.status(400).send({ err: err });
38 } else { 39 } else {
39 let params = { 40 let params = {
40 Bucket: BUCKET_NAME, 41 Bucket: BUCKET_NAME,
...@@ -45,6 +46,7 @@ router.post('/', function(req, res, next) { ...@@ -45,6 +46,7 @@ router.post('/', function(req, res, next) {
45 s3.putObject(params, function(err, data) { 46 s3.putObject(params, function(err, data) {
46 if (err) { 47 if (err) {
47 console.log('s3 error'); 48 console.log('s3 error');
49 + res.status(400).send({ err: err });
48 } else { 50 } else {
49 let params2 = { 51 let params2 = {
50 Bucket: BUCKET_NAME, 52 Bucket: BUCKET_NAME,
...@@ -55,6 +57,7 @@ router.post('/', function(req, res, next) { ...@@ -55,6 +57,7 @@ router.post('/', function(req, res, next) {
55 s3.putObject(params2, function(err, data) { 57 s3.putObject(params2, function(err, data) {
56 if (err) { 58 if (err) {
57 console.log('s3 error'); 59 console.log('s3 error');
60 + res.status(400).send({ err: err });
58 } else { 61 } else {
59 let params3 = { 62 let params3 = {
60 Bucket: BUCKET_NAME, 63 Bucket: BUCKET_NAME,
...@@ -65,6 +68,21 @@ router.post('/', function(req, res, next) { ...@@ -65,6 +68,21 @@ router.post('/', function(req, res, next) {
65 s3.putObject(params3, function(err, data) { 68 s3.putObject(params3, function(err, data) {
66 if (err) { 69 if (err) {
67 console.log('s3 error'); 70 console.log('s3 error');
71 + res.status(400).send({ err: err });
72 + } else {
73 + let date = moment().format();
74 + let root = '/';
75 + let sql = "INSERT INTO folders (folder_name,location,user_id,created) values (?,?,?,?);";
76 + connection.query(sql, ['share', root, user_id, date], function(err, result, field) {
77 + if (err) {
78 + console.log('insert1 error');
79 + res.status(400).send({ err: err });
80 + } else {
81 + let sql = "INSERT INTO folders (folder_name,location,user_id,created) values (?,?,?,?);";
82 + connection.query(sql, ['trashcan', root, user_id, date], function(err, result, field) {
83 + if (err) {
84 + console.log('insert2 error');
85 + res.status(400).send({ err: err });
68 } else { 86 } else {
69 res.status(200).send('saved'); 87 res.status(200).send('saved');
70 } 88 }
...@@ -73,6 +91,10 @@ router.post('/', function(req, res, next) { ...@@ -73,6 +91,10 @@ router.post('/', function(req, res, next) {
73 }); 91 });
74 } 92 }
75 }); 93 });
94 + }
95 + });
96 + }
97 + });
76 98
77 99
78 } 100 }
......
...@@ -250,11 +250,14 @@ export default { ...@@ -250,11 +250,14 @@ export default {
250 cur: this.$store.state.cur + move_folder_name + '/', 250 cur: this.$store.state.cur + move_folder_name + '/',
251 }; 251 };
252 const response = await folder(curData); 252 const response = await folder(curData);
253 + const file_response = await file(curData);
253 console.log(response.data); 254 console.log(response.data);
254 this.$store.commit('setFolder', response.data.folders); 255 this.$store.commit('setFolder', response.data.folders);
256 + this.$store.commit('setFile', file_response.data.files);
255 this.$store.commit('setCur', response.data.cur); 257 this.$store.commit('setCur', response.data.cur);
256 this.$store.commit('setParent', response.data.parentPath); 258 this.$store.commit('setParent', response.data.parentPath);
257 this.folders = this.$store.getters.folderL; 259 this.folders = this.$store.getters.folderL;
260 + this.files = this.$store.getters.fileL;
258 } catch (error) { 261 } catch (error) {
259 console.log('에러'); 262 console.log('에러');
260 console.log(error.response.data); 263 console.log(error.response.data);
...@@ -267,11 +270,14 @@ export default { ...@@ -267,11 +270,14 @@ export default {
267 cur: this.$store.state.parent, 270 cur: this.$store.state.parent,
268 }; 271 };
269 const response = await folder(cData); 272 const response = await folder(cData);
273 + const file_response = await file(cData);
270 console.log(response.data); 274 console.log(response.data);
271 this.$store.commit('setFolder', response.data.folders); 275 this.$store.commit('setFolder', response.data.folders);
276 + this.$store.commit('setFile', file_response.data.files);
272 this.$store.commit('setCur', response.data.cur); 277 this.$store.commit('setCur', response.data.cur);
273 this.$store.commit('setParent', response.data.parentPath); 278 this.$store.commit('setParent', response.data.parentPath);
274 this.folders = this.$store.getters.folderL; 279 this.folders = this.$store.getters.folderL;
280 + this.files = this.$store.getters.fileL;
275 } catch (error) { 281 } catch (error) {
276 console.log('에러'); 282 console.log('에러');
277 console.log(error.response.data); 283 console.log(error.response.data);
......