Hong

.

......@@ -4,9 +4,6 @@ const router = express.Router();
router.get('/show', function(req, res, next) {
console.log(req.query);
user_id = req.query.id;
let folders = [];
let files = [];
let checkfolder = 'SELECT * FROM folders WHERE user_id = ? AND favorite = 1;';
let checkfiles = 'SELECT * FROM files WHERE user_id = ? AND favorite = 1;';
connection.query(checkfolder, [user_id], function(err, folder, fields) {
......@@ -14,16 +11,14 @@ router.get('/show', function(req, res, next) {
console.log('select error');
res.status(404).send();
} else {
folders.push(folder);
connection.query(checkfiles, [user_id], function(err, file, fields) {
if (err) {
console.log('select error');
res.status(404).send();
} else {
files.push(file);
res.status(200).send({
folders: folders,
files: files
folders: folder,
files: file
});
}
});
......
......@@ -2,17 +2,14 @@ const express = require('express');
const router = express.Router();
const AWS = require("aws-sdk");
const moment = require("moment");
AWS.config.loadFromPath(__dirname + "/../modules/awsconfig.json");
const BUCKET_NAME = "qkrrlqja-test";
let curPath = "";
let user_id = "";
let parentPath = "";
const s3 = new AWS.S3({
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
region: "ap-northeast-2"
});
const s3 = new AWS.S3();
router.get('/show', function(req, res, next) {
console.log(req.query);
......@@ -107,6 +104,16 @@ router.post('/delfolder', function(req, res, next) {
Bucket: BUCKET_NAME,
Key: 'drive/' + curPath + folder_name + '/'
};
let infolderpath = cur + name + '/';
let checkinfolder = 'SELECT location FROM folders WHERE location = ? AND user_id = ? UNION ALL SELECT location FROM files WHERE location = ? AND user_id = ?;';
connection.query(checkinfolder, [infolderpath, user_id, infolderpath, user_id], function(err, infolder) {
if (err) {
console.log("copy error");
res.status(304).send({ error: "checkinfolder error" });
} else {
if (infolder.length != 0) {
res.status(204).send({ error: "infolder exist!" })
} else {
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) {
......@@ -144,6 +151,9 @@ router.post('/delfolder', function(req, res, next) {
}
}
});
}
}
});
});
......@@ -155,6 +165,16 @@ router.post('/move', function(req, res, next) {
let name = req.body.name;
let newPath = user_id + req.body.newPath;
if (req.body.isfolder) {
let infolderpath = cur + name + '/';
let checkinfolder = 'SELECT location FROM folders WHERE location = ? AND user_id = ? UNION ALL SELECT location FROM files WHERE location = ? AND user_id = ?;';
connection.query(checkinfolder, [infolderpath, user_id, infolderpath, user_id], function(err, infolder) {
if (err) {
console.log("copy error");
res.status(304).send({ error: "checkinfolder error" });
} else {
if (infolder.length != 0) {
res.status(204).send({ error: "infolder exist!" })
} else {
let checkfolder = 'SELECT * FROM folders WHERE location = ? AND folder_name = ? AND user_id = ?;';
connection.query(checkfolder, [cur, name, user_id], function(err1, rows, fields) {
console.log(rows);
......@@ -204,6 +224,9 @@ router.post('/move', function(req, res, next) {
res.status(304).send({ error: "Does not exist" });
}
});
}
}
});
} else {
let checkfile = 'SELECT * FROM files WHERE location = ? AND file_name = ? AND user_id = ?;';
connection.query(checkfile, [cur, name, user_id], function(err1, rows, fields) {
......@@ -255,66 +278,66 @@ router.post('/move', function(req, res, next) {
});
router.post('/modify', function(req, res, next) {
console.log(req.body);
user_id = req.body.id;
let cur = req.body.cur;
curPath = user_id + cur;
let name = req.body.folder_name;
let newName = req.body.newName;
// router.post('/modify', function(req, res, next) {
// console.log(req.body);
// user_id = req.body.id;
// let cur = req.body.cur;
// curPath = user_id + cur;
// let name = req.body.folder_name;
// let newName = req.body.newName;
let checkfolder = 'SELECT * FROM folders WHERE location = ? AND folder_name = ? AND user_id = ?;';
connection.query(checkfolder, [cur, name, user_id], function(err1, rows, fields) {
console.log(rows);
if (rows.length != 0) {
let copy_params = {
Bucket: BUCKET_NAME,
CopySource: BUCKET_NAME + '/drive/' + curPath + name + '/',
Key: 'drive/' + curPath + newName + '/'
};
let del_params = {
Bucket: 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 date = moment().format();
let values = [newName, date, cur, name, user_id];
let updatesql = 'UPDATE folders SET folder_name = ? AND modify = ? 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, [cur, user_id], function(err, rows, fields) {
res.status(200).send({
folders: rows
});
});
}
});
}
});
}
});
} else {
console.log("Does not exist");
res.status(304).send({ error: "Does not exist" });
}
});
// let checkfolder = 'SELECT * FROM folders WHERE location = ? AND folder_name = ? AND user_id = ?;';
// connection.query(checkfolder, [cur, name, user_id], function(err1, rows, fields) {
// console.log(rows);
// if (rows.length != 0) {
// let copy_params = {
// Bucket: BUCKET_NAME,
// CopySource: BUCKET_NAME + '/drive/' + curPath + name + '/',
// Key: 'drive/' + curPath + newName + '/'
// };
// let del_params = {
// Bucket: 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 date = moment().format();
// let values = [newName, date, cur, name, user_id];
// let updatesql = 'UPDATE folders SET folder_name = ? AND modify = ? 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, [cur, user_id], function(err, rows, fields) {
// res.status(200).send({
// folders: rows
// });
// });
// }
// });
// }
// });
// }
// });
// } else {
// console.log("Does not exist");
// res.status(304).send({ error: "Does not exist" });
// }
// });
});
// });
router.get('/search', function(req, res, next) {
console.log(req.query);
......
......@@ -2,14 +2,11 @@ const express = require('express');
const router = express.Router();
const AWS = require("aws-sdk");
const moment = require("moment");
AWS.config.loadFromPath(__dirname + "/../modules/awsconfig.json");
const BUCKET_NAME = "hong-s3-cloud";
const s3 = new AWS.S3({
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
region: "ap-northeast-2"
});
const s3 = new AWS.S3();
router.post('/', function(req, res, next) {
......@@ -25,15 +22,15 @@ router.post('/', function(req, res, next) {
if (rows.length != 0) {
let copy_params = {
Bucket: BUCKET_NAME,
CopySource: BUCKET_NAME + '/' + curPath + name,
Key: target_id + '/share/' + name
CopySource: BUCKET_NAME + '/drive/' + curPath + name,
Key: 'drive/' + target_id + '/share/' + name
};
s3.copyObject(copy_params, function(err, data) {
if (err) {
console.log(err, data);
res.status(304).send({ error: "copy error" });
} else {
let values = [name, cur, target_id];
let values = [name, '/share/', target_id];
let sharesql = 'INSERT INTO files (file_name,location,user_id) values (?,?,?);';
connection.query(sharesql, values, function(err3, result, field) {
if (err3) {
......