박기범

merge

......@@ -7,9 +7,7 @@ var S3 = require('../modules/s3/s3');
// /file/delete/:name
router.get('/:name', function(req, res) {
console.log(req.query);
console.log(req.params);
router.get('/:name', function (req, res) {
var file_name = req.params.name;
var user_id = req.query.id;
var curPath = req.query.cur;
......@@ -17,56 +15,35 @@ router.get('/:name', function(req, res) {
var targetPath = 'trashcan';
var sourceFile = curPath.substring(1) + file_name;
var sql1 = 'UPDATE files SET location = ? WHERE location = ? AND file_name = ? AND user_id = ?;';
connection.query(sql1, ['/trashcan/', curPath, file_name, user_id], function(err) {
var sql1 = 'DELETE FROM files WHERE file_name = (?) AND location=(?) AND user_Id = (?)';
var sql2 = 'INSERT INTO trashcan (trash_name, location, user_Id) VALUES (?, ?, ?)';
connection.query(sql1, [file_name, curPath, user_id], function (err) {
if (err) {
console.log('delete db error');
res.send({erorr: 'db delete error'});
}
else {
//connection.query(sql2, [file_name, '/trashcan'+curPath, user_id], function (err) {
connection.query(sql2, [file_name, '/trashcan/', user_id], function (err) {
if (err) {
console.log('update db error');
res.send({ erorr: 'db update error' });
} else {
S3.moveFile2(S3.BUCKET_NAME, user_id, sourceFile, file_name, targetPath, function(result) {
console.log('insert in trashcan db error');
res.send({error: 'db insert error'});
}
else {
// /drive/user_id/sourceFile --> /drive/user_id/trashcan/sourceFile
S3.moveFile4(S3.BUCKET_NAME, user_id, sourceFile, targetPath, function (result) {
if (result) {
res.send("move to trashcan success");
res.send({message: "move to trashcan success"});
}else{
res.send({err: "no such file"})
}
})
}
})
}
})
});
// // /file/delete/:name
// router.get('/:name', function (req, res) {
// var file_name = req.params.name;
// var user_id = req.query.id;
// var curPath = req.query.cur;
// var targetPath = 'trashcan';
// var sourceFile = curPath.substring(1) + file_name;
// var sql1 = 'DELETE FROM files WHERE file_name = (?) AND location=(?) AND user_Id = (?)';
// var sql2 = 'INSERT INTO trashcan (trash_name, location, user_Id) VALUES (?, ?, ?)';
// connection.query(sql1, [file_name, curPath, user_id], function (err) {
// if (err) {
// console.log('delete db error');
// res.send({erorr: 'db delete error'});
// }
// else {
// connection.query(sql2, [file_name, '/trashcan'+curPath, user_id], function (err) {
// if (err) {
// console.log('insert in trashcan db error');
// res.send({error: 'db insert error'});
// }
// else {
// // /drive/user_id/sourceFile --> /drive/user_id/trashcan/sourceFile
// S3.moveFile2(S3.BUCKET_NAME, user_id, sourceFile, targetPath, function (result) {
// if (result) {
// res.send("move to trashcan success");
// }
// })
// }
// })
// }
// })
// });
module.exports = router;
\ No newline at end of file
......
......@@ -16,6 +16,7 @@ router.get('/:name', function (req, res) {
var user_id = req.query.id;
var targetFile = curPath.substring(1) + file_name; // folder1/folder2/test.txt
console.log(targetFile);
S3.downloadFile3(S3.BUCKET_NAME, user_id, targetFile, function (result, downloadDir) {
......@@ -29,7 +30,7 @@ router.get('/:name', function (req, res) {
}
})
}else{
res.send({ err: 'download error'})
res.send({ err: 'no such file'})
}
})
});
......
......@@ -9,25 +9,24 @@ var fs = require('fs');
// /file
router.get('/', function(req, res) {
console.log(req.query);
router.get('/', function (req, res) {
var user_id = req.query.id;
var curPath = req.query.cur; // /folder1/folder2/
var sql = 'SELECT * FROM files WHERE user_id=(?) AND location=(?) ORDER BY date DESC';
connection.query(sql, [user_id, curPath], function(err, result) {
if (err) {
res.send({ error: 'select error' });
} else {
connection.query(sql, [user_id, curPath], function (err, result) {
if (err){
res.send({error: 'select error'});
}else{
res.status(200).send({ files: result });
res.status(200).send({files: result});
}
})
});
router.get('/:name', function(req, res) {
router.get('/:name', function (req, res) {
var file_name = req.params.name;
var curPath = req.query.cur; // /folder1/folder2/
var user_id = req.query.id;
......@@ -36,11 +35,11 @@ router.get('/:name', function(req, res) {
var extension = targetFile.split('.')[1].toLowerCase();
S3.downloadFile2(S3.BUCKET_NAME, user_id, targetFile, function(result, downloadDir) {
if (result) {
S3.downloadFile2(S3.BUCKET_NAME, user_id, targetFile, function(result, downloadDir){
if (result){
var content;
content = fs.readFileSync(downloadDir, 'utf8');
res.send({ file_name: file_name, content: content });
res.send({file_name: file_name, content: content});
//if (extension == 'jpg' || extension == 'jpeg' || extension == 'png') {
// res.send({ type: 'image', src: downloadDir})
......
......@@ -22,7 +22,7 @@ router.post('/:name', function(req, res){
if (curPath == '/') {
targetPath = '';
} else {
targetPath = curPath.substring(1, curPaht.length-1); // folder1/folder2
targetPath = curPath.substring(1, curPath.length-1); // folder1/folder2
}
var originalDir = __dirname + '/../modules/s3/download/' + user_id + curPath + file_name;
......@@ -50,7 +50,7 @@ router.post('/:name', function(req, res){
res.send({ error: 'update error' });
} else {
fs.unlinkSync(tempDownloadDir);
res.send('modify file success');
res.send({message: 'modify file success'});
}
})
} else {
......
......@@ -16,7 +16,7 @@
var AWS = require('aws-sdk');
AWS.config.update({ region: 'ap-northeast-2' });
var BUCKET_NAME = 'qkrrlqja-test';
var BUCKET_NAME = 'khuloud';
var s3 = new AWS.S3();
var fs = require('fs');
......