Showing
5 changed files
with
38 additions
and
61 deletions
... | @@ -7,9 +7,7 @@ var S3 = require('../modules/s3/s3'); | ... | @@ -7,9 +7,7 @@ var S3 = require('../modules/s3/s3'); |
7 | 7 | ||
8 | 8 | ||
9 | // /file/delete/:name | 9 | // /file/delete/:name |
10 | -router.get('/:name', function(req, res) { | 10 | +router.get('/:name', function (req, res) { |
11 | - console.log(req.query); | ||
12 | - console.log(req.params); | ||
13 | var file_name = req.params.name; | 11 | var file_name = req.params.name; |
14 | var user_id = req.query.id; | 12 | var user_id = req.query.id; |
15 | var curPath = req.query.cur; | 13 | var curPath = req.query.cur; |
... | @@ -17,56 +15,35 @@ router.get('/:name', function(req, res) { | ... | @@ -17,56 +15,35 @@ router.get('/:name', function(req, res) { |
17 | var targetPath = 'trashcan'; | 15 | var targetPath = 'trashcan'; |
18 | var sourceFile = curPath.substring(1) + file_name; | 16 | var sourceFile = curPath.substring(1) + file_name; |
19 | 17 | ||
20 | - var sql1 = 'UPDATE files SET location = ? WHERE location = ? AND file_name = ? AND user_id = ?;'; | 18 | + var sql1 = 'DELETE FROM files WHERE file_name = (?) AND location=(?) AND user_Id = (?)'; |
21 | - connection.query(sql1, ['/trashcan/', curPath, file_name, user_id], function(err) { | 19 | + var sql2 = 'INSERT INTO trashcan (trash_name, location, user_Id) VALUES (?, ?, ?)'; |
20 | + | ||
21 | + connection.query(sql1, [file_name, curPath, user_id], function (err) { | ||
22 | + if (err) { | ||
23 | + console.log('delete db error'); | ||
24 | + res.send({erorr: 'db delete error'}); | ||
25 | + } | ||
26 | + else { | ||
27 | + //connection.query(sql2, [file_name, '/trashcan'+curPath, user_id], function (err) { | ||
28 | + connection.query(sql2, [file_name, '/trashcan/', user_id], function (err) { | ||
22 | if (err) { | 29 | if (err) { |
23 | - console.log('update db error'); | 30 | + console.log('insert in trashcan db error'); |
24 | - res.send({ erorr: 'db update error' }); | 31 | + res.send({error: 'db insert error'}); |
25 | - } else { | 32 | + } |
26 | - S3.moveFile2(S3.BUCKET_NAME, user_id, sourceFile, file_name, targetPath, function(result) { | 33 | + else { |
34 | + // /drive/user_id/sourceFile --> /drive/user_id/trashcan/sourceFile | ||
35 | + S3.moveFile4(S3.BUCKET_NAME, user_id, sourceFile, targetPath, function (result) { | ||
27 | if (result) { | 36 | if (result) { |
28 | - res.send("move to trashcan success"); | 37 | + res.send({message: "move to trashcan success"}); |
38 | + }else{ | ||
39 | + res.send({err: "no such file"}) | ||
40 | + } | ||
41 | + }) | ||
29 | } | 42 | } |
30 | }) | 43 | }) |
31 | } | 44 | } |
32 | }) | 45 | }) |
33 | }); | 46 | }); |
34 | 47 | ||
35 | -// // /file/delete/:name | ||
36 | -// router.get('/:name', function (req, res) { | ||
37 | -// var file_name = req.params.name; | ||
38 | -// var user_id = req.query.id; | ||
39 | -// var curPath = req.query.cur; | ||
40 | - | ||
41 | -// var targetPath = 'trashcan'; | ||
42 | -// var sourceFile = curPath.substring(1) + file_name; | ||
43 | - | ||
44 | -// var sql1 = 'DELETE FROM files WHERE file_name = (?) AND location=(?) AND user_Id = (?)'; | ||
45 | -// var sql2 = 'INSERT INTO trashcan (trash_name, location, user_Id) VALUES (?, ?, ?)'; | ||
46 | - | ||
47 | -// connection.query(sql1, [file_name, curPath, user_id], function (err) { | ||
48 | -// if (err) { | ||
49 | -// console.log('delete db error'); | ||
50 | -// res.send({erorr: 'db delete error'}); | ||
51 | -// } | ||
52 | -// else { | ||
53 | -// connection.query(sql2, [file_name, '/trashcan'+curPath, user_id], function (err) { | ||
54 | -// if (err) { | ||
55 | -// console.log('insert in trashcan db error'); | ||
56 | -// res.send({error: 'db insert error'}); | ||
57 | -// } | ||
58 | -// else { | ||
59 | -// // /drive/user_id/sourceFile --> /drive/user_id/trashcan/sourceFile | ||
60 | -// S3.moveFile2(S3.BUCKET_NAME, user_id, sourceFile, targetPath, function (result) { | ||
61 | -// if (result) { | ||
62 | -// res.send("move to trashcan success"); | ||
63 | -// } | ||
64 | -// }) | ||
65 | -// } | ||
66 | -// }) | ||
67 | -// } | ||
68 | -// }) | ||
69 | -// }); | ||
70 | - | ||
71 | 48 | ||
72 | module.exports = router; | 49 | module.exports = router; |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -16,6 +16,7 @@ router.get('/:name', function (req, res) { | ... | @@ -16,6 +16,7 @@ router.get('/:name', function (req, res) { |
16 | var user_id = req.query.id; | 16 | var user_id = req.query.id; |
17 | 17 | ||
18 | var targetFile = curPath.substring(1) + file_name; // folder1/folder2/test.txt | 18 | var targetFile = curPath.substring(1) + file_name; // folder1/folder2/test.txt |
19 | + console.log(targetFile); | ||
19 | 20 | ||
20 | 21 | ||
21 | S3.downloadFile3(S3.BUCKET_NAME, user_id, targetFile, function (result, downloadDir) { | 22 | S3.downloadFile3(S3.BUCKET_NAME, user_id, targetFile, function (result, downloadDir) { |
... | @@ -29,7 +30,7 @@ router.get('/:name', function (req, res) { | ... | @@ -29,7 +30,7 @@ router.get('/:name', function (req, res) { |
29 | } | 30 | } |
30 | }) | 31 | }) |
31 | }else{ | 32 | }else{ |
32 | - res.send({ err: 'download error'}) | 33 | + res.send({ err: 'no such file'}) |
33 | } | 34 | } |
34 | }) | 35 | }) |
35 | }); | 36 | }); | ... | ... |
... | @@ -9,25 +9,24 @@ var fs = require('fs'); | ... | @@ -9,25 +9,24 @@ var fs = require('fs'); |
9 | 9 | ||
10 | 10 | ||
11 | // /file | 11 | // /file |
12 | -router.get('/', function(req, res) { | 12 | +router.get('/', function (req, res) { |
13 | - console.log(req.query); | ||
14 | var user_id = req.query.id; | 13 | var user_id = req.query.id; |
15 | var curPath = req.query.cur; // /folder1/folder2/ | 14 | var curPath = req.query.cur; // /folder1/folder2/ |
16 | 15 | ||
17 | var sql = 'SELECT * FROM files WHERE user_id=(?) AND location=(?) ORDER BY date DESC'; | 16 | var sql = 'SELECT * FROM files WHERE user_id=(?) AND location=(?) ORDER BY date DESC'; |
18 | - connection.query(sql, [user_id, curPath], function(err, result) { | 17 | + connection.query(sql, [user_id, curPath], function (err, result) { |
19 | - if (err) { | 18 | + if (err){ |
20 | - res.send({ error: 'select error' }); | 19 | + res.send({error: 'select error'}); |
21 | - } else { | 20 | + }else{ |
22 | 21 | ||
23 | - res.status(200).send({ files: result }); | 22 | + res.status(200).send({files: result}); |
24 | } | 23 | } |
25 | }) | 24 | }) |
26 | }); | 25 | }); |
27 | 26 | ||
28 | 27 | ||
29 | 28 | ||
30 | -router.get('/:name', function(req, res) { | 29 | +router.get('/:name', function (req, res) { |
31 | var file_name = req.params.name; | 30 | var file_name = req.params.name; |
32 | var curPath = req.query.cur; // /folder1/folder2/ | 31 | var curPath = req.query.cur; // /folder1/folder2/ |
33 | var user_id = req.query.id; | 32 | var user_id = req.query.id; |
... | @@ -36,11 +35,11 @@ router.get('/:name', function(req, res) { | ... | @@ -36,11 +35,11 @@ router.get('/:name', function(req, res) { |
36 | var extension = targetFile.split('.')[1].toLowerCase(); | 35 | var extension = targetFile.split('.')[1].toLowerCase(); |
37 | 36 | ||
38 | 37 | ||
39 | - S3.downloadFile2(S3.BUCKET_NAME, user_id, targetFile, function(result, downloadDir) { | 38 | + S3.downloadFile2(S3.BUCKET_NAME, user_id, targetFile, function(result, downloadDir){ |
40 | - if (result) { | 39 | + if (result){ |
41 | var content; | 40 | var content; |
42 | content = fs.readFileSync(downloadDir, 'utf8'); | 41 | content = fs.readFileSync(downloadDir, 'utf8'); |
43 | - res.send({ file_name: file_name, content: content }); | 42 | + res.send({file_name: file_name, content: content}); |
44 | 43 | ||
45 | //if (extension == 'jpg' || extension == 'jpeg' || extension == 'png') { | 44 | //if (extension == 'jpg' || extension == 'jpeg' || extension == 'png') { |
46 | // res.send({ type: 'image', src: downloadDir}) | 45 | // res.send({ type: 'image', src: downloadDir}) | ... | ... |
... | @@ -22,7 +22,7 @@ router.post('/:name', function(req, res){ | ... | @@ -22,7 +22,7 @@ router.post('/:name', function(req, res){ |
22 | if (curPath == '/') { | 22 | if (curPath == '/') { |
23 | targetPath = ''; | 23 | targetPath = ''; |
24 | } else { | 24 | } else { |
25 | - targetPath = curPath.substring(1, curPaht.length-1); // folder1/folder2 | 25 | + targetPath = curPath.substring(1, curPath.length-1); // folder1/folder2 |
26 | } | 26 | } |
27 | 27 | ||
28 | var originalDir = __dirname + '/../modules/s3/download/' + user_id + curPath + file_name; | 28 | var originalDir = __dirname + '/../modules/s3/download/' + user_id + curPath + file_name; |
... | @@ -50,7 +50,7 @@ router.post('/:name', function(req, res){ | ... | @@ -50,7 +50,7 @@ router.post('/:name', function(req, res){ |
50 | res.send({ error: 'update error' }); | 50 | res.send({ error: 'update error' }); |
51 | } else { | 51 | } else { |
52 | fs.unlinkSync(tempDownloadDir); | 52 | fs.unlinkSync(tempDownloadDir); |
53 | - res.send('modify file success'); | 53 | + res.send({message: 'modify file success'}); |
54 | } | 54 | } |
55 | }) | 55 | }) |
56 | } else { | 56 | } else { | ... | ... |
... | @@ -16,7 +16,7 @@ | ... | @@ -16,7 +16,7 @@ |
16 | var AWS = require('aws-sdk'); | 16 | var AWS = require('aws-sdk'); |
17 | AWS.config.update({ region: 'ap-northeast-2' }); | 17 | AWS.config.update({ region: 'ap-northeast-2' }); |
18 | 18 | ||
19 | -var BUCKET_NAME = 'qkrrlqja-test'; | 19 | +var BUCKET_NAME = 'khuloud'; |
20 | 20 | ||
21 | var s3 = new AWS.S3(); | 21 | var s3 = new AWS.S3(); |
22 | var fs = require('fs'); | 22 | var fs = require('fs'); | ... | ... |
-
Please register or login to post a comment