Hong

폴더삭제 구현

......@@ -29,27 +29,18 @@ router.get('/show', function(req, res, next) {
parentPath += '/';
}
}
folders = {}
let checkfolder = 'SELECT * FROM folders WHERE location = ? AND user_id = ?;';
connection.query(checkfolder, [curPath, user_id], function(err, rows, fields) {
if (err) {
console.log('select error');
res.status(404).send()
} else {
if (rows.length != 0) {
res.status(200).send({
folders: rows,
cur: curPath,
parentPath: parentPath
})
} else {
res.status(200).send({
folders: rows,
cur: curPath,
parentPath: parentPath
})
}
}
});
});
......@@ -70,6 +61,9 @@ router.post('/makefolder', function(req, res, next) {
let checksql = 'SELECT * FROM folders WHERE location = ? AND folder_name = ?;';
console.log(req.body)
connection.query(checksql, [cur, folder_name], function(err, rows, fields) {
if (err) {
} else {
if (rows.length == 0) {
s3.putObject(params, function(err, data) {
if (err) {
......@@ -77,8 +71,6 @@ router.post('/makefolder', function(req, res, next) {
throw err;
} else {
console.log(data);
}
});
let sql = 'INSERT INTO folders (folder_name,location,user_id,created) values (?,?,?,?);';
let values = [folder_name, cur, user_id, date];
connection.query(sql, values, function(err, result, field) {
......@@ -86,72 +78,70 @@ router.post('/makefolder', function(req, res, next) {
console.log('insert error');
throw err;
} else {
folders = {}
let checkfolder = 'SELECT * FROM folders WHERE location = ? AND user_id = ?;';
connection.query(checkfolder, [cur, user_id], function(err, rows, fields) {
if (rows.length != 0) {
console.log(rows);
res.status(200).send({
folders: rows
})
} else {
res.send({ error: "Does not exist" });
});
}
});
}
});
} else {
res.status(404).send({ error: "same name error" });
}
}
});
});
router.post('/delfolder', function(req, res, next) {
user_id = req.body.user_id;
curPath = user_id + req.body.cur;
user_id = req.body.id;
let cur = req.body.cur;
curPath = user_id + cur;
let folder_name = req.body.folder_name;
let params = {
Bucket: BUCKET_NAME + curPath,
Key: folder_name + '/'
Bucket: BUCKET_NAME,
Key: curPath + folder_name + '/'
};
let checksql = 'SELECT * FROM folders WHERE location = ? AND folder_name = ?;';
let values = [curPath, folder_name];
let checksql = 'SELECT * FROM folders WHERE location = ? AND folder_name = ? AND user_id = ?;';
let values = [cur, folder_name, user_id];
connection.query(checksql, values, function(err, rows, fields) {
if (err) {
res.status(404).send({ error: "error" });
} else {
if (rows.length != 0) {
s3.deleteObject(params, function(err, data) {
if (err) {
console.log('s3 error');
//throw err;
} else {
let sql = 'DELETE FROM folders WHERE location = ? AND folder_name = ?;';
console.log(data);
let sql = 'DELETE FROM folders WHERE location = ? AND folder_name = ? AND user_id = ?;';
connection.query(sql, values, function(err, result, field) {
if (err) {
//throw err;
} else {
folders = {}
console.log(cur);
console.log(user_id);
let checkfolder = 'SELECT * FROM folders WHERE location = ? AND user_id = ?;';
connection.query(checkfolder, [cur, user_id], function(err, rows, fields) {
if (rows.length != 0) {
res.status(200).send({
folders: rows,
cur: curPath
folders: rows
})
} else {
res.send({ error: "Does not exist" });
}
});
}
});
}
});
} else {
res.send({ error: "Does not exist" });
console.log(req.body);
res.status(304).send({ error: "Does not exist" });
}
}
});
});
......
......@@ -219,10 +219,9 @@ import Axios from 'axios';
cur : this.$store.state.cur,
folder_name: folderName
}
const reponse = await deleteFolder(cData);
console.log(response.data);
const response = await deleteFolder(cData);
console.log(response);
this.$store.commit('setFolder', response.data.folders);
this.$store.commit('setCur', response.data.cur);
} catch (error) {
console.log("에러");
console.log(error.response.data);
......