Showing
2 changed files
with
56 additions
and
77 deletions
... | @@ -4,65 +4,56 @@ const router = express.Router(); | ... | @@ -4,65 +4,56 @@ 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 | - folders = []; | 7 | + let folders = []; |
8 | - files = []; | 8 | + let files = []; |
9 | 9 | ||
10 | - let checkfolder = 'SELECT * FROM Folder_Favorites WHERE user_id = ?;'; | 10 | + let checkfolder = 'SELECT * FROM folders WHERE user_id = ? AND favorite = 1;'; |
11 | - let checkfiles = 'SELECT * FROM File_Favorites WHERE user_id = ?;'; | 11 | + let checkfiles = 'SELECT * FROM files WHERE user_id = ? AND favorite = 1;'; |
12 | - connection.query(checkfolder, [user_id], function(err, rows, fields) { | 12 | + connection.query(checkfolder, [user_id], function(err, folder, fields) { |
13 | if (err) { | 13 | if (err) { |
14 | console.log('select error'); | 14 | console.log('select error'); |
15 | res.status(404).send(); | 15 | res.status(404).send(); |
16 | } else { | 16 | } else { |
17 | - folders.push(rows); | 17 | + folders.push(folder); |
18 | - } | 18 | + connection.query(checkfiles, [user_id], function(err, file, fields) { |
19 | - }); | ||
20 | - connection.query(checkfiles, [user_id], function(err, rows, fields) { | ||
21 | if (err) { | 19 | if (err) { |
22 | console.log('select error'); | 20 | console.log('select error'); |
23 | res.status(404).send(); | 21 | res.status(404).send(); |
24 | } else { | 22 | } else { |
25 | - files.push(rows); | 23 | + files.push(file); |
26 | - } | ||
27 | - }); | ||
28 | res.status(200).send({ | 24 | res.status(200).send({ |
29 | folders: folders, | 25 | folders: folders, |
30 | files: files | 26 | files: files |
31 | }); | 27 | }); |
28 | + } | ||
29 | + }); | ||
30 | + } | ||
31 | + }); | ||
32 | }); | 32 | }); |
33 | 33 | ||
34 | router.post('/addfolder', function(req, res, next) { | 34 | router.post('/addfolder', function(req, res, next) { |
35 | let user_id = req.body.id; | 35 | let user_id = req.body.id; |
36 | let folder_name = req.body.name; | 36 | let folder_name = req.body.name; |
37 | + let cur = req.body.cur; | ||
37 | console.log(req.body); | 38 | console.log(req.body); |
38 | - let getid = 'SELECT folder_id FROM folders WHERE user_id = ? AND folder_name = ?;'; | 39 | + let checkfolder = 'SELECT * FROM folders WHERE location = ? AND user_id = ? AND folder_name = ? AND favorite = 1;'; |
39 | - connection.query(getid, [user_id, folder_name], function(err, folder, fields) { | 40 | + connection.query(checkfolder, [cur, user_id, folder_name], function(err, rows, fields) { |
40 | - if (err) { | ||
41 | - console.log('getid error'); | ||
42 | - res.status(400).send({ error: err }); | ||
43 | - } else { | ||
44 | - if (folder.length == 0) { | ||
45 | - console.log('dont exist error'); | ||
46 | - res.status(400).send({ error: err }); | ||
47 | - } else { | ||
48 | - let folder_id = folder[0].folder_id; | ||
49 | - console.log(folder_id); | ||
50 | - let checkfolder = 'SELECT * FROM Folder_Favorites WHERE user_id = ? AND folder_id = ?;'; | ||
51 | - connection.query(checkfolder, [user_id, folder_id], function(err, rows, fields) { | ||
52 | if (err) { | 41 | if (err) { |
53 | console.log('select error'); | 42 | console.log('select error'); |
54 | res.status(400).send({ error: err }); | 43 | res.status(400).send({ error: err }); |
55 | } else { | 44 | } else { |
56 | if (rows.length == 0) { | 45 | if (rows.length == 0) { |
57 | - let sql = 'INSERT INTO Folder_Favorites (folder_id,user_id) values (?,?);'; | 46 | + let sql = 'UPDATE folders SET favorite = 1 WHERE location = ? AND folder_name = ? AND user_id = ?;'; |
58 | - connection.query(sql, [folder_id, user_id], function(err, result, fields) { | 47 | + connection.query(sql, [cur, folder_name, user_id], function(err, result, fields) { |
59 | if (err) { | 48 | if (err) { |
60 | - console.log('insert error'); | 49 | + console.log('update error'); |
61 | res.status(400).send({ error: err }); | 50 | res.status(400).send({ error: err }); |
62 | } else { | 51 | } else { |
52 | + let getfolder = 'SELECT * FROM folders WHERE location = ? AND user_id = ?;'; | ||
53 | + connection.query(getfolder, [cur, user_id], function(err, folders, fields) { | ||
63 | res.status(200).send({ | 54 | res.status(200).send({ |
64 | - success: 'success', | 55 | + folders: folders |
65 | - error: '' | 56 | + }) |
66 | }); | 57 | }); |
67 | } | 58 | } |
68 | }); | 59 | }); |
... | @@ -72,38 +63,31 @@ router.post('/addfolder', function(req, res, next) { | ... | @@ -72,38 +63,31 @@ router.post('/addfolder', function(req, res, next) { |
72 | } | 63 | } |
73 | } | 64 | } |
74 | }); | 65 | }); |
75 | - } | ||
76 | - } | ||
77 | - }); | ||
78 | }); | 66 | }); |
79 | 67 | ||
80 | router.post('/addfile', function(req, res, next) { | 68 | router.post('/addfile', function(req, res, next) { |
81 | let user_id = req.body.id; | 69 | let user_id = req.body.id; |
82 | let file_name = req.body.name; | 70 | let file_name = req.body.name; |
83 | - | 71 | + let cur = req.body.cur; |
84 | - let getid = 'SELECT file_id FROM files WHERE user_id = ? AND file_name = ?;'; | 72 | + console.log(req.body); |
85 | - connection.query(getid, [user_id, file_name], function(err, file, fields) { | 73 | + let checkfolder = 'SELECT * FROM files WHERE location = ? AND user_id = ? AND file_name = ? AND favorite = 1;'; |
86 | - if (err) { | 74 | + connection.query(checkfolder, [cur, user_id, file_name], function(err, rows, fields) { |
87 | - console.log('getid error'); | ||
88 | - res.status(400).send({ error: err }); | ||
89 | - } else { | ||
90 | - let file_id = file[0].file_id; | ||
91 | - let checkfile = 'SELECT * FROM File_Favorites WHERE user_id = ? AND file_id = ?;'; | ||
92 | - connection.query(checkfile, [user_id, file_id], function(err, rows, fields) { | ||
93 | if (err) { | 75 | if (err) { |
94 | console.log('select error'); | 76 | console.log('select error'); |
95 | res.status(400).send({ error: err }); | 77 | res.status(400).send({ error: err }); |
96 | } else { | 78 | } else { |
97 | if (rows.length == 0) { | 79 | if (rows.length == 0) { |
98 | - let sql = 'INSERT INTO File_Favorites (file_id,user_id) values (?,?);'; | 80 | + let sql = 'UPDATE files SET favorite = 1 WHERE location = ? AND file_name = ? AND user_id = ?;'; |
99 | - connection.query(sql, [file_id, user_id], function(err, result, fields) { | 81 | + connection.query(sql, [cur, file_name, user_id], function(err, result, fields) { |
100 | if (err) { | 82 | if (err) { |
101 | - console.log('insert error'); | 83 | + console.log('update error'); |
102 | res.status(400).send({ error: err }); | 84 | res.status(400).send({ error: err }); |
103 | } else { | 85 | } else { |
86 | + let getfolder = 'SELECT * FROM files WHERE location = ? AND user_id = ?;'; | ||
87 | + connection.query(getfolder, [cur, user_id], function(err, files, fields) { | ||
104 | res.status(200).send({ | 88 | res.status(200).send({ |
105 | - success: 'success', | 89 | + files: files |
106 | - error: '' | 90 | + }) |
107 | }); | 91 | }); |
108 | } | 92 | } |
109 | }); | 93 | }); |
... | @@ -113,14 +97,12 @@ router.post('/addfile', function(req, res, next) { | ... | @@ -113,14 +97,12 @@ router.post('/addfile', function(req, res, next) { |
113 | } | 97 | } |
114 | } | 98 | } |
115 | }); | 99 | }); |
116 | - } | ||
117 | - }); | ||
118 | }); | 100 | }); |
119 | 101 | ||
120 | router.post('/delfolder', function(req, res, next) { | 102 | router.post('/delfolder', function(req, res, next) { |
121 | let user_id = req.body.id; | 103 | let user_id = req.body.id; |
122 | let folder_name = req.body.name; | 104 | let folder_name = req.body.name; |
123 | - let checkfolder = 'SELECT * FROM Folder_Favorites JOIN folders ON (Folder_Favorites.folder_id = folders.folder_id AND Folder_Favorites.user_id = ? AND folders.folder_name = ?);'; | 105 | + let checkfolder = 'SELECT * FROM folders WHERE location = ? AND user_id = ? AND folder_name = ? AND favorite = 1;'; |
124 | 106 | ||
125 | connection.query(checkfolder, [user_id, folder_name], function(err, rows, fields) { | 107 | connection.query(checkfolder, [user_id, folder_name], function(err, rows, fields) { |
126 | if (err) { | 108 | if (err) { |
... | @@ -128,19 +110,20 @@ router.post('/delfolder', function(req, res, next) { | ... | @@ -128,19 +110,20 @@ router.post('/delfolder', function(req, res, next) { |
128 | res.status(400).send({ error: err }); | 110 | res.status(400).send({ error: err }); |
129 | } else { | 111 | } else { |
130 | if (rows.length != 0) { | 112 | if (rows.length != 0) { |
131 | - let folder_id = rows[0].folder_id; | 113 | + let sql = 'UPDATE folders SET favorite = 0 WHERE location = ? AND folder_name = ? AND user_id = ?;'; |
132 | - let sql = 'DELETE Folder_Favorites WHERE folder_id = ? AND user_id = ?;'; | 114 | + connection.query(sql, [cur, folder_name, user_id], function(err, result, fields) { |
133 | - connection.query(sql, [folder_id, user_id], function(err, result, fields) { | ||
134 | if (err) { | 115 | if (err) { |
135 | - console.log('delete error'); | 116 | + console.log('update error'); |
136 | res.status(400).send({ error: err }); | 117 | res.status(400).send({ error: err }); |
137 | } else { | 118 | } else { |
119 | + let getfolder = 'SELECT * FROM folders WHERE location = ? AND user_id = ?;'; | ||
120 | + connection.query(getfolder, [cur, user_id], function(err, folders, fields) { | ||
138 | res.status(200).send({ | 121 | res.status(200).send({ |
139 | - success: 'success', | 122 | + folders: folders |
140 | - error: '' | 123 | + }) |
141 | }); | 124 | }); |
142 | } | 125 | } |
143 | - }) | 126 | + }); |
144 | } else { | 127 | } else { |
145 | console.log('dont exist error'); | 128 | console.log('dont exist error'); |
146 | res.status(400).send({ error: err }); | 129 | res.status(400).send({ error: err }); |
... | @@ -152,7 +135,7 @@ router.post('/delfolder', function(req, res, next) { | ... | @@ -152,7 +135,7 @@ router.post('/delfolder', function(req, res, next) { |
152 | router.post('/delfile', function(req, res, next) { | 135 | router.post('/delfile', function(req, res, next) { |
153 | let user_id = req.body.id; | 136 | let user_id = req.body.id; |
154 | let file_name = req.body.name; | 137 | let file_name = req.body.name; |
155 | - let checkfile = 'SELECT * FROM File_Favorites JOIN files ON (File_Favorites.file_id = files.file_id AND File_Favorites.user_id = ? AND files.file_name = ?);'; | 138 | + let checkfile = 'SELECT * FROM files WHERE location = ? AND user_id = ? AND file_name = ? AND favorite = 1;'; |
156 | 139 | ||
157 | connection.query(checkfile, [user_id, file_name], function(err, rows, fields) { | 140 | connection.query(checkfile, [user_id, file_name], function(err, rows, fields) { |
158 | if (err) { | 141 | if (err) { |
... | @@ -160,19 +143,20 @@ router.post('/delfile', function(req, res, next) { | ... | @@ -160,19 +143,20 @@ router.post('/delfile', function(req, res, next) { |
160 | res.status(400).send({ error: err }); | 143 | res.status(400).send({ error: err }); |
161 | } else { | 144 | } else { |
162 | if (rows.length != 0) { | 145 | if (rows.length != 0) { |
163 | - let file_id = rows[0].file_id; | 146 | + let sql = 'UPDATE files SET favorite = 0 WHERE location = ? AND file_name = ? AND user_id = ?;'; |
164 | - let sql = 'DELETE File_Favorites WHERE file_id = ? AND user_id = ?;'; | 147 | + connection.query(sql, [cur, file_name, user_id], function(err, result, fields) { |
165 | - connection.query(sql, [file_id, user_id], function(err, result, fields) { | ||
166 | if (err) { | 148 | if (err) { |
167 | - console.log('insert error'); | 149 | + console.log('update error'); |
168 | res.status(400).send({ error: err }); | 150 | res.status(400).send({ error: err }); |
169 | } else { | 151 | } else { |
152 | + let getfolder = 'SELECT * FROM files WHERE location = ? AND user_id = ?;'; | ||
153 | + connection.query(getfolder, [cur, user_id], function(err, files, fields) { | ||
170 | res.status(200).send({ | 154 | res.status(200).send({ |
171 | - success: 'success', | 155 | + files: files |
172 | - error: '' | 156 | + }) |
173 | }); | 157 | }); |
174 | } | 158 | } |
175 | - }) | 159 | + }); |
176 | } else { | 160 | } else { |
177 | console.log('dont exist error'); | 161 | console.log('dont exist error'); |
178 | res.status(400).send({ error: err }); | 162 | res.status(400).send({ error: err }); | ... | ... |
... | @@ -2,16 +2,11 @@ var express = require('express'); | ... | @@ -2,16 +2,11 @@ var express = require('express'); |
2 | var request = require('request'); | 2 | var request = require('request'); |
3 | var async = require('async'); | 3 | var async = require('async'); |
4 | const AWS = require("aws-sdk"); | 4 | const AWS = require("aws-sdk"); |
5 | - | 5 | +AWS.config.loadFromPath(__dirname + "/../modules/awsconfig.json"); |
6 | var cryptoM = require('./../../routes/modules/cryptoM.js'); | 6 | var cryptoM = require('./../../routes/modules/cryptoM.js'); |
7 | 7 | ||
8 | const BUCKET_NAME = "hong-s3-cloud"; | 8 | const BUCKET_NAME = "hong-s3-cloud"; |
9 | - | 9 | +const s3 = new AWS.S3(); |
10 | -const s3 = new AWS.S3({ | ||
11 | - accessKeyId: process.env.AWS_ACCESS_KEY_ID, | ||
12 | - secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY, | ||
13 | - region: "ap-northeast-2" | ||
14 | -}); | ||
15 | 10 | ||
16 | var router = express.Router(); | 11 | var router = express.Router(); |
17 | 12 | ||
... | @@ -43,7 +38,7 @@ router.post('/', function(req, res, next) { | ... | @@ -43,7 +38,7 @@ router.post('/', function(req, res, next) { |
43 | } else { | 38 | } else { |
44 | let params = { | 39 | let params = { |
45 | Bucket: BUCKET_NAME, | 40 | Bucket: BUCKET_NAME, |
46 | - Key: user_id + '/', | 41 | + Key: 'drive/' + user_id + '/', |
47 | Body: "", | 42 | Body: "", |
48 | ACL: "public-read-write" | 43 | ACL: "public-read-write" |
49 | }; | 44 | }; |
... | @@ -53,7 +48,7 @@ router.post('/', function(req, res, next) { | ... | @@ -53,7 +48,7 @@ router.post('/', function(req, res, next) { |
53 | } else { | 48 | } else { |
54 | let params2 = { | 49 | let params2 = { |
55 | Bucket: BUCKET_NAME, | 50 | Bucket: BUCKET_NAME, |
56 | - Key: user_id + '/share/', | 51 | + Key: 'drive/' + user_id + '/share/', |
57 | Body: "", | 52 | Body: "", |
58 | ACL: "public-read-write" | 53 | ACL: "public-read-write" |
59 | }; | 54 | }; |
... | @@ -63,7 +58,7 @@ router.post('/', function(req, res, next) { | ... | @@ -63,7 +58,7 @@ router.post('/', function(req, res, next) { |
63 | } else { | 58 | } else { |
64 | let params3 = { | 59 | let params3 = { |
65 | Bucket: BUCKET_NAME, | 60 | Bucket: BUCKET_NAME, |
66 | - Key: user_id + '/trashcan/', | 61 | + Key: 'drive/' + user_id + '/trashcan/', |
67 | Body: "", | 62 | Body: "", |
68 | ACL: "public-read-write" | 63 | ACL: "public-read-write" |
69 | }; | 64 | }; | ... | ... |
-
Please register or login to post a comment