박기범

'.'

...@@ -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
......
...@@ -29,26 +29,17 @@ router.get('/show', function(req, res, next) { ...@@ -29,26 +29,17 @@ router.get('/show', function(req, res, next) {
29 parentPath += '/'; 29 parentPath += '/';
30 } 30 }
31 } 31 }
32 - folders = {}
33 let checkfolder = 'SELECT * FROM folders WHERE location = ? AND user_id = ?;'; 32 let checkfolder = 'SELECT * FROM folders WHERE location = ? AND user_id = ?;';
34 connection.query(checkfolder, [curPath, user_id], function(err, rows, fields) { 33 connection.query(checkfolder, [curPath, user_id], function(err, rows, fields) {
35 if (err) { 34 if (err) {
36 console.log('select error'); 35 console.log('select error');
37 res.status(404).send() 36 res.status(404).send()
38 } else { 37 } else {
39 - if (rows.length != 0) {
40 res.status(200).send({ 38 res.status(200).send({
41 folders: rows, 39 folders: rows,
42 cur: curPath, 40 cur: curPath,
43 parentPath: parentPath 41 parentPath: parentPath
44 }) 42 })
45 - } else {
46 - res.status(200).send({
47 - folders: rows,
48 - cur: curPath,
49 - parentPath: parentPath
50 - })
51 - }
52 } 43 }
53 }); 44 });
54 }); 45 });
...@@ -70,6 +61,9 @@ router.post('/makefolder', function(req, res, next) { ...@@ -70,6 +61,9 @@ router.post('/makefolder', function(req, res, next) {
70 let checksql = 'SELECT * FROM folders WHERE location = ? AND folder_name = ?;'; 61 let checksql = 'SELECT * FROM folders WHERE location = ? AND folder_name = ?;';
71 console.log(req.body) 62 console.log(req.body)
72 connection.query(checksql, [cur, folder_name], function(err, rows, fields) { 63 connection.query(checksql, [cur, folder_name], function(err, rows, fields) {
64 + if (err) {
65 +
66 + } else {
73 if (rows.length == 0) { 67 if (rows.length == 0) {
74 s3.putObject(params, function(err, data) { 68 s3.putObject(params, function(err, data) {
75 if (err) { 69 if (err) {
...@@ -77,8 +71,6 @@ router.post('/makefolder', function(req, res, next) { ...@@ -77,8 +71,6 @@ router.post('/makefolder', function(req, res, next) {
77 throw err; 71 throw err;
78 } else { 72 } else {
79 console.log(data); 73 console.log(data);
80 - }
81 - });
82 let sql = 'INSERT INTO folders (folder_name,location,user_id,created) values (?,?,?,?);'; 74 let sql = 'INSERT INTO folders (folder_name,location,user_id,created) values (?,?,?,?);';
83 let values = [folder_name, cur, user_id, date]; 75 let values = [folder_name, cur, user_id, date];
84 connection.query(sql, values, function(err, result, field) { 76 connection.query(sql, values, function(err, result, field) {
...@@ -86,172 +78,175 @@ router.post('/makefolder', function(req, res, next) { ...@@ -86,172 +78,175 @@ router.post('/makefolder', function(req, res, next) {
86 console.log('insert error'); 78 console.log('insert error');
87 throw err; 79 throw err;
88 } else { 80 } else {
89 - folders = {}
90 let checkfolder = 'SELECT * FROM folders WHERE location = ? AND user_id = ?;'; 81 let checkfolder = 'SELECT * FROM folders WHERE location = ? AND user_id = ?;';
91 connection.query(checkfolder, [cur, user_id], function(err, rows, fields) { 82 connection.query(checkfolder, [cur, user_id], function(err, rows, fields) {
92 - if (rows.length != 0) { 83 + console.log(rows);
93 res.status(200).send({ 84 res.status(200).send({
94 folders: rows 85 folders: rows
95 }) 86 })
96 - } else { 87 + });
97 - res.send({ error: "Does not exist" });
98 } 88 }
99 }); 89 });
100 } 90 }
101 }); 91 });
102 -
103 -
104 } else { 92 } else {
105 res.status(404).send({ error: "same name error" }); 93 res.status(404).send({ error: "same name error" });
106 } 94 }
95 + }
107 }); 96 });
108 }); 97 });
109 98
110 99
111 router.post('/delfolder', function(req, res, next) { 100 router.post('/delfolder', function(req, res, next) {
112 101
113 - user_id = req.body.user_id; 102 + user_id = req.body.id;
114 - curPath = user_id + req.body.cur; 103 + let cur = req.body.cur;
104 + curPath = user_id + cur;
115 let folder_name = req.body.folder_name; 105 let folder_name = req.body.folder_name;
116 let params = { 106 let params = {
117 - Bucket: BUCKET_NAME + curPath, 107 + Bucket: BUCKET_NAME,
118 - Key: folder_name + '/' 108 + Key: curPath + folder_name + '/'
119 }; 109 };
120 - let checksql = 'SELECT * FROM folders WHERE location = ? AND folder_name = ?;'; 110 + let checksql = 'SELECT * FROM folders WHERE location = ? AND folder_name = ? AND user_id = ?;';
121 - let values = [curPath, folder_name]; 111 + let values = [cur, folder_name, user_id];
122 -
123 connection.query(checksql, values, function(err, rows, fields) { 112 connection.query(checksql, values, function(err, rows, fields) {
113 + if (err) {
114 + res.status(404).send({ error: "error" });
115 + } else {
124 if (rows.length != 0) { 116 if (rows.length != 0) {
125 s3.deleteObject(params, function(err, data) { 117 s3.deleteObject(params, function(err, data) {
126 if (err) { 118 if (err) {
119 + console.log('s3 error');
127 //throw err; 120 //throw err;
128 } else { 121 } else {
129 - let sql = 'DELETE FROM folders WHERE location = ? AND folder_name = ?;'; 122 + console.log(data);
123 + let sql = 'DELETE FROM folders WHERE location = ? AND folder_name = ? AND user_id = ?;';
130 connection.query(sql, values, function(err, result, field) { 124 connection.query(sql, values, function(err, result, field) {
131 if (err) { 125 if (err) {
132 //throw err; 126 //throw err;
133 } else { 127 } else {
134 - folders = {} 128 + console.log(cur);
129 + console.log(user_id);
135 let checkfolder = 'SELECT * FROM folders WHERE location = ? AND user_id = ?;'; 130 let checkfolder = 'SELECT * FROM folders WHERE location = ? AND user_id = ?;';
136 connection.query(checkfolder, [cur, user_id], function(err, rows, fields) { 131 connection.query(checkfolder, [cur, user_id], function(err, rows, fields) {
137 - if (rows.length != 0) {
138 res.status(200).send({ 132 res.status(200).send({
139 - folders: rows, 133 + folders: rows
140 - cur: curPath
141 }) 134 })
142 - } else {
143 - res.send({ error: "Does not exist" });
144 - }
145 }); 135 });
146 136
147 } 137 }
148 }); 138 });
149 } 139 }
150 }); 140 });
151 -
152 -
153 } else { 141 } else {
154 - res.send({ error: "Does not exist" }); 142 + console.log(req.body);
143 + res.status(304).send({ error: "Does not exist" });
144 + }
155 } 145 }
156 }); 146 });
157 }); 147 });
158 148
159 149
160 router.post('/move', function(req, res, next) { 150 router.post('/move', function(req, res, next) {
161 - 151 + console.log(req.body);
162 - user_id = req.body.user_id; 152 + user_id = req.body.id;
163 - curPath = user_id + req.body.cur; 153 + let cur = req.body.cur;
164 - let name = req.body.mfile; 154 + curPath = user_id + cur;
165 - let newPath = req.body.newPath; 155 + let name = req.body.folder_name;
166 - let checkfolder = 'SELECT * FROM folders WHERE location = ? AND folder_name = ?;'; 156 + let newPath = user_id + req.body.newPath;
167 if (req.body.isfolder) { 157 if (req.body.isfolder) {
168 - connection.query(checkfolder, [curPath, name], function(err1, rows, fields) { 158 + let checkfolder = 'SELECT * FROM folders WHERE location = ? AND folder_name = ? AND user_id = ?;';
159 + connection.query(checkfolder, [cur, name, user_id], function(err1, rows, fields) {
160 + console.log(rows);
169 if (rows.length != 0) { 161 if (rows.length != 0) {
170 let copy_params = { 162 let copy_params = {
171 - Bucket: BUCKET_NAME + curPath, 163 + Bucket: BUCKET_NAME,
172 - CopySource: BUCKET_NAME + curPath + file + '/', 164 + CopySource: BUCKET_NAME + '/' + curPath + name + '/',
173 - Key: newPath + file + '/' 165 + Key: newPath + name + '/'
174 }; 166 };
175 -
176 let del_params = { 167 let del_params = {
177 - Bucket: BUCKET_NAME + curPath, 168 + Bucket: BUCKET_NAME,
178 - Key: file + '/' 169 + Key: curPath + name + '/'
179 }; 170 };
180 s3.copyObject(copy_params, function(err, data) { 171 s3.copyObject(copy_params, function(err, data) {
172 + if (err) {
181 console.log(err, data); 173 console.log(err, data);
182 - }); 174 + console.log("copy error");
175 + res.status(304).send({ error: "copy error" });
176 + } else {
183 s3.deleteObject(del_params, function(err, data) { 177 s3.deleteObject(del_params, function(err, data) {
178 + if (err) {
184 console.log(err, data); 179 console.log(err, data);
185 - }); 180 + console.log("delete error");
186 - let values = [newPath, curPath, name]; 181 + res.status(304).send({ error: "delete error" });
187 - let updatesql = 'UPDATE folders SET location = ? WHERE location = ? AND folder_name = ?;'; 182 + } else {
183 + let values = [req.body.newPath, cur, name, user_id];
184 + let updatesql = 'UPDATE folders SET location = ? WHERE location = ? AND folder_name = ? AND user_id = ?;';
188 connection.query(updatesql, values, function(err3, result, field) { 185 connection.query(updatesql, values, function(err3, result, field) {
189 if (err3) { 186 if (err3) {
190 - throw err; 187 + console.log("updatesql error");
188 + res.status(304).send({ error: "updatesql error" });
191 } else { 189 } else {
192 - folders = {} 190 + let resultsql = 'SELECT * FROM folders WHERE location = ? AND user_id = ?;';
193 - connection.query(checkfolder, [cur, user_id], function(err, rows, fields) { 191 + connection.query(resultsql, [cur, user_id], function(err, rows, fields) {
194 - if (rows.length != 0) {
195 res.status(200).send({ 192 res.status(200).send({
196 - folders: rows, 193 + folders: rows
197 - cur: curPath 194 + });
198 - }) 195 + });
199 - } else { 196 + }
200 - res.send({ error: "Does not exist" }); 197 + });
201 } 198 }
202 }); 199 });
203 } 200 }
204 }); 201 });
205 -
206 -
207 } else { 202 } else {
208 - res.send({ error: "Does not exist" }); 203 + console.log("Does not exist");
204 + res.status(304).send({ error: "Does not exist" });
209 } 205 }
210 }); 206 });
211 } else { 207 } else {
212 - let checkfile = 'SELECT * FROM files WHERE location = ? AND file_name = ?'; 208 + let checkfile = 'SELECT * FROM files WHERE location = ? AND file_name = ? AND user_id = ?';
213 - 209 + connection.query(checkfile, [curPath, name, user_id], function(err1, rows, fields) {
214 - connection.query(checkfile, [curPath, name], function(err1, rows, fields) {
215 if (rows.length != 0) { 210 if (rows.length != 0) {
216 let copy_params = { 211 let copy_params = {
217 - Bucket: BUCKET_NAME + curPath, 212 + Bucket: BUCKET_NAME,
218 - CopySource: BUCKET_NAME + curPath + file, 213 + CopySource: BUCKET_NAME + '/' + curPath + file,
219 Key: newPath + file 214 Key: newPath + file
220 }; 215 };
221 -
222 let del_params = { 216 let del_params = {
223 - Bucket: BUCKET_NAME + curPath, 217 + Bucket: BUCKET_NAME,
224 - Key: file 218 + Key: curPath + file
225 }; 219 };
226 s3.copyObject(copy_params, function(err, data) { 220 s3.copyObject(copy_params, function(err, data) {
221 + if (err) {
227 console.log(err, data); 222 console.log(err, data);
228 - }); 223 + res.status(304).send({ error: "copy error" });
224 + } else {
229 s3.deleteObject(del_params, function(err, data) { 225 s3.deleteObject(del_params, function(err, data) {
226 + if (err) {
230 console.log(err, data); 227 console.log(err, data);
231 - }); 228 + res.status(304).send({ error: "delete error" });
232 - let values = [newPath, curPath, name]; 229 + } else {
233 - let updatesql = 'UPDATE files SET location = ? WHERE location = ? AND file_name = ?;'; 230 + let values = [newPath, cur, name, user_id];
231 + let updatesql = 'UPDATE files SET location = ? WHERE location = ? AND file_name = ? AND user_id = ?;';
234 connection.query(updatesql, values, function(err3, result, field) { 232 connection.query(updatesql, values, function(err3, result, field) {
235 if (err3) { 233 if (err3) {
236 - throw err; 234 + res.status(304).send({ error: "updatesql error" });
237 } else { 235 } else {
238 - folders = {} 236 + let resultsql = 'SELECT * FROM folders WHERE location = ? AND user_id = ?;';
239 - connection.query(checkfolder, [cur, user_id], function(err, rows, fields) { 237 + connection.query(resultsql, [cur, user_id], function(err, rows, fields) {
240 - if (rows.length != 0) {
241 res.status(200).send({ 238 res.status(200).send({
242 - folders: rows, 239 + folders: rows
243 - cur: curPath 240 + });
244 - }) 241 + });
245 - } else { 242 + }
246 - res.send({ error: "Does not exist" }); 243 + });
247 } 244 }
248 }); 245 });
249 } 246 }
250 }); 247 });
251 -
252 -
253 } else { 248 } else {
254 - res.send({ error: "Does not exist" }); 249 + res.status(304).send({ error: "Does not exist" });
255 } 250 }
256 }); 251 });
257 252
......
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) {
......