최동원

Merge branch 'share,favorite' of http://khuhub.khu.ac.kr/2020-1-CloudComputing/D…

…_Team_Khuloud into share,favorite
......@@ -33,7 +33,7 @@ router.get('/show', function(req, res, next) {
connection.query(checkfolder, [curPath, user_id], function(err, rows, fields) {
if (err) {
console.log('select error');
res.status(404).send()
res.status(400).send({ err: err });
} else {
res.status(200).send({
folders: rows,
......@@ -62,12 +62,13 @@ router.post('/makefolder', function(req, res, next) {
console.log(req.body)
connection.query(checksql, [cur, folder_name], function(err, rows, fields) {
if (err) {
res.status(400).send({ err: err });
} else {
if (rows.length == 0) {
s3.putObject(params, function(err, data) {
if (err) {
console.log('s3 error');
res.status(400).send({ err: err });
} else {
console.log(data);
let sql = 'INSERT INTO folders (folder_name,location,user_id,created) values (?,?,?,?);';
......@@ -75,7 +76,7 @@ router.post('/makefolder', function(req, res, next) {
connection.query(sql, values, function(err, result, field) {
if (err) {
console.log('insert error');
throw err;
res.status(400).send({ err: err });
} else {
let checkfolder = 'SELECT * FROM folders WHERE location = ? AND user_id = ?;';
connection.query(checkfolder, [cur, user_id], function(err, rows, fields) {
......@@ -116,13 +117,13 @@ router.post('/delfolder', function(req, res, next) {
s3.deleteObject(params, function(err, data) {
if (err) {
console.log('s3 error');
//throw err;
res.status(400).send({ err: err });
} else {
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;
res.status(400).send({ err: err });
} else {
console.log(cur);
console.log(user_id);
......
......@@ -4,6 +4,7 @@ var async = require('async');
const AWS = require("aws-sdk");
AWS.config.loadFromPath(__dirname + "/../modules/awsconfig.json");
var cryptoM = require('./../../routes/modules/cryptoM.js');
const moment = require("moment");
const BUCKET_NAME = "hong-s3-cloud";
const s3 = new AWS.S3();
......@@ -34,7 +35,7 @@ router.post('/', function(req, res, next) {
connection.query(sql, values, function(err) {
if (err) {
console.log("inserting user failed");
throw err;
res.status(400).send({ err: err });
} else {
let params = {
Bucket: BUCKET_NAME,
......@@ -45,6 +46,7 @@ router.post('/', function(req, res, next) {
s3.putObject(params, function(err, data) {
if (err) {
console.log('s3 error');
res.status(400).send({ err: err });
} else {
let params2 = {
Bucket: BUCKET_NAME,
......@@ -55,6 +57,7 @@ router.post('/', function(req, res, next) {
s3.putObject(params2, function(err, data) {
if (err) {
console.log('s3 error');
res.status(400).send({ err: err });
} else {
let params3 = {
Bucket: BUCKET_NAME,
......@@ -65,8 +68,27 @@ router.post('/', function(req, res, next) {
s3.putObject(params3, function(err, data) {
if (err) {
console.log('s3 error');
res.status(400).send({ err: err });
} else {
res.status(200).send('saved');
let date = moment().format();
let root = '/';
let sql = "INSERT INTO folders (folder_name,location,user_id,created) values (?,?,?,?);";
connection.query(sql, ['share', root, user_id, date], function(err, result, field) {
if (err) {
console.log('insert1 error');
res.status(400).send({ err: err });
} else {
let sql = "INSERT INTO folders (folder_name,location,user_id,created) values (?,?,?,?);";
connection.query(sql, ['trashcan', root, user_id, date], function(err, result, field) {
if (err) {
console.log('insert2 error');
res.status(400).send({ err: err });
} else {
res.status(200).send('saved');
}
});
}
});
}
});
}
......
......@@ -250,11 +250,14 @@ export default {
cur: this.$store.state.cur + move_folder_name + '/',
};
const response = await folder(curData);
const file_response = await file(curData);
console.log(response.data);
this.$store.commit('setFolder', response.data.folders);
this.$store.commit('setFile', file_response.data.files);
this.$store.commit('setCur', response.data.cur);
this.$store.commit('setParent', response.data.parentPath);
this.folders = this.$store.getters.folderL;
this.files = this.$store.getters.fileL;
} catch (error) {
console.log('에러');
console.log(error.response.data);
......@@ -267,11 +270,14 @@ export default {
cur: this.$store.state.parent,
};
const response = await folder(cData);
const file_response = await file(cData);
console.log(response.data);
this.$store.commit('setFolder', response.data.folders);
this.$store.commit('setFile', file_response.data.files);
this.$store.commit('setCur', response.data.cur);
this.$store.commit('setParent', response.data.parentPath);
this.folders = this.$store.getters.folderL;
this.files = this.$store.getters.fileL;
} catch (error) {
console.log('에러');
console.log(error.response.data);
......