Hong

updateShow

...@@ -4,44 +4,83 @@ const AWS = require("aws-sdk"); ...@@ -4,44 +4,83 @@ const AWS = require("aws-sdk");
4 const moment = require("moment"); 4 const moment = require("moment");
5 AWS.config.loadFromPath(__dirname + "/../modules/awsconfig.json"); 5 AWS.config.loadFromPath(__dirname + "/../modules/awsconfig.json");
6 6
7 -const BUCKET_NAME = "qkrrlqja-test"; 7 +const BUCKET_NAME = "hong-s3-cloud";
8 let curPath = ""; 8 let curPath = "";
9 let user_id = ""; 9 let user_id = "";
10 let parentPath = ""; 10 let parentPath = "";
11 11
12 const s3 = new AWS.S3(); 12 const s3 = new AWS.S3();
13 13
14 +// router.get('/show', function(req, res, next) {
15 +// console.log(req.query);
16 +// user_id = req.query.id;
17 +// curPath = req.query.cur;
18 +// if (curPath == '/') {
19 +// parentPath = '/';
20 +// } else {
21 +// let pathSplit = curPath.split('/')
22 +// console.log(pathSplit);
23 +// parentPath = '/';
24 +// for (let i = 1; i < pathSplit.length - 2; i++) {
25 +// parentPath += pathSplit[i];
26 +// parentPath += '/';
27 +// }
28 +// }
29 +// let checkfolder = 'SELECT * FROM folders WHERE location = ? AND user_id = ?;';
30 +// connection.query(checkfolder, [curPath, user_id], function(err, rows, fields) {
31 +// if (err) {
32 +// console.log('select error');
33 +// res.status(400).send({ err: err });
34 +// } else {
35 +// res.status(200).send({
36 +// folders: rows,
37 +// cur: curPath,
38 +// parentPath: parentPath
39 +// })
40 +// }
41 +// });
42 +// });
43 +
14 router.get('/show', function(req, res, next) { 44 router.get('/show', function(req, res, next) {
15 console.log(req.query); 45 console.log(req.query);
16 - user_id = req.query.id; 46 + user_id = req.query.user_id;
17 - curPath = req.query.cur; 47 + folder_id = req.query.folder_id;
18 - if (curPath == '/') { 48 + let checkfolder = 'SELECT * FROM folders WHERE folder_id = ? AND user_id = ?;';
19 - parentPath = '/'; 49 + connection.query(checkfolder, [curPath, user_id], function(err, rows) {
20 - } else {
21 - let pathSplit = curPath.split('/')
22 - console.log(pathSplit);
23 - parentPath = '/';
24 - for (let i = 1; i < pathSplit.length - 2; i++) {
25 - parentPath += pathSplit[i];
26 - parentPath += '/';
27 - }
28 - }
29 - let checkfolder = 'SELECT * FROM folders WHERE location = ? AND user_id = ?;';
30 - connection.query(checkfolder, [curPath, user_id], function(err, rows, fields) {
31 if (err) { 50 if (err) {
32 - console.log('select error'); 51 + console.log('select1 error');
33 res.status(400).send({ err: err }); 52 res.status(400).send({ err: err });
34 } else { 53 } else {
35 - res.status(200).send({ 54 + let location = rows[0].location + rows[0].folder_name + '/';
36 - folders: rows, 55 + if (rows.length == 0) {
37 - cur: curPath, 56 + console.log('does not exist');
38 - parentPath: parentPath 57 + res.status(400).send({ err: 'does not exist' });
39 - }) 58 + } else {
59 + let gerFolder = 'SELECT * FROM folders WHERE location = ? AND user_id = ?;';
60 + connection.query(gerFolder, [location, user_id], function(err, folder) {
61 + if (err) {
62 + console.log('select2 error');
63 + res.status(400).send({ err: err });
64 + } else {
65 + let gerFile = 'SELECT * FROM files WHERE location = ? AND user_id = ?;';
66 + connection.query(gerFile, [location, user_id], function(err, folder) {
67 + if (err) {
68 + console.log('select3 error');
69 + res.status(400).send({ err: err });
70 + } else {
71 + res.status(200).send({
72 + folders: folder,
73 + files: file
74 + });
75 + }
76 + });
77 + }
78 + });
79 + }
40 } 80 }
41 }); 81 });
42 }); 82 });
43 83
44 -
45 router.post('/makefolder', function(req, res, next) { 84 router.post('/makefolder', function(req, res, next) {
46 85
47 user_id = req.body.user_id; 86 user_id = req.body.user_id;
......