최동원

.

...@@ -148,100 +148,105 @@ router.post('/delfolder', function(req, res, next) { ...@@ -148,100 +148,105 @@ router.post('/delfolder', function(req, res, next) {
148 148
149 149
150 router.post('/move', function(req, res, next) { 150 router.post('/move', function(req, res, next) {
151 - 151 + console.log(req.body);
152 - user_id = req.body.user_id; 152 + user_id = req.body.id;
153 - curPath = user_id + req.body.cur; 153 + let cur = req.body.cur;
154 - let name = req.body.mfile; 154 + curPath = user_id + cur;
155 - let newPath = req.body.newPath; 155 + let name = req.body.folder_name;
156 - let checkfolder = 'SELECT * FROM folders WHERE location = ? AND folder_name = ?;'; 156 + let newPath = user_id + req.body.newPath;
157 if (req.body.isfolder) { 157 if (req.body.isfolder) {
158 - 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);
159 if (rows.length != 0) { 161 if (rows.length != 0) {
160 let copy_params = { 162 let copy_params = {
161 - Bucket: BUCKET_NAME + curPath, 163 + Bucket: BUCKET_NAME,
162 - CopySource: BUCKET_NAME + curPath + file + '/', 164 + CopySource: BUCKET_NAME + '/' + curPath + name + '/',
163 - Key: newPath + file + '/' 165 + Key: newPath + name + '/'
164 }; 166 };
165 -
166 let del_params = { 167 let del_params = {
167 - Bucket: BUCKET_NAME + curPath, 168 + Bucket: BUCKET_NAME,
168 - Key: file + '/' 169 + Key: curPath + name + '/'
169 }; 170 };
170 s3.copyObject(copy_params, function(err, data) { 171 s3.copyObject(copy_params, function(err, data) {
171 - console.log(err, data); 172 + if (err) {
172 - }); 173 + console.log(err, data);
173 - s3.deleteObject(del_params, function(err, data) { 174 + console.log("copy error");
174 - console.log(err, data); 175 + res.status(304).send({ error: "copy error" });
175 - });
176 - let values = [newPath, curPath, name];
177 - let updatesql = 'UPDATE folders SET location = ? WHERE location = ? AND folder_name = ?;';
178 - connection.query(updatesql, values, function(err3, result, field) {
179 - if (err3) {
180 - throw err;
181 } else { 176 } else {
182 - folders = {} 177 + s3.deleteObject(del_params, function(err, data) {
183 - connection.query(checkfolder, [cur, user_id], function(err, rows, fields) { 178 + if (err) {
184 - if (rows.length != 0) { 179 + console.log(err, data);
185 - res.status(200).send({ 180 + console.log("delete error");
186 - folders: rows, 181 + res.status(304).send({ error: "delete error" });
187 - cur: curPath
188 - })
189 } else { 182 } else {
190 - res.send({ error: "Does not exist" }); 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 = ?;';
185 + connection.query(updatesql, values, function(err3, result, field) {
186 + if (err3) {
187 + console.log("updatesql error");
188 + res.status(304).send({ error: "updatesql error" });
189 + } else {
190 + let resultsql = 'SELECT * FROM folders WHERE location = ? AND user_id = ?;';
191 + connection.query(resultsql, [cur, user_id], function(err, rows, fields) {
192 + res.status(200).send({
193 + folders: rows
194 + });
195 + });
196 + }
197 + });
191 } 198 }
192 }); 199 });
193 } 200 }
194 }); 201 });
195 -
196 -
197 } else { 202 } else {
198 - res.send({ error: "Does not exist" }); 203 + console.log("Does not exist");
204 + res.status(304).send({ error: "Does not exist" });
199 } 205 }
200 }); 206 });
201 } else { 207 } else {
202 - let checkfile = 'SELECT * FROM files WHERE location = ? AND file_name = ?'; 208 + let checkfile = 'SELECT * FROM files WHERE location = ? AND file_name = ? AND user_id = ?';
203 - 209 + connection.query(checkfile, [curPath, name, user_id], function(err1, rows, fields) {
204 - connection.query(checkfile, [curPath, name], function(err1, rows, fields) {
205 if (rows.length != 0) { 210 if (rows.length != 0) {
206 let copy_params = { 211 let copy_params = {
207 - Bucket: BUCKET_NAME + curPath, 212 + Bucket: BUCKET_NAME,
208 - CopySource: BUCKET_NAME + curPath + file, 213 + CopySource: BUCKET_NAME + '/' + curPath + file,
209 Key: newPath + file 214 Key: newPath + file
210 }; 215 };
211 -
212 let del_params = { 216 let del_params = {
213 - Bucket: BUCKET_NAME + curPath, 217 + Bucket: BUCKET_NAME,
214 - Key: file 218 + Key: curPath + file
215 }; 219 };
216 s3.copyObject(copy_params, function(err, data) { 220 s3.copyObject(copy_params, function(err, data) {
217 - console.log(err, data); 221 + if (err) {
218 - }); 222 + console.log(err, data);
219 - s3.deleteObject(del_params, function(err, data) { 223 + res.status(304).send({ error: "copy error" });
220 - console.log(err, data);
221 - });
222 - let values = [newPath, curPath, name];
223 - let updatesql = 'UPDATE files SET location = ? WHERE location = ? AND file_name = ?;';
224 - connection.query(updatesql, values, function(err3, result, field) {
225 - if (err3) {
226 - throw err;
227 } else { 224 } else {
228 - folders = {} 225 + s3.deleteObject(del_params, function(err, data) {
229 - connection.query(checkfolder, [cur, user_id], function(err, rows, fields) { 226 + if (err) {
230 - if (rows.length != 0) { 227 + console.log(err, data);
231 - res.status(200).send({ 228 + res.status(304).send({ error: "delete error" });
232 - folders: rows,
233 - cur: curPath
234 - })
235 } else { 229 } else {
236 - res.send({ error: "Does not exist" }); 230 + let values = [newPath, cur, name, user_id];
231 + let updatesql = 'UPDATE files SET location = ? WHERE location = ? AND file_name = ? AND user_id = ?;';
232 + connection.query(updatesql, values, function(err3, result, field) {
233 + if (err3) {
234 + res.status(304).send({ error: "updatesql error" });
235 + } else {
236 + let resultsql = 'SELECT * FROM folders WHERE location = ? AND user_id = ?;';
237 + connection.query(resultsql, [cur, user_id], function(err, rows, fields) {
238 + res.status(200).send({
239 + folders: rows
240 + });
241 + });
242 + }
243 + });
237 } 244 }
238 }); 245 });
239 } 246 }
240 }); 247 });
241 -
242 -
243 } else { 248 } else {
244 - res.send({ error: "Does not exist" }); 249 + res.status(304).send({ error: "Does not exist" });
245 } 250 }
246 }); 251 });
247 252
......
...@@ -27,8 +27,14 @@ function makeFolder(folderData) { ...@@ -27,8 +27,14 @@ function makeFolder(folderData) {
27 return axios.post('/api/folder/makefolder', folderData); 27 return axios.post('/api/folder/makefolder', folderData);
28 } 28 }
29 29
30 -function deleteFolder(folderData){ 30 +function deleteFolder(folderData) {
31 return axios.post('/api/folder/delfolder', folderData); 31 return axios.post('/api/folder/delfolder', folderData);
32 } 32 }
33 33
34 -export { registerUser, loginUser, folder, makeFolder, deleteFolder };
...\ No newline at end of file ...\ No newline at end of file
34 +function moveFolder(folderData) {
35 + return axios.post('/api/folder/move', folderData);
36 +}
37 +
38 +
39 +
40 +export { registerUser, loginUser, folder, makeFolder, deleteFolder, moveFolder };
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -72,12 +72,28 @@ ...@@ -72,12 +72,28 @@
72 >Cancel</v-btn> 72 >Cancel</v-btn>
73 <v-btn 73 <v-btn
74 text 74 text
75 - @click="" 75 + @click="transferF(item.folder_name)"
76 >Move</v-btn> 76 >Move</v-btn>
77 </v-card-actions> 77 </v-card-actions>
78 </v-card> 78 </v-card>
79 </v-dialog> 79 </v-dialog>
80 - 80 + <v-menu
81 + v-model="showMenu"
82 + :position-x="x"
83 + :position-y="y"
84 + absolute
85 + offset-y
86 + >
87 + <v-list dense>
88 + <v-list-item @click.prevent="dialog2 = !dialog2">
89 + <v-list-item-title>이동</v-list-item-title>
90 + </v-list-item>
91 + <v-list-item @click.prevent="deleteF(item.folder_name)">
92 + <v-list-item-title>삭제</v-list-item-title>
93 + </v-list-item>
94 + </v-list>
95 + </v-menu>
96 + </v-list-item>
81 97
82 <v-divider inset></v-divider> 98 <v-divider inset></v-divider>
83 <v-subheader inset>Files</v-subheader> 99 <v-subheader inset>Files</v-subheader>
...@@ -173,7 +189,7 @@ ...@@ -173,7 +189,7 @@
173 </div> 189 </div>
174 </template> 190 </template>
175 <script> 191 <script>
176 -import { folder, makeFolder, deleteFolder } from '../api/index'; 192 +import { folder, makeFolder, deleteFolder, moveFolder } from '../api/index';
177 import Axios from 'axios'; 193 import Axios from 'axios';
178 export default { 194 export default {
179 data() { 195 data() {
...@@ -278,6 +294,26 @@ import Axios from 'axios'; ...@@ -278,6 +294,26 @@ import Axios from 'axios';
278 console.log(error.response.data); 294 console.log(error.response.data);
279 } 295 }
280 }, 296 },
297 + async transferF(folderName){
298 + try {
299 + const cData = {
300 + id: this.$store.state.id,
301 + cur : this.$store.state.cur,
302 + folder_name: folderName,
303 + isfolder: true,
304 + newPath: this.foldername
305 + }
306 + const response = await moveFolder(cData);
307 + console.log(response);
308 + this.$store.commit('setFolder', response.data.folders);
309 + } catch (error) {
310 + console.log("에러");
311 + console.log(error.response.data);
312 + } finally{
313 + this.initFolderName();
314 + this.dialog2 = false;
315 + }
316 + },
281 show (e) { 317 show (e) {
282 e.preventDefault() 318 e.preventDefault()
283 this.showMenu = false 319 this.showMenu = false
......