Hong

즐겨찾기ing

...@@ -44,8 +44,8 @@ router.post('/addfolder', function(req, res, next) { ...@@ -44,8 +44,8 @@ router.post('/addfolder', function(req, res, next) {
44 console.log('update error'); 44 console.log('update error');
45 res.status(400).send({ error: err }); 45 res.status(400).send({ error: err });
46 } else { 46 } else {
47 - let getfolder = 'SELECT * FROM folders WHERE location = ? AND user_id = ?;'; 47 + let getfolder = 'SELECT * FROM folders WHERE location = ? AND user_id = ? AND folder_name != ?;';
48 - connection.query(getfolder, [cur, user_id], function(err, folders, fields) { 48 + connection.query(getfolder, [cur, user_id, 'trashcan'], function(err, folders, fields) {
49 res.status(200).send({ 49 res.status(200).send({
50 folders: folders 50 folders: folders
51 }) 51 })
...@@ -112,8 +112,8 @@ router.post('/delfolder', function(req, res, next) { ...@@ -112,8 +112,8 @@ router.post('/delfolder', function(req, res, next) {
112 console.log('update error'); 112 console.log('update error');
113 res.status(400).send({ error: err }); 113 res.status(400).send({ error: err });
114 } else { 114 } else {
115 - let getfolder = 'SELECT * FROM folders WHERE location = ? AND user_id = ?;'; 115 + let getfolder = 'SELECT * FROM folders WHERE location = ? AND user_id = ? AND folder_name != ?;';
116 - connection.query(getfolder, [cur, user_id], function(err, folders, fields) { 116 + connection.query(getfolder, [cur, user_id, 'trashcan'], function(err, folders, fields) {
117 res.status(200).send({ 117 res.status(200).send({
118 folders: folders 118 folders: folders
119 }) 119 })
......
...@@ -179,4 +179,116 @@ router.get('/all', function(req, res, next) { ...@@ -179,4 +179,116 @@ router.get('/all', function(req, res, next) {
179 }); 179 });
180 }); 180 });
181 181
182 +router.post('/restore', function(req, res, next) {
183 + console.log(req.body);
184 + let user_id = req.body.user_id;
185 + let id = req.body.id;
186 + if (req.body.isfolder) {
187 + let checkfolder = 'SELECT * FROM folders WHERE folder_id = ? AND user_id = ?;';
188 + connection.query(checkfolder, [id, user_id], function(err1, rows, fields) {
189 + console.log(rows);
190 + if (rows.length != 0) {
191 + let curPath = user_id + '/trashcan/'
192 + let name = rows[0].folder_name
193 + let copy_params = {
194 + Bucket: S3.BUCKET_NAM,
195 + CopySource: S3.BUCKET_NAM + '/drive/' + curPath + name + '/',
196 + Key: 'drive/' + user_id + '/' + name + '/'
197 + };
198 + let del_params = {
199 + Bucket: S3.BUCKET_NAM,
200 + Key: 'drive/' + curPath + name + '/'
201 + };
202 + s3.copyObject(copy_params, function(err, data) {
203 + if (err) {
204 + console.log(err, data);
205 + console.log("copy error");
206 + res.status(304).send({ error: "copy error" });
207 + } else {
208 + s3.deleteObject(del_params, function(err, data) {
209 + if (err) {
210 + console.log(err, data);
211 + console.log("delete error");
212 + res.status(304).send({ error: "delete error" });
213 + } else {
214 + let values = ['/', '/trashcan/', name, user_id];
215 + let updatesql = 'UPDATE folders SET location = ? WHERE location = ? AND folder_name = ? AND user_id = ?;';
216 + connection.query(updatesql, values, function(err3, result, field) {
217 + if (err3) {
218 + console.log("updatesql error");
219 + res.status(304).send({ error: "updatesql error" });
220 + } else {
221 + let resultsql = 'SELECT * FROM folders WHERE location = ? AND user_id = ?;';
222 + connection.query(resultsql, ['/trashcan/', user_id], function(err, folder, fields) {
223 + res.status(200).send({
224 + folders: folder
225 + });
226 + });
227 + }
228 + });
229 + }
230 + });
231 + }
232 + });
233 + } else {
234 + console.log("Does not exist folder");
235 + res.status(304).send({ error: "Does not exist" });
236 + }
237 + });
238 + } else {
239 + let checkfile = 'SELECT * FROM files WHERE file_id = ? AND user_id = ?;';
240 + connection.query(checkfile, [id, user_id], function(err1, rows, fields) {
241 + console.log(rows);
242 + if (rows.length != 0) {
243 + let curPath = user_id + '/trashcan/'
244 + let name = rows[0].file_name
245 + let copy_params = {
246 + Bucket: S3.BUCKET_NAME,
247 + CopySource: S3.BUCKET_NAME + '/drive/' + curPath + name,
248 + Key: 'drive/' + user_id + '/' + name
249 + };
250 + let del_params = {
251 + Bucket: S3.BUCKET_NAME,
252 + Key: 'drive/' + curPath + name
253 + };
254 + s3.copyObject(copy_params, function(err, data) {
255 + if (err) {
256 + console.log(err, data);
257 + console.log("copy error");
258 + res.status(304).send({ error: "copy error" });
259 + } else {
260 + s3.deleteObject(del_params, function(err, data) {
261 + if (err) {
262 + console.log(err, data);
263 + console.log("delete error");
264 + res.status(304).send({ error: "delete error" });
265 + } else {
266 + let values = ['/', '/trashcan/', name, user_id];
267 + let updatesql = 'UPDATE files SET location = ? WHERE location = ? AND folder_name = ? AND user_id = ?;';
268 + connection.query(updatesql, values, function(err3, result, field) {
269 + if (err3) {
270 + console.log("updatesql error");
271 + res.status(304).send({ error: "updatesql error" });
272 + } else {
273 + let resultsql = 'SELECT * FROM files WHERE location = ? AND user_id = ?;';
274 + connection.query(resultsql, ['/trashcan/', user_id], function(err, file, fields) {
275 + res.status(200).send({
276 + files: file
277 + });
278 + });
279 + }
280 + });
281 + }
282 + });
283 + }
284 + });
285 + } else {
286 + console.log("Does not exist file");
287 + res.status(304).send({ error: "Does not exist" });
288 + }
289 + });
290 +
291 + }
292 +});
293 +
182 module.exports = router; 294 module.exports = router;
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -518,7 +518,8 @@ export default { ...@@ -518,7 +518,8 @@ export default {
518 name: this.curfName.folder_name, 518 name: this.curfName.folder_name,
519 }; 519 };
520 console.log(cData); 520 console.log(cData);
521 - const response = await delFavorite(cData); 521 + const del = await delFavorite(cData);
522 + const response = await getFavoriteList(this.$store.state.id);
522 this.$store.commit('setfavFolderList', response.data.folders); 523 this.$store.commit('setfavFolderList', response.data.folders);
523 } catch (error) { 524 } catch (error) {
524 console.log('에러'); 525 console.log('에러');
...@@ -546,7 +547,8 @@ export default { ...@@ -546,7 +547,8 @@ export default {
546 name: this.cfilename.file_name, 547 name: this.cfilename.file_name,
547 }; 548 };
548 console.log(fData); 549 console.log(fData);
549 - const response = await delFavoriteFile(fData); 550 + const del = await delFavoriteFile(fData);
551 + const response = await getFavoriteList(this.$store.state.id);
550 this.$store.commit('setfavFileList', response.data.files); 552 this.$store.commit('setfavFileList', response.data.files);
551 } catch (error) { 553 } catch (error) {
552 console.log('에러'); 554 console.log('에러');
......