Hong

.

...@@ -4,9 +4,6 @@ const router = express.Router(); ...@@ -4,9 +4,6 @@ const router = express.Router();
4 router.get('/show', function(req, res, next) { 4 router.get('/show', function(req, res, next) {
5 console.log(req.query); 5 console.log(req.query);
6 user_id = req.query.id; 6 user_id = req.query.id;
7 - let folders = [];
8 - let files = [];
9 -
10 let checkfolder = 'SELECT * FROM folders WHERE user_id = ? AND favorite = 1;'; 7 let checkfolder = 'SELECT * FROM folders WHERE user_id = ? AND favorite = 1;';
11 let checkfiles = 'SELECT * FROM files WHERE user_id = ? AND favorite = 1;'; 8 let checkfiles = 'SELECT * FROM files WHERE user_id = ? AND favorite = 1;';
12 connection.query(checkfolder, [user_id], function(err, folder, fields) { 9 connection.query(checkfolder, [user_id], function(err, folder, fields) {
...@@ -14,16 +11,14 @@ router.get('/show', function(req, res, next) { ...@@ -14,16 +11,14 @@ router.get('/show', function(req, res, next) {
14 console.log('select error'); 11 console.log('select error');
15 res.status(404).send(); 12 res.status(404).send();
16 } else { 13 } else {
17 - folders.push(folder);
18 connection.query(checkfiles, [user_id], function(err, file, fields) { 14 connection.query(checkfiles, [user_id], function(err, file, fields) {
19 if (err) { 15 if (err) {
20 console.log('select error'); 16 console.log('select error');
21 res.status(404).send(); 17 res.status(404).send();
22 } else { 18 } else {
23 - files.push(file);
24 res.status(200).send({ 19 res.status(200).send({
25 - folders: folders, 20 + folders: folder,
26 - files: files 21 + files: file
27 }); 22 });
28 } 23 }
29 }); 24 });
......
...@@ -2,17 +2,14 @@ const express = require('express'); ...@@ -2,17 +2,14 @@ const express = require('express');
2 const router = express.Router(); 2 const router = express.Router();
3 const AWS = require("aws-sdk"); 3 const AWS = require("aws-sdk");
4 const moment = require("moment"); 4 const moment = require("moment");
5 +AWS.config.loadFromPath(__dirname + "/../modules/awsconfig.json");
5 6
6 const BUCKET_NAME = "qkrrlqja-test"; 7 const BUCKET_NAME = "qkrrlqja-test";
7 let curPath = ""; 8 let curPath = "";
8 let user_id = ""; 9 let user_id = "";
9 let parentPath = ""; 10 let parentPath = "";
10 11
11 -const s3 = new AWS.S3({ 12 +const s3 = new AWS.S3();
12 - accessKeyId: process.env.AWS_ACCESS_KEY_ID,
13 - secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
14 - region: "ap-northeast-2"
15 -});
16 13
17 router.get('/show', function(req, res, next) { 14 router.get('/show', function(req, res, next) {
18 console.log(req.query); 15 console.log(req.query);
...@@ -107,6 +104,16 @@ router.post('/delfolder', function(req, res, next) { ...@@ -107,6 +104,16 @@ router.post('/delfolder', function(req, res, next) {
107 Bucket: BUCKET_NAME, 104 Bucket: BUCKET_NAME,
108 Key: 'drive/' + curPath + folder_name + '/' 105 Key: 'drive/' + curPath + folder_name + '/'
109 }; 106 };
107 + let infolderpath = cur + name + '/';
108 + let checkinfolder = 'SELECT location FROM folders WHERE location = ? AND user_id = ? UNION ALL SELECT location FROM files WHERE location = ? AND user_id = ?;';
109 + connection.query(checkinfolder, [infolderpath, user_id, infolderpath, user_id], function(err, infolder) {
110 + if (err) {
111 + console.log("copy error");
112 + res.status(304).send({ error: "checkinfolder error" });
113 + } else {
114 + if (infolder.length != 0) {
115 + res.status(204).send({ error: "infolder exist!" })
116 + } else {
110 let checksql = 'SELECT * FROM folders WHERE location = ? AND folder_name = ? AND user_id = ?;'; 117 let checksql = 'SELECT * FROM folders WHERE location = ? AND folder_name = ? AND user_id = ?;';
111 let values = [cur, folder_name, user_id]; 118 let values = [cur, folder_name, user_id];
112 connection.query(checksql, values, function(err, rows, fields) { 119 connection.query(checksql, values, function(err, rows, fields) {
...@@ -144,6 +151,9 @@ router.post('/delfolder', function(req, res, next) { ...@@ -144,6 +151,9 @@ router.post('/delfolder', function(req, res, next) {
144 } 151 }
145 } 152 }
146 }); 153 });
154 + }
155 + }
156 + });
147 }); 157 });
148 158
149 159
...@@ -155,6 +165,16 @@ router.post('/move', function(req, res, next) { ...@@ -155,6 +165,16 @@ router.post('/move', function(req, res, next) {
155 let name = req.body.name; 165 let name = req.body.name;
156 let newPath = user_id + req.body.newPath; 166 let newPath = user_id + req.body.newPath;
157 if (req.body.isfolder) { 167 if (req.body.isfolder) {
168 + let infolderpath = cur + name + '/';
169 + let checkinfolder = 'SELECT location FROM folders WHERE location = ? AND user_id = ? UNION ALL SELECT location FROM files WHERE location = ? AND user_id = ?;';
170 + connection.query(checkinfolder, [infolderpath, user_id, infolderpath, user_id], function(err, infolder) {
171 + if (err) {
172 + console.log("copy error");
173 + res.status(304).send({ error: "checkinfolder error" });
174 + } else {
175 + if (infolder.length != 0) {
176 + res.status(204).send({ error: "infolder exist!" })
177 + } else {
158 let checkfolder = 'SELECT * FROM folders WHERE location = ? AND folder_name = ? AND user_id = ?;'; 178 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) { 179 connection.query(checkfolder, [cur, name, user_id], function(err1, rows, fields) {
160 console.log(rows); 180 console.log(rows);
...@@ -204,6 +224,9 @@ router.post('/move', function(req, res, next) { ...@@ -204,6 +224,9 @@ router.post('/move', function(req, res, next) {
204 res.status(304).send({ error: "Does not exist" }); 224 res.status(304).send({ error: "Does not exist" });
205 } 225 }
206 }); 226 });
227 + }
228 + }
229 + });
207 } else { 230 } else {
208 let checkfile = 'SELECT * FROM files WHERE location = ? AND file_name = ? AND user_id = ?;'; 231 let checkfile = 'SELECT * FROM files WHERE location = ? AND file_name = ? AND user_id = ?;';
209 connection.query(checkfile, [cur, name, user_id], function(err1, rows, fields) { 232 connection.query(checkfile, [cur, name, user_id], function(err1, rows, fields) {
...@@ -255,66 +278,66 @@ router.post('/move', function(req, res, next) { ...@@ -255,66 +278,66 @@ router.post('/move', function(req, res, next) {
255 }); 278 });
256 279
257 280
258 -router.post('/modify', function(req, res, next) { 281 +// router.post('/modify', function(req, res, next) {
259 - console.log(req.body); 282 +// console.log(req.body);
260 - user_id = req.body.id; 283 +// user_id = req.body.id;
261 - let cur = req.body.cur; 284 +// let cur = req.body.cur;
262 - curPath = user_id + cur; 285 +// curPath = user_id + cur;
263 - let name = req.body.folder_name; 286 +// let name = req.body.folder_name;
264 - let newName = req.body.newName; 287 +// let newName = req.body.newName;
265 288
266 - let checkfolder = 'SELECT * FROM folders WHERE location = ? AND folder_name = ? AND user_id = ?;'; 289 +// let checkfolder = 'SELECT * FROM folders WHERE location = ? AND folder_name = ? AND user_id = ?;';
267 - connection.query(checkfolder, [cur, name, user_id], function(err1, rows, fields) { 290 +// connection.query(checkfolder, [cur, name, user_id], function(err1, rows, fields) {
268 - console.log(rows); 291 +// console.log(rows);
269 - if (rows.length != 0) { 292 +// if (rows.length != 0) {
270 - let copy_params = { 293 +// let copy_params = {
271 - Bucket: BUCKET_NAME, 294 +// Bucket: BUCKET_NAME,
272 - CopySource: BUCKET_NAME + '/drive/' + curPath + name + '/', 295 +// CopySource: BUCKET_NAME + '/drive/' + curPath + name + '/',
273 - Key: 'drive/' + curPath + newName + '/' 296 +// Key: 'drive/' + curPath + newName + '/'
274 - }; 297 +// };
275 - let del_params = { 298 +// let del_params = {
276 - Bucket: BUCKET_NAME, 299 +// Bucket: BUCKET_NAME,
277 - Key: 'drive/' + curPath + name + '/' 300 +// Key: 'drive/' + curPath + name + '/'
278 - }; 301 +// };
279 - s3.copyObject(copy_params, function(err, data) { 302 +// s3.copyObject(copy_params, function(err, data) {
280 - if (err) { 303 +// if (err) {
281 - console.log(err, data); 304 +// console.log(err, data);
282 - console.log("copy error"); 305 +// console.log("copy error");
283 - res.status(304).send({ error: "copy error" }); 306 +// res.status(304).send({ error: "copy error" });
284 - } else { 307 +// } else {
285 - s3.deleteObject(del_params, function(err, data) { 308 +// s3.deleteObject(del_params, function(err, data) {
286 - if (err) { 309 +// if (err) {
287 - console.log(err, data); 310 +// console.log(err, data);
288 - console.log("delete error"); 311 +// console.log("delete error");
289 - res.status(304).send({ error: "delete error" }); 312 +// res.status(304).send({ error: "delete error" });
290 - } else { 313 +// } else {
291 - let date = moment().format(); 314 +// let date = moment().format();
292 - let values = [newName, date, cur, name, user_id]; 315 +// let values = [newName, date, cur, name, user_id];
293 - let updatesql = 'UPDATE folders SET folder_name = ? AND modify = ? WHERE location = ? AND folder_name = ? AND user_id = ?;'; 316 +// let updatesql = 'UPDATE folders SET folder_name = ? AND modify = ? WHERE location = ? AND folder_name = ? AND user_id = ?;';
294 - connection.query(updatesql, values, function(err3, result, field) { 317 +// connection.query(updatesql, values, function(err3, result, field) {
295 - if (err3) { 318 +// if (err3) {
296 - console.log("updatesql error"); 319 +// console.log("updatesql error");
297 - res.status(304).send({ error: "updatesql error" }); 320 +// res.status(304).send({ error: "updatesql error" });
298 - } else { 321 +// } else {
299 - let resultsql = 'SELECT * FROM folders WHERE location = ? AND user_id = ?;'; 322 +// let resultsql = 'SELECT * FROM folders WHERE location = ? AND user_id = ?;';
300 - connection.query(resultsql, [cur, user_id], function(err, rows, fields) { 323 +// connection.query(resultsql, [cur, user_id], function(err, rows, fields) {
301 - res.status(200).send({ 324 +// res.status(200).send({
302 - folders: rows 325 +// folders: rows
303 - }); 326 +// });
304 - }); 327 +// });
305 - } 328 +// }
306 - }); 329 +// });
307 - } 330 +// }
308 - }); 331 +// });
309 - } 332 +// }
310 - }); 333 +// });
311 - } else { 334 +// } else {
312 - console.log("Does not exist"); 335 +// console.log("Does not exist");
313 - res.status(304).send({ error: "Does not exist" }); 336 +// res.status(304).send({ error: "Does not exist" });
314 - } 337 +// }
315 - }); 338 +// });
316 339
317 -}); 340 +// });
318 341
319 router.get('/search', function(req, res, next) { 342 router.get('/search', function(req, res, next) {
320 console.log(req.query); 343 console.log(req.query);
......
...@@ -2,14 +2,11 @@ const express = require('express'); ...@@ -2,14 +2,11 @@ const express = require('express');
2 const router = express.Router(); 2 const router = express.Router();
3 const AWS = require("aws-sdk"); 3 const AWS = require("aws-sdk");
4 const moment = require("moment"); 4 const moment = require("moment");
5 +AWS.config.loadFromPath(__dirname + "/../modules/awsconfig.json");
5 6
6 const BUCKET_NAME = "hong-s3-cloud"; 7 const BUCKET_NAME = "hong-s3-cloud";
7 8
8 -const s3 = new AWS.S3({ 9 +const s3 = new AWS.S3();
9 - accessKeyId: process.env.AWS_ACCESS_KEY_ID,
10 - secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
11 - region: "ap-northeast-2"
12 -});
13 10
14 11
15 router.post('/', function(req, res, next) { 12 router.post('/', function(req, res, next) {
...@@ -25,15 +22,15 @@ router.post('/', function(req, res, next) { ...@@ -25,15 +22,15 @@ router.post('/', function(req, res, next) {
25 if (rows.length != 0) { 22 if (rows.length != 0) {
26 let copy_params = { 23 let copy_params = {
27 Bucket: BUCKET_NAME, 24 Bucket: BUCKET_NAME,
28 - CopySource: BUCKET_NAME + '/' + curPath + name, 25 + CopySource: BUCKET_NAME + '/drive/' + curPath + name,
29 - Key: target_id + '/share/' + name 26 + Key: 'drive/' + target_id + '/share/' + name
30 }; 27 };
31 s3.copyObject(copy_params, function(err, data) { 28 s3.copyObject(copy_params, function(err, data) {
32 if (err) { 29 if (err) {
33 console.log(err, data); 30 console.log(err, data);
34 res.status(304).send({ error: "copy error" }); 31 res.status(304).send({ error: "copy error" });
35 } else { 32 } else {
36 - let values = [name, cur, target_id]; 33 + let values = [name, '/share/', target_id];
37 let sharesql = 'INSERT INTO files (file_name,location,user_id) values (?,?,?);'; 34 let sharesql = 'INSERT INTO files (file_name,location,user_id) values (?,?,?);';
38 connection.query(sharesql, values, function(err3, result, field) { 35 connection.query(sharesql, values, function(err3, result, field) {
39 if (err3) { 36 if (err3) {
......