Hong

즐겨찾기ing

......@@ -44,8 +44,8 @@ router.post('/addfolder', function(req, res, next) {
console.log('update error');
res.status(400).send({ error: err });
} else {
let getfolder = 'SELECT * FROM folders WHERE location = ? AND user_id = ?;';
connection.query(getfolder, [cur, user_id], function(err, folders, fields) {
let getfolder = 'SELECT * FROM folders WHERE location = ? AND user_id = ? AND folder_name != ?;';
connection.query(getfolder, [cur, user_id, 'trashcan'], function(err, folders, fields) {
res.status(200).send({
folders: folders
})
......@@ -112,8 +112,8 @@ router.post('/delfolder', function(req, res, next) {
console.log('update error');
res.status(400).send({ error: err });
} else {
let getfolder = 'SELECT * FROM folders WHERE location = ? AND user_id = ?;';
connection.query(getfolder, [cur, user_id], function(err, folders, fields) {
let getfolder = 'SELECT * FROM folders WHERE location = ? AND user_id = ? AND folder_name != ?;';
connection.query(getfolder, [cur, user_id, 'trashcan'], function(err, folders, fields) {
res.status(200).send({
folders: folders
})
......
......@@ -179,4 +179,116 @@ router.get('/all', function(req, res, next) {
});
});
router.post('/restore', function(req, res, next) {
console.log(req.body);
let user_id = req.body.user_id;
let id = req.body.id;
if (req.body.isfolder) {
let checkfolder = 'SELECT * FROM folders WHERE folder_id = ? AND user_id = ?;';
connection.query(checkfolder, [id, user_id], function(err1, rows, fields) {
console.log(rows);
if (rows.length != 0) {
let curPath = user_id + '/trashcan/'
let name = rows[0].folder_name
let copy_params = {
Bucket: S3.BUCKET_NAM,
CopySource: S3.BUCKET_NAM + '/drive/' + curPath + name + '/',
Key: 'drive/' + user_id + '/' + name + '/'
};
let del_params = {
Bucket: S3.BUCKET_NAM,
Key: 'drive/' + curPath + name + '/'
};
s3.copyObject(copy_params, function(err, data) {
if (err) {
console.log(err, data);
console.log("copy error");
res.status(304).send({ error: "copy error" });
} else {
s3.deleteObject(del_params, function(err, data) {
if (err) {
console.log(err, data);
console.log("delete error");
res.status(304).send({ error: "delete error" });
} else {
let values = ['/', '/trashcan/', name, user_id];
let updatesql = 'UPDATE folders SET location = ? WHERE location = ? AND folder_name = ? AND user_id = ?;';
connection.query(updatesql, values, function(err3, result, field) {
if (err3) {
console.log("updatesql error");
res.status(304).send({ error: "updatesql error" });
} else {
let resultsql = 'SELECT * FROM folders WHERE location = ? AND user_id = ?;';
connection.query(resultsql, ['/trashcan/', user_id], function(err, folder, fields) {
res.status(200).send({
folders: folder
});
});
}
});
}
});
}
});
} else {
console.log("Does not exist folder");
res.status(304).send({ error: "Does not exist" });
}
});
} else {
let checkfile = 'SELECT * FROM files WHERE file_id = ? AND user_id = ?;';
connection.query(checkfile, [id, user_id], function(err1, rows, fields) {
console.log(rows);
if (rows.length != 0) {
let curPath = user_id + '/trashcan/'
let name = rows[0].file_name
let copy_params = {
Bucket: S3.BUCKET_NAME,
CopySource: S3.BUCKET_NAME + '/drive/' + curPath + name,
Key: 'drive/' + user_id + '/' + name
};
let del_params = {
Bucket: S3.BUCKET_NAME,
Key: 'drive/' + curPath + name
};
s3.copyObject(copy_params, function(err, data) {
if (err) {
console.log(err, data);
console.log("copy error");
res.status(304).send({ error: "copy error" });
} else {
s3.deleteObject(del_params, function(err, data) {
if (err) {
console.log(err, data);
console.log("delete error");
res.status(304).send({ error: "delete error" });
} else {
let values = ['/', '/trashcan/', name, user_id];
let updatesql = 'UPDATE files SET location = ? WHERE location = ? AND folder_name = ? AND user_id = ?;';
connection.query(updatesql, values, function(err3, result, field) {
if (err3) {
console.log("updatesql error");
res.status(304).send({ error: "updatesql error" });
} else {
let resultsql = 'SELECT * FROM files WHERE location = ? AND user_id = ?;';
connection.query(resultsql, ['/trashcan/', user_id], function(err, file, fields) {
res.status(200).send({
files: file
});
});
}
});
}
});
}
});
} else {
console.log("Does not exist file");
res.status(304).send({ error: "Does not exist" });
}
});
}
});
module.exports = router;
\ No newline at end of file
......
......@@ -518,7 +518,8 @@ export default {
name: this.curfName.folder_name,
};
console.log(cData);
const response = await delFavorite(cData);
const del = await delFavorite(cData);
const response = await getFavoriteList(this.$store.state.id);
this.$store.commit('setfavFolderList', response.data.folders);
} catch (error) {
console.log('에러');
......@@ -546,7 +547,8 @@ export default {
name: this.cfilename.file_name,
};
console.log(fData);
const response = await delFavoriteFile(fData);
const del = await delFavoriteFile(fData);
const response = await getFavoriteList(this.$store.state.id);
this.$store.commit('setfavFileList', response.data.files);
} catch (error) {
console.log('에러');
......