Showing
3 changed files
with
105 additions
and
58 deletions
... | @@ -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) { |
172 | + if (err) { | ||
171 | console.log(err, data); | 173 | console.log(err, data); |
172 | - }); | 174 | + console.log("copy error"); |
175 | + res.status(304).send({ error: "copy error" }); | ||
176 | + } else { | ||
173 | s3.deleteObject(del_params, function(err, data) { | 177 | s3.deleteObject(del_params, function(err, data) { |
178 | + if (err) { | ||
174 | console.log(err, data); | 179 | console.log(err, data); |
175 | - }); | 180 | + console.log("delete error"); |
176 | - let values = [newPath, curPath, name]; | 181 | + res.status(304).send({ error: "delete error" }); |
177 | - 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 = ?;'; | ||
178 | connection.query(updatesql, values, function(err3, result, field) { | 185 | connection.query(updatesql, values, function(err3, result, field) { |
179 | if (err3) { | 186 | if (err3) { |
180 | - throw err; | 187 | + console.log("updatesql error"); |
188 | + res.status(304).send({ error: "updatesql error" }); | ||
181 | } else { | 189 | } else { |
182 | - folders = {} | 190 | + let resultsql = 'SELECT * FROM folders WHERE location = ? AND user_id = ?;'; |
183 | - connection.query(checkfolder, [cur, user_id], function(err, rows, fields) { | 191 | + connection.query(resultsql, [cur, user_id], function(err, rows, fields) { |
184 | - if (rows.length != 0) { | ||
185 | res.status(200).send({ | 192 | res.status(200).send({ |
186 | - folders: rows, | 193 | + folders: rows |
187 | - cur: curPath | 194 | + }); |
188 | - }) | 195 | + }); |
189 | - } else { | 196 | + } |
190 | - res.send({ error: "Does not exist" }); | 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) { |
221 | + if (err) { | ||
217 | console.log(err, data); | 222 | console.log(err, data); |
218 | - }); | 223 | + res.status(304).send({ error: "copy error" }); |
224 | + } else { | ||
219 | s3.deleteObject(del_params, function(err, data) { | 225 | s3.deleteObject(del_params, function(err, data) { |
226 | + if (err) { | ||
220 | console.log(err, data); | 227 | console.log(err, data); |
221 | - }); | 228 | + res.status(304).send({ error: "delete error" }); |
222 | - let values = [newPath, curPath, name]; | 229 | + } else { |
223 | - 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 = ?;'; | ||
224 | connection.query(updatesql, values, function(err3, result, field) { | 232 | connection.query(updatesql, values, function(err3, result, field) { |
225 | if (err3) { | 233 | if (err3) { |
226 | - throw err; | 234 | + res.status(304).send({ error: "updatesql error" }); |
227 | } else { | 235 | } else { |
228 | - folders = {} | 236 | + let resultsql = 'SELECT * FROM folders WHERE location = ? AND user_id = ?;'; |
229 | - connection.query(checkfolder, [cur, user_id], function(err, rows, fields) { | 237 | + connection.query(resultsql, [cur, user_id], function(err, rows, fields) { |
230 | - if (rows.length != 0) { | ||
231 | res.status(200).send({ | 238 | res.status(200).send({ |
232 | - folders: rows, | 239 | + folders: rows |
233 | - cur: curPath | 240 | + }); |
234 | - }) | 241 | + }); |
235 | - } else { | 242 | + } |
236 | - res.send({ error: "Does not exist" }); | 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 | ... | ... |
-
Please register or login to post a comment