박기범

'.'

......@@ -8,32 +8,37 @@ var S3 = require('../modules/s3/s3');
// /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 user_id = req.session.user_id;
var sourceFile = req.params.name;
var targetPath = 'trashcan';
var sourceFile = curPath.substring(1) + file_name;
var paths = sourceFile.split('/');
var index = sourceFile.length - (paths[paths.length - 1].length + 1);
var file_name = paths[paths.length - 1];
var location = sourceFile.substring(6 + user_id.length, index);
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) {
connection.query(sql1, [file_name, location, user_id], function (err) {
if (err) {
console.log('delete db error');
res.status(404).send({erorr: 'db delete error'});
throw err;
}
else {
connection.query(sql2, [file_name, '/trashcan'+curPath, user_id], function (err) {
connection.query(sql2, [file_name, location, user_id], function (err) {
if (err) {
console.log('insert in trashcan db error');
res.status(404).send({error: 'db insert error'});
throw err;
}
else {
// /drive/user_id/sourceFile --> /drive/user_id/trashcan/sourceFile
S3.moveFile2(S3.BUCKET_NAME, user_id, sourceFile, targetPath, function (result) {
S3.moveFile(S3.BUCKET_NAME, user_id, sourceFile, targetPath, function (result) {
if (result) {
res.satus(200).send("move to trashcan success");
console.log("file move to trashcan success");
res.send("Upload Success");
}
})
}
......
......@@ -8,25 +8,22 @@ AWS.config.loadFromPath(__dirname + "/../modules/awsconfig.json");
var S3 = require('../modules/s3/s3');
// /file/download/:name
router.get('/:name', function (req, res) {
var file_name = req.params.name; // test.txt
var user_id = req.query.id;
var curPath = req.query.cur; // /folder1/folder2/
var targetFile = (curPath + file_name).substring(1); // folder1/folder2/test.txt
S3.downloadFile2(S3.BUCKET_NAME, user_id, targetFile, function (result, downloadDir) {
if (result){
res.download(downloadDir, function (err) {
fs.unlink(downloadDir, function (err) {
console.log('download success');
});
var file_name = req.params.name;
var user_id = req.session.user_id;
var sourceFile = file_name;
var tempDownloadDir = __dirname + '/../modules/s3/download/' + user_id + '/' + file_name;
S3.downloadFile(S3.BUCKET_NAME, user_id, sourceFile, function (result, data) {
!fs.existsSync(tempDownloadDir + '/../') && fs.mkdirSync(tempDownloadDir + '/../');
fs.writeFileSync(tempDownloadDir, data);
res.download(tempDownloadDir, function (err) {
fs.unlink(tempDownloadDir, function (err) {
console.log("Download Success");
});
}else{
res.status(404).send({error: 'download error'});
}
});
});
});
......
This diff is collapsed. Click to expand it.
{
"accessKeyId": "ASIAZQ5XTMMFRYJNKBIQ",
"secretAccessKey": "NNsqT/NamEdilVYzp/dS8ys2MMlEDEmyreZb6VLJ",
"sessionToken": "FwoGZXIvYXdzELP//////////wEaDJMOjkb8lIC9vGm9uCLDAWLA9QiZ4tlf+5oJaJE3MQeD6PKFGE1xTVNBTIKOY6ROuMC+sHfKVONokm+comkRD5z2Mi4l7XxSQDmOM3TtcuxwsJWw5aIKKUUUqCQbzqEy2JSAsJxBMUDiUGQnIlYJDCuB+uWWvfgAxUrDz/ReJQeXmpuFOVIymn12jTXy4scLZcz22cpiZj4pr9d05VOkzUyXozIHGEVEHgIV1qdy5sJLMicz4RQi4+bIuE5w4lCYdpk0nzduAHStgyWEN0/VjEbJSCiG48b2BTIt675GjnR/TJwYd8BOnqKzAwQyF4WxMzAgJ2NaCwPcE0ZR2/KVYQoIO1Os/Vk6",
"accessKeyId": "ASIAZQ5XTMMFRBJO2LG5",
"secretAccessKey": "ltsYvzKAoQ5UnNWEk13Zf8n4wJdkQkemsJ7GdsbS",
"sessionToken": "FwoGZXIvYXdzEI///////////wEaDLleFCvWDhdhFpXCvCLDAX/Hka6vXTZKxdyEBUh7ZSxPYLH184u1Tpo2qWHYFziUVKWJSCm5wqPNv0QWoAp8sL5NB0W5kty8hoeKv16SYB9Z+yzT1qtfuKTmrro2jGSo7AnxDSBla6UQHAv82yVetiGwu+IKhm6tHUvdNSlkIV0Qi9rNrDc9eynhFN/emFI/6NsocbQ47mmW6BZx0Z4/hHKW9TL6Uec/E87Z+oxVRFsVOGyNtow980bQgZFYJMbh3AN6poTlofP1q/qn2nUWwAdsDCjfhr/2BTItlcDfO5PEH5Gwffzv69JMTVBIemfIpS/Ybx6F6i7GbI2fZKGtGfRSecobbj4m",
"region": "us-east-1"
}
\ No newline at end of file
......
var mysql = require('mysql');
connection = mysql.createConnection({
//host: '1.201.142.243',
//user: 'khuloud',
//port: 3306,
//password: 'password1234',
//database: 'khuloud',
//connectionLimit: 30
host: 'localhost',
user: 'root',
host: '1.201.142.243',
user: 'khuloud',
port: 3306,
password: '1234',
database: 'temp'
password: 'password1234',
database: 'khuloud',
connectionLimit: 30
});
\ No newline at end of file
......
......@@ -52,8 +52,6 @@ var S3 = {
},
copyFile2: function (bucketName, userId, sourceFile, targetFile, callback) {
// sourceFile => folder1/folder2/test.txt
// targetFile => trashcan/folder1/folder2/test.txt
var copyParams = {
Bucket: bucketName,
CopySource: bucketName + '/drive/' + userId + '/' + sourceFile,
......@@ -74,7 +72,6 @@ var S3 = {
},
deleteFile: function (bucketName, userId, targetFile, callback) {
// targetFile => folder1/folder2/test.txt
var deleteParams = {
Bucket: bucketName,
Key: 'drive/' + userId + '/' + targetFile
......@@ -98,7 +95,7 @@ var S3 = {
Bucket: bucketName,
Key: 'drive/' + userId + '/' + targetFile
};
console.log('drive/' + userId + '/' + targetFile);
s3.getObject(downloadParams, function (err, data) {
if (err) {
console.log("Download File Error", err);
......@@ -106,51 +103,8 @@ var S3 = {
} else {
if (data) {
console.log("Get File Success");
callback(true, data.body);
}
}
})
},
// /routes/modules/s3/download에 저장
downloadFile2: function(bucketName, userId, targetFile, callback){
tempDownloadDir = __dirname + '/download/' + userId + '/' + targetFile;
S3.downloadFile(bucketName, userId, targetFile, function(result, data){
if (result) {
makeFolder(tempDownloadDir, function(result){
if (result) {
fs.writeFileSync(tempDownloadDir, data);
callback(true, tempDownloadDir);
}
})
}else{
console.log('Download File Error');
callback(false);
}
})
},
// 최종
downloadFile3: function(bucketName, userId, targetFile, callback){
// targetFile 예1 => test.txt
// targetFile 예2 => folder1/folder2/test.txt
var tempDownloadDir = __dirname + '/download/' + userId + '/' + targetFile;
makeFolder(tempDownloadDir, function(result){
if (result){
var file = fs.createWriteStream(tempDownloadDir);
var params = {
Bucket: bucketName,
Key: 'drive/' + userId + '/' + targetFile
};
try {
s3.getObject(params).createReadStream().pipe(file);
callback(true, tempDownloadDir);
}catch(err){
console.log('no such file');
callback(false);
callback(1, data.Body);
}
}else{
callback(false);
}
})
},
......@@ -220,20 +174,6 @@ var S3 = {
})
},
// 중복된 파일 버전 만들기(test.txt -> text(1).txt)
makeVersion: function (bucketName, userId, sourceFile, lvNum, callback) {
var sourceFile;
var splited = sourceFile.split('(').join(',').split(')').join(',').split(',');
if (splited.length != 3) {
sourceFile = sourceFile.split('.')[0] + '(' + lvNum.toString() + ').' + sourceFile.split('.')[1];
} else {
sourceFile = sourceFile.split('(')[0] + '(' + lvNum.toString() + ')' + sourceFile.split(')')[1];
}
console.log('makeVersion ', sourceFile);
callback(true, sourceFile);
},
// sourceFile이 단순히 filename과 같은 경우
moveFile: function (bucketName, userId, sourceFile, targetPath, callback) {
S3.copyFile(bucketName, userId, sourceFile, targetPath, function (res) {
......@@ -254,10 +194,25 @@ var S3 = {
})
},
makeVersion: function(bucketName, userId, sourceFile, lvNum, callback){
var sourceFile;
var splited = sourceFile.split('(').join(',').split(')').join(',').split(',');
if (splited.length != 3){
sourceFile = sourceFile.split('.')[0] + '(' + lvNum.toString() + ')' + sourceFile.split('.')[1];
}else{
sourceFile = sourceFile.split('(')[0] + '(' + lvNum.toString() + ')' + sourceFile.split(')')[1];
}
console.log('makeVersion ', sourceFile);
callback(true, sourceFile);
},
// sourceFile에 임의의 경로가 포함된 경우
moveFile2: function (bucketName, userId, sourceFile, targetPath, callback) {
// sourceFile => folder1/folder2/test.txt
var targetFile = targetPath + '/' + sourceFile;
var paths = sourceFile.split('/');
var filename = paths[paths.length - 1];
console.log('paths = ' + paths);
console.log('filename = ' + filename);
var targetFile = targetPath + filename;
S3.copyFile2(bucketName, userId, sourceFile, targetFile, function (res) {
if (!res) {
......@@ -280,11 +235,10 @@ var S3 = {
uploadFile: function (bucketName, userId, sourceFile, targetPath, body, callback) {
var pathbody = fs.createReadStream(body);
if (targetPath!='' && targetPath[targetPath.length-1]!='/') {
if (targetPath != '') {
targetPath = targetPath + '/';
}
var targetFile = targetPath + sourceFile;
console.log('targetFile', targetFile);
var uploadParams = {
Bucket: bucketName,
......@@ -345,23 +299,4 @@ var S3 = {
},
}
var makeFolder = function(dir, callback){
var paths = dir.substring(__dirname.length+1); // download/userId/folder1/folder2/test.txt
paths = paths.split('/');
var folders = __dirname;
for(var i=0; i<paths.length-1; i++){
folders += '/'+paths[i];
if(!fs.existsSync(folders)){
fs.mkdirSync(folders)
}
}
if (fs.existsSync(folders)){
callback(true);
}else{
callback(false);
}
}
module.exports = S3;
\ No newline at end of file
......
......@@ -205,9 +205,11 @@ import Axios from 'axios';
id : this.$store.state.id,
cur: '/'
}
console.log(curData);
const response = await folder(curData);
const file_response = await file(curData);
console.log(response.data);
console.log(file_response);
this.$store.commit('setFolder', response.data.folders);
this.$store.commit('setCur', response.data.cur);
this.$store.commit('setParent', response.data.parentPath);
......@@ -334,8 +336,14 @@ import Axios from 'axios';
this.$store.commit('setFile', filelist.data.files);
this.files = this.$store.getters.fileL;
}catch(error){
const fileData={
file: this.files,
user_id: this.$store.state.id,
cur: this.$store.state.cur
}
console.log(fileData);
console.log("에러");
console.log(error.reponse.err)
console.log(error.reponse.err);
}
},
show (folderN, e) {
......