Showing
2 changed files
with
60 additions
and
3 deletions
... | @@ -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); | ... | ... |
... | @@ -3,7 +3,9 @@ const router = express.Router(); | ... | @@ -3,7 +3,9 @@ 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(); | ||
7 | 9 | ||
8 | router.get('/delfile', function(req, res, next) { | 10 | router.get('/delfile', function(req, res, next) { |
9 | var file_id = req.query.file_id; | 11 | var file_id = req.query.file_id; |
... | @@ -20,7 +22,7 @@ router.get('/delfile', function(req, res, next) { | ... | @@ -20,7 +22,7 @@ router.get('/delfile', function(req, res, next) { |
20 | console.log('exist error'); | 22 | console.log('exist error'); |
21 | res.send({ erorr: 'exist error' }); | 23 | res.send({ erorr: 'exist error' }); |
22 | } else { | 24 | } else { |
23 | - var curPath = rows[0].location; | 25 | + var curPath = '/trashcan/'; |
24 | var file_name = rows[0].file_name; | 26 | var file_name = rows[0].file_name; |
25 | var sourceFile = curPath.substring(1) + file_name; | 27 | var sourceFile = curPath.substring(1) + file_name; |
26 | 28 | ||
... | @@ -65,7 +67,6 @@ router.get('/delfolder', function(req, res, next) { | ... | @@ -65,7 +67,6 @@ router.get('/delfolder', function(req, res, next) { |
65 | } else { | 67 | } else { |
66 | var curPath = '/trashcan/' | 68 | var curPath = '/trashcan/' |
67 | var folder_name = rows[0].folder_name; | 69 | var folder_name = rows[0].folder_name; |
68 | - var sourcefolder = curPath.substring(1) + folder_name + '/'; | ||
69 | 70 | ||
70 | var sql1 = 'DELETE FROM folders WHERE folder_name = (?) AND location=(?) AND user_Id = (?)'; | 71 | var sql1 = 'DELETE FROM folders WHERE folder_name = (?) AND location=(?) AND user_Id = (?)'; |
71 | connection.query(sql1, [folder_name, curPath, user_id], function(err) { | 72 | connection.query(sql1, [folder_name, curPath, user_id], function(err) { |
... | @@ -97,5 +98,59 @@ router.get('/delfolder', function(req, res, next) { | ... | @@ -97,5 +98,59 @@ router.get('/delfolder', function(req, res, next) { |
97 | }) | 98 | }) |
98 | }); | 99 | }); |
99 | 100 | ||
101 | +router.get('/all', function(req, res, next) { | ||
102 | + var user_id = req.query.id; | ||
103 | + | ||
104 | + var getfolder = "SELECT * FROM folders WHERE user_id = ? AND location = ?;"; | ||
105 | + connection.query(getfolder, [user_id, '/trashcan/'], function(err, folders) { | ||
106 | + if (err) { | ||
107 | + console.log('select db error'); | ||
108 | + res.send({ erorr: 'db select error' }); | ||
109 | + } else { | ||
110 | + var getfile = "SELECT * FROM files WHERE user_id = ? AND location = ?;"; | ||
111 | + connection.query(getfile, [user_id, '/trashcan/'], function(err, files) { | ||
112 | + if (err) { | ||
113 | + console.log('select db error'); | ||
114 | + res.send({ erorr: 'db select error' }); | ||
115 | + } else { | ||
116 | + for (let i of files) { | ||
117 | + var sql1 = 'DELETE FROM files WHERE file_id = ?;'; | ||
118 | + var sourceFile = 'trashcan/' + i.file_name; | ||
119 | + connection.query(sql1, [i.file_id], function(err) { | ||
120 | + if (err) { | ||
121 | + console.log('delete db error'); | ||
122 | + res.send({ erorr: 'db delete error' }); | ||
123 | + } else { | ||
124 | + S3.deleteFile(S3.BUCKET_NAME, user_id, sourceFile, function(result) {}) | ||
125 | + } | ||
126 | + }) | ||
127 | + } | ||
128 | + for (let j of folders) { | ||
129 | + var curPath = '/trashcan/'; | ||
130 | + | ||
131 | + var sql1 = 'DELETE FROM folders WHERE folder_name = (?) AND location=(?) AND user_Id = (?)'; | ||
132 | + connection.query(sql1, [j.folder_name, curPath, user_id], function(err) { | ||
133 | + if (err) { | ||
134 | + console.log('delete db error'); | ||
135 | + res.send({ erorr: 'db delete error' }); | ||
136 | + } else { | ||
137 | + var params = { | ||
138 | + Bucket: S3.BUCKET_NAME, | ||
139 | + Key: 'drive/' + user_id + curPath + j.folder_name + '/' | ||
140 | + }; | ||
141 | + s3.deleteObject(params, function(err, data) { | ||
142 | + if (err) { | ||
143 | + res.status(400).send({ err: err }); | ||
144 | + } | ||
145 | + }); | ||
146 | + } | ||
147 | + }); | ||
148 | + } | ||
149 | + res.send({ success: "success" }); | ||
150 | + } | ||
151 | + }); | ||
152 | + } | ||
153 | + }); | ||
154 | +}); | ||
100 | 155 | ||
101 | module.exports = router; | 156 | module.exports = router; |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment