최동원

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

…_Team_Khuloud into share,favorite
...@@ -15,6 +15,7 @@ var folderRouter = require('./routes/folders'); ...@@ -15,6 +15,7 @@ var folderRouter = require('./routes/folders');
15 var quickRouter = require('./routes/quick'); 15 var quickRouter = require('./routes/quick');
16 var favoritesRouter = require('./routes/favorites'); 16 var favoritesRouter = require('./routes/favorites');
17 var shareRouter = require('./routes/share'); 17 var shareRouter = require('./routes/share');
18 +var trashcanRouter = require('./routes/trashcan');
18 19
19 20
20 var passport = require('passport'); 21 var passport = require('passport');
...@@ -64,6 +65,7 @@ app.use('/api/RegistUser', registerRouter); ...@@ -64,6 +65,7 @@ app.use('/api/RegistUser', registerRouter);
64 app.use('/api/folder', folderRouter); 65 app.use('/api/folder', folderRouter);
65 app.use('/api/favorites', favoritesRouter); 66 app.use('/api/favorites', favoritesRouter);
66 app.use('/api/share', shareRouter); 67 app.use('/api/share', shareRouter);
68 +app.use('/api/trashcan', trashcanRouter);
67 //app.use('/users', usersRouter); 69 //app.use('/users', usersRouter);
68 app.use('/api/file', fileRouter); 70 app.use('/api/file', fileRouter);
69 app.use('/api/quick', quickRouter); 71 app.use('/api/quick', quickRouter);
......
...@@ -53,8 +53,8 @@ router.get('/show', function(req, res, next) { ...@@ -53,8 +53,8 @@ router.get('/show', function(req, res, next) {
53 console.log('select2 error'); 53 console.log('select2 error');
54 res.status(400).send({ err: err }); 54 res.status(400).send({ err: err });
55 } else { 55 } else {
56 - let gerFile = 'SELECT * FROM files WHERE location = ? AND user_id = ?;'; 56 + let gerFile = 'SELECT * FROM files WHERE location = ? AND user_id = ? AND folder_name != ?;';
57 - connection.query(gerFile, [location, user_id], function(err, file) { 57 + connection.query(gerFile, [location, user_id, 'trashcan'], function(err, file) {
58 if (err) { 58 if (err) {
59 console.log('select3 error'); 59 console.log('select3 error');
60 res.status(400).send({ err: err }); 60 res.status(400).send({ err: err });
......
...@@ -18,7 +18,7 @@ router.post('/', function(req, res, next) { ...@@ -18,7 +18,7 @@ router.post('/', function(req, res, next) {
18 let target_id = req.body.target_id; 18 let target_id = req.body.target_id;
19 19
20 let checkfile = 'SELECT * FROM files WHERE location = ? AND file_name = ? AND user_id = ?'; 20 let checkfile = 'SELECT * FROM files WHERE location = ? AND file_name = ? AND user_id = ?';
21 - connection.query(checkfile, [curPath, name, user_id], function(err1, rows, fields) { 21 + connection.query(checkfile, [cur, name, user_id], function(err1, rows, fields) {
22 if (rows.length != 0) { 22 if (rows.length != 0) {
23 let copy_params = { 23 let copy_params = {
24 Bucket: BUCKET_NAME, 24 Bucket: BUCKET_NAME,
...@@ -43,6 +43,7 @@ router.post('/', function(req, res, next) { ...@@ -43,6 +43,7 @@ router.post('/', function(req, res, next) {
43 } 43 }
44 }); 44 });
45 } else { 45 } else {
46 + console.log("Does not exist");
46 res.status(304).send({ error: "Does not exist" }); 47 res.status(304).send({ error: "Does not exist" });
47 } 48 }
48 }); 49 });
......
...@@ -3,7 +3,35 @@ const router = express.Router(); ...@@ -3,7 +3,35 @@ const router = express.Router();
3 const AWS = require("aws-sdk"); 3 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 -var S3 = require('../modules/s3/s3'); 6 +var S3 = require(__dirname + '/modules/s3/s3');
7 +
8 +const s3 = new AWS.S3();
9 +
10 +router.get('/show', function(req, res, next) {
11 + console.log(req.query);
12 + user_id = req.query.id;
13 +
14 + let checkfolder = 'SELECT * FROM folders WHERE location = ? AND user_id = ?;';
15 + connection.query(checkfolder, ['/trashcan/', user_id], function(err, folder) {
16 + if (err) {
17 + console.log('select error');
18 + res.status(400).send({ err: err });
19 + } else {
20 + let checkfile = 'SELECT * FROM files WHERE location = ? AND user_id = ?;';
21 + connection.query(checkfile, ['/trashcan/', user_id], function(err, file) {
22 + if (err) {
23 + console.log('select error');
24 + res.status(400).send({ err: err });
25 + } else {
26 + res.status(200).send({
27 + folders: folder,
28 + files: file
29 + })
30 + }
31 + });
32 + }
33 + });
34 +});
7 35
8 router.get('/delfile', function(req, res, next) { 36 router.get('/delfile', function(req, res, next) {
9 var file_id = req.query.file_id; 37 var file_id = req.query.file_id;
...@@ -20,7 +48,7 @@ router.get('/delfile', function(req, res, next) { ...@@ -20,7 +48,7 @@ router.get('/delfile', function(req, res, next) {
20 console.log('exist error'); 48 console.log('exist error');
21 res.send({ erorr: 'exist error' }); 49 res.send({ erorr: 'exist error' });
22 } else { 50 } else {
23 - var curPath = rows[0].location; 51 + var curPath = '/trashcan/';
24 var file_name = rows[0].file_name; 52 var file_name = rows[0].file_name;
25 var sourceFile = curPath.substring(1) + file_name; 53 var sourceFile = curPath.substring(1) + file_name;
26 54
...@@ -65,7 +93,6 @@ router.get('/delfolder', function(req, res, next) { ...@@ -65,7 +93,6 @@ router.get('/delfolder', function(req, res, next) {
65 } else { 93 } else {
66 var curPath = '/trashcan/' 94 var curPath = '/trashcan/'
67 var folder_name = rows[0].folder_name; 95 var folder_name = rows[0].folder_name;
68 - var sourcefolder = curPath.substring(1) + folder_name + '/';
69 96
70 var sql1 = 'DELETE FROM folders WHERE folder_name = (?) AND location=(?) AND user_Id = (?)'; 97 var sql1 = 'DELETE FROM folders WHERE folder_name = (?) AND location=(?) AND user_Id = (?)';
71 connection.query(sql1, [folder_name, curPath, user_id], function(err) { 98 connection.query(sql1, [folder_name, curPath, user_id], function(err) {
...@@ -97,5 +124,59 @@ router.get('/delfolder', function(req, res, next) { ...@@ -97,5 +124,59 @@ router.get('/delfolder', function(req, res, next) {
97 }) 124 })
98 }); 125 });
99 126
127 +router.get('/all', function(req, res, next) {
128 + var user_id = req.query.id;
129 +
130 + var getfolder = "SELECT * FROM folders WHERE user_id = ? AND location = ?;";
131 + connection.query(getfolder, [user_id, '/trashcan/'], function(err, folders) {
132 + if (err) {
133 + console.log('select db error');
134 + res.send({ erorr: 'db select error' });
135 + } else {
136 + var getfile = "SELECT * FROM files WHERE user_id = ? AND location = ?;";
137 + connection.query(getfile, [user_id, '/trashcan/'], function(err, files) {
138 + if (err) {
139 + console.log('select db error');
140 + res.send({ erorr: 'db select error' });
141 + } else {
142 + for (let i of files) {
143 + var sql1 = 'DELETE FROM files WHERE file_id = ?;';
144 + var sourceFile = 'trashcan/' + i.file_name;
145 + connection.query(sql1, [i.file_id], function(err) {
146 + if (err) {
147 + console.log('delete db error');
148 + res.send({ erorr: 'db delete error' });
149 + } else {
150 + S3.deleteFile(S3.BUCKET_NAME, user_id, sourceFile, function(result) {})
151 + }
152 + })
153 + }
154 + for (let j of folders) {
155 + var curPath = '/trashcan/';
156 +
157 + var sql1 = 'DELETE FROM folders WHERE folder_name = (?) AND location=(?) AND user_Id = (?)';
158 + connection.query(sql1, [j.folder_name, curPath, user_id], function(err) {
159 + if (err) {
160 + console.log('delete db error');
161 + res.send({ erorr: 'db delete error' });
162 + } else {
163 + var params = {
164 + Bucket: S3.BUCKET_NAME,
165 + Key: 'drive/' + user_id + curPath + j.folder_name + '/'
166 + };
167 + s3.deleteObject(params, function(err, data) {
168 + if (err) {
169 + res.status(400).send({ err: err });
170 + }
171 + });
172 + }
173 + });
174 + }
175 + res.send({ success: "success" });
176 + }
177 + });
178 + }
179 + });
180 +});
100 181
101 module.exports = router; 182 module.exports = router;
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -70,7 +70,7 @@ ...@@ -70,7 +70,7 @@
70 </v-list-item-action> 70 </v-list-item-action>
71 </v-list-item> 71 </v-list-item>
72 </v-list> 72 </v-list>
73 - <!--file detial --> 73 + <!--file detail -->
74 <v-dialog v-model="showdetailF" max-width="290"> 74 <v-dialog v-model="showdetailF" max-width="290">
75 <v-card> 75 <v-card>
76 <v-card-title class="headline"> 76 <v-card-title class="headline">
......