박기범

'.'

...@@ -8,32 +8,37 @@ var S3 = require('../modules/s3/s3'); ...@@ -8,32 +8,37 @@ var S3 = require('../modules/s3/s3');
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 - var file_name = req.params.name; 11 + var user_id = req.session.user_id;
12 - var user_id = req.query.id;
13 - var curPath = req.query.cur;
14 12
13 + var sourceFile = req.params.name;
15 var targetPath = 'trashcan'; 14 var targetPath = 'trashcan';
16 - var sourceFile = curPath.substring(1) + file_name; 15 +
16 + var paths = sourceFile.split('/');
17 + var index = sourceFile.length - (paths[paths.length - 1].length + 1);
18 + var file_name = paths[paths.length - 1];
19 + var location = sourceFile.substring(6 + user_id.length, index);
17 20
18 var sql1 = 'DELETE FROM files WHERE file_name = (?) AND location=(?) AND user_Id = (?)'; 21 var sql1 = 'DELETE FROM files WHERE file_name = (?) AND location=(?) AND user_Id = (?)';
19 var sql2 = 'INSERT INTO trashcan (trash_name, location, user_Id) VALUES (?, ?, ?)'; 22 var sql2 = 'INSERT INTO trashcan (trash_name, location, user_Id) VALUES (?, ?, ?)';
20 23
21 - connection.query(sql1, [file_name, curPath, user_id], function (err) { 24 +
25 + connection.query(sql1, [file_name, location, user_id], function (err) {
22 if (err) { 26 if (err) {
23 console.log('delete db error'); 27 console.log('delete db error');
24 - res.status(404).send({erorr: 'db delete error'}); 28 + throw err;
25 } 29 }
26 else { 30 else {
27 - connection.query(sql2, [file_name, '/trashcan'+curPath, user_id], function (err) { 31 + connection.query(sql2, [file_name, location, user_id], function (err) {
28 if (err) { 32 if (err) {
29 console.log('insert in trashcan db error'); 33 console.log('insert in trashcan db error');
30 - res.status(404).send({error: 'db insert error'}); 34 + throw err;
31 } 35 }
32 else { 36 else {
33 // /drive/user_id/sourceFile --> /drive/user_id/trashcan/sourceFile 37 // /drive/user_id/sourceFile --> /drive/user_id/trashcan/sourceFile
34 - S3.moveFile2(S3.BUCKET_NAME, user_id, sourceFile, targetPath, function (result) { 38 + S3.moveFile(S3.BUCKET_NAME, user_id, sourceFile, targetPath, function (result) {
35 if (result) { 39 if (result) {
36 - res.satus(200).send("move to trashcan success"); 40 + console.log("file move to trashcan success");
41 + res.send("Upload Success");
37 } 42 }
38 }) 43 })
39 } 44 }
......
...@@ -8,25 +8,22 @@ AWS.config.loadFromPath(__dirname + "/../modules/awsconfig.json"); ...@@ -8,25 +8,22 @@ AWS.config.loadFromPath(__dirname + "/../modules/awsconfig.json");
8 var S3 = require('../modules/s3/s3'); 8 var S3 = require('../modules/s3/s3');
9 9
10 10
11 -
12 // /file/download/:name 11 // /file/download/:name
13 router.get('/:name', function (req, res) { 12 router.get('/:name', function (req, res) {
14 - var file_name = req.params.name; // test.txt 13 + var file_name = req.params.name;
15 - var user_id = req.query.id; 14 + var user_id = req.session.user_id;
16 - var curPath = req.query.cur; // /folder1/folder2/ 15 +
17 - 16 + var sourceFile = file_name;
18 - var targetFile = (curPath + file_name).substring(1); // folder1/folder2/test.txt 17 + var tempDownloadDir = __dirname + '/../modules/s3/download/' + user_id + '/' + file_name;
19 - 18 +
20 - S3.downloadFile2(S3.BUCKET_NAME, user_id, targetFile, function (result, downloadDir) { 19 + S3.downloadFile(S3.BUCKET_NAME, user_id, sourceFile, function (result, data) {
21 - if (result){ 20 + !fs.existsSync(tempDownloadDir + '/../') && fs.mkdirSync(tempDownloadDir + '/../');
22 - res.download(downloadDir, function (err) { 21 + fs.writeFileSync(tempDownloadDir, data);
23 - fs.unlink(downloadDir, function (err) { 22 + res.download(tempDownloadDir, function (err) {
24 - console.log('download success'); 23 + fs.unlink(tempDownloadDir, function (err) {
24 + console.log("Download Success");
25 }); 25 });
26 }); 26 });
27 - }else{
28 - res.status(404).send({error: 'download error'});
29 - }
30 }); 27 });
31 }); 28 });
32 29
......
This diff is collapsed. Click to expand it.
1 { 1 {
2 - "accessKeyId": "ASIAZQ5XTMMFRYJNKBIQ", 2 + "accessKeyId": "ASIAZQ5XTMMFRBJO2LG5",
3 - "secretAccessKey": "NNsqT/NamEdilVYzp/dS8ys2MMlEDEmyreZb6VLJ", 3 + "secretAccessKey": "ltsYvzKAoQ5UnNWEk13Zf8n4wJdkQkemsJ7GdsbS",
4 - "sessionToken": "FwoGZXIvYXdzELP//////////wEaDJMOjkb8lIC9vGm9uCLDAWLA9QiZ4tlf+5oJaJE3MQeD6PKFGE1xTVNBTIKOY6ROuMC+sHfKVONokm+comkRD5z2Mi4l7XxSQDmOM3TtcuxwsJWw5aIKKUUUqCQbzqEy2JSAsJxBMUDiUGQnIlYJDCuB+uWWvfgAxUrDz/ReJQeXmpuFOVIymn12jTXy4scLZcz22cpiZj4pr9d05VOkzUyXozIHGEVEHgIV1qdy5sJLMicz4RQi4+bIuE5w4lCYdpk0nzduAHStgyWEN0/VjEbJSCiG48b2BTIt675GjnR/TJwYd8BOnqKzAwQyF4WxMzAgJ2NaCwPcE0ZR2/KVYQoIO1Os/Vk6", 4 + "sessionToken": "FwoGZXIvYXdzEI///////////wEaDLleFCvWDhdhFpXCvCLDAX/Hka6vXTZKxdyEBUh7ZSxPYLH184u1Tpo2qWHYFziUVKWJSCm5wqPNv0QWoAp8sL5NB0W5kty8hoeKv16SYB9Z+yzT1qtfuKTmrro2jGSo7AnxDSBla6UQHAv82yVetiGwu+IKhm6tHUvdNSlkIV0Qi9rNrDc9eynhFN/emFI/6NsocbQ47mmW6BZx0Z4/hHKW9TL6Uec/E87Z+oxVRFsVOGyNtow980bQgZFYJMbh3AN6poTlofP1q/qn2nUWwAdsDCjfhr/2BTItlcDfO5PEH5Gwffzv69JMTVBIemfIpS/Ybx6F6i7GbI2fZKGtGfRSecobbj4m",
5 "region": "us-east-1" 5 "region": "us-east-1"
6 } 6 }
...\ No newline at end of file ...\ No newline at end of file
......
1 var mysql = require('mysql'); 1 var mysql = require('mysql');
2 2
3 connection = mysql.createConnection({ 3 connection = mysql.createConnection({
4 - //host: '1.201.142.243', 4 + host: '1.201.142.243',
5 - //user: 'khuloud', 5 + user: 'khuloud',
6 - //port: 3306,
7 - //password: 'password1234',
8 - //database: 'khuloud',
9 - //connectionLimit: 30
10 - host: 'localhost',
11 - user: 'root',
12 port: 3306, 6 port: 3306,
13 - password: '1234', 7 + password: 'password1234',
14 - database: 'temp' 8 + database: 'khuloud',
9 + connectionLimit: 30
15 }); 10 });
...\ No newline at end of file ...\ No newline at end of file
......
1 -안녕
...\ No newline at end of file ...\ No newline at end of file
...@@ -52,8 +52,6 @@ var S3 = { ...@@ -52,8 +52,6 @@ var S3 = {
52 }, 52 },
53 53
54 copyFile2: function (bucketName, userId, sourceFile, targetFile, callback) { 54 copyFile2: function (bucketName, userId, sourceFile, targetFile, callback) {
55 - // sourceFile => folder1/folder2/test.txt
56 - // targetFile => trashcan/folder1/folder2/test.txt
57 var copyParams = { 55 var copyParams = {
58 Bucket: bucketName, 56 Bucket: bucketName,
59 CopySource: bucketName + '/drive/' + userId + '/' + sourceFile, 57 CopySource: bucketName + '/drive/' + userId + '/' + sourceFile,
...@@ -74,7 +72,6 @@ var S3 = { ...@@ -74,7 +72,6 @@ var S3 = {
74 }, 72 },
75 73
76 deleteFile: function (bucketName, userId, targetFile, callback) { 74 deleteFile: function (bucketName, userId, targetFile, callback) {
77 - // targetFile => folder1/folder2/test.txt
78 var deleteParams = { 75 var deleteParams = {
79 Bucket: bucketName, 76 Bucket: bucketName,
80 Key: 'drive/' + userId + '/' + targetFile 77 Key: 'drive/' + userId + '/' + targetFile
...@@ -98,7 +95,7 @@ var S3 = { ...@@ -98,7 +95,7 @@ var S3 = {
98 Bucket: bucketName, 95 Bucket: bucketName,
99 Key: 'drive/' + userId + '/' + targetFile 96 Key: 'drive/' + userId + '/' + targetFile
100 }; 97 };
101 - console.log('drive/' + userId + '/' + targetFile); 98 +
102 s3.getObject(downloadParams, function (err, data) { 99 s3.getObject(downloadParams, function (err, data) {
103 if (err) { 100 if (err) {
104 console.log("Download File Error", err); 101 console.log("Download File Error", err);
...@@ -106,51 +103,8 @@ var S3 = { ...@@ -106,51 +103,8 @@ var S3 = {
106 } else { 103 } else {
107 if (data) { 104 if (data) {
108 console.log("Get File Success"); 105 console.log("Get File Success");
109 - callback(true, data.body); 106 + callback(1, data.Body);
110 - }
111 - }
112 - })
113 - },
114 -
115 - // /routes/modules/s3/download에 저장
116 - downloadFile2: function(bucketName, userId, targetFile, callback){
117 - tempDownloadDir = __dirname + '/download/' + userId + '/' + targetFile;
118 - S3.downloadFile(bucketName, userId, targetFile, function(result, data){
119 - if (result) {
120 - makeFolder(tempDownloadDir, function(result){
121 - if (result) {
122 - fs.writeFileSync(tempDownloadDir, data);
123 - callback(true, tempDownloadDir);
124 - }
125 - })
126 - }else{
127 - console.log('Download File Error');
128 - callback(false);
129 - }
130 - })
131 - },
132 -
133 - // 최종
134 - downloadFile3: function(bucketName, userId, targetFile, callback){
135 - // targetFile 예1 => test.txt
136 - // targetFile 예2 => folder1/folder2/test.txt
137 - var tempDownloadDir = __dirname + '/download/' + userId + '/' + targetFile;
138 - makeFolder(tempDownloadDir, function(result){
139 - if (result){
140 - var file = fs.createWriteStream(tempDownloadDir);
141 - var params = {
142 - Bucket: bucketName,
143 - Key: 'drive/' + userId + '/' + targetFile
144 - };
145 - try {
146 - s3.getObject(params).createReadStream().pipe(file);
147 - callback(true, tempDownloadDir);
148 - }catch(err){
149 - console.log('no such file');
150 - callback(false);
151 } 107 }
152 - }else{
153 - callback(false);
154 } 108 }
155 }) 109 })
156 }, 110 },
...@@ -220,20 +174,6 @@ var S3 = { ...@@ -220,20 +174,6 @@ var S3 = {
220 }) 174 })
221 }, 175 },
222 176
223 - // 중복된 파일 버전 만들기(test.txt -> text(1).txt)
224 - makeVersion: function (bucketName, userId, sourceFile, lvNum, callback) {
225 - var sourceFile;
226 - var splited = sourceFile.split('(').join(',').split(')').join(',').split(',');
227 - if (splited.length != 3) {
228 - sourceFile = sourceFile.split('.')[0] + '(' + lvNum.toString() + ').' + sourceFile.split('.')[1];
229 - } else {
230 - sourceFile = sourceFile.split('(')[0] + '(' + lvNum.toString() + ')' + sourceFile.split(')')[1];
231 - }
232 - console.log('makeVersion ', sourceFile);
233 -
234 - callback(true, sourceFile);
235 - },
236 -
237 // sourceFile이 단순히 filename과 같은 경우 177 // sourceFile이 단순히 filename과 같은 경우
238 moveFile: function (bucketName, userId, sourceFile, targetPath, callback) { 178 moveFile: function (bucketName, userId, sourceFile, targetPath, callback) {
239 S3.copyFile(bucketName, userId, sourceFile, targetPath, function (res) { 179 S3.copyFile(bucketName, userId, sourceFile, targetPath, function (res) {
...@@ -254,10 +194,25 @@ var S3 = { ...@@ -254,10 +194,25 @@ var S3 = {
254 }) 194 })
255 }, 195 },
256 196
197 + makeVersion: function(bucketName, userId, sourceFile, lvNum, callback){
198 + var sourceFile;
199 + var splited = sourceFile.split('(').join(',').split(')').join(',').split(',');
200 + if (splited.length != 3){
201 + sourceFile = sourceFile.split('.')[0] + '(' + lvNum.toString() + ')' + sourceFile.split('.')[1];
202 + }else{
203 + sourceFile = sourceFile.split('(')[0] + '(' + lvNum.toString() + ')' + sourceFile.split(')')[1];
204 + }
205 + console.log('makeVersion ', sourceFile);
206 + callback(true, sourceFile);
207 + },
208 +
257 // sourceFile에 임의의 경로가 포함된 경우 209 // sourceFile에 임의의 경로가 포함된 경우
258 moveFile2: function (bucketName, userId, sourceFile, targetPath, callback) { 210 moveFile2: function (bucketName, userId, sourceFile, targetPath, callback) {
259 - // sourceFile => folder1/folder2/test.txt 211 + var paths = sourceFile.split('/');
260 - var targetFile = targetPath + '/' + sourceFile; 212 + var filename = paths[paths.length - 1];
213 + console.log('paths = ' + paths);
214 + console.log('filename = ' + filename);
215 + var targetFile = targetPath + filename;
261 216
262 S3.copyFile2(bucketName, userId, sourceFile, targetFile, function (res) { 217 S3.copyFile2(bucketName, userId, sourceFile, targetFile, function (res) {
263 if (!res) { 218 if (!res) {
...@@ -280,11 +235,10 @@ var S3 = { ...@@ -280,11 +235,10 @@ var S3 = {
280 uploadFile: function (bucketName, userId, sourceFile, targetPath, body, callback) { 235 uploadFile: function (bucketName, userId, sourceFile, targetPath, body, callback) {
281 var pathbody = fs.createReadStream(body); 236 var pathbody = fs.createReadStream(body);
282 237
283 - if (targetPath!='' && targetPath[targetPath.length-1]!='/') { 238 + if (targetPath != '') {
284 targetPath = targetPath + '/'; 239 targetPath = targetPath + '/';
285 } 240 }
286 var targetFile = targetPath + sourceFile; 241 var targetFile = targetPath + sourceFile;
287 - console.log('targetFile', targetFile);
288 242
289 var uploadParams = { 243 var uploadParams = {
290 Bucket: bucketName, 244 Bucket: bucketName,
...@@ -345,23 +299,4 @@ var S3 = { ...@@ -345,23 +299,4 @@ var S3 = {
345 }, 299 },
346 } 300 }
347 301
348 -var makeFolder = function(dir, callback){
349 - var paths = dir.substring(__dirname.length+1); // download/userId/folder1/folder2/test.txt
350 - paths = paths.split('/');
351 -
352 - var folders = __dirname;
353 - for(var i=0; i<paths.length-1; i++){
354 - folders += '/'+paths[i];
355 - if(!fs.existsSync(folders)){
356 - fs.mkdirSync(folders)
357 - }
358 - }
359 -
360 - if (fs.existsSync(folders)){
361 - callback(true);
362 - }else{
363 - callback(false);
364 - }
365 -}
366 -
367 module.exports = S3; 302 module.exports = S3;
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -205,9 +205,11 @@ import Axios from 'axios'; ...@@ -205,9 +205,11 @@ import Axios from 'axios';
205 id : this.$store.state.id, 205 id : this.$store.state.id,
206 cur: '/' 206 cur: '/'
207 } 207 }
208 + console.log(curData);
208 const response = await folder(curData); 209 const response = await folder(curData);
209 const file_response = await file(curData); 210 const file_response = await file(curData);
210 console.log(response.data); 211 console.log(response.data);
212 + console.log(file_response);
211 this.$store.commit('setFolder', response.data.folders); 213 this.$store.commit('setFolder', response.data.folders);
212 this.$store.commit('setCur', response.data.cur); 214 this.$store.commit('setCur', response.data.cur);
213 this.$store.commit('setParent', response.data.parentPath); 215 this.$store.commit('setParent', response.data.parentPath);
...@@ -334,8 +336,14 @@ import Axios from 'axios'; ...@@ -334,8 +336,14 @@ import Axios from 'axios';
334 this.$store.commit('setFile', filelist.data.files); 336 this.$store.commit('setFile', filelist.data.files);
335 this.files = this.$store.getters.fileL; 337 this.files = this.$store.getters.fileL;
336 }catch(error){ 338 }catch(error){
339 + const fileData={
340 + file: this.files,
341 + user_id: this.$store.state.id,
342 + cur: this.$store.state.cur
343 + }
344 + console.log(fileData);
337 console.log("에러"); 345 console.log("에러");
338 - console.log(error.reponse.err) 346 + console.log(error.reponse.err);
339 } 347 }
340 }, 348 },
341 show (folderN, e) { 349 show (folderN, e) {
......