최동원

.

......@@ -116,3 +116,4 @@ dist
.pnp.*
backend/routes/modules/s3/download/*
backend/routes/modules/awsconfig.json
......
......@@ -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,13 +11,11 @@ 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: folder,
files: file
......
......@@ -2,49 +2,85 @@ 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";
const BUCKET_NAME = "hong-s3-cloud";
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);
// user_id = req.query.id;
// curPath = req.query.cur;
// if (curPath == '/') {
// parentPath = '/';
// } else {
// let pathSplit = curPath.split('/')
// console.log(pathSplit);
// parentPath = '/';
// for (let i = 1; i < pathSplit.length - 2; i++) {
// parentPath += pathSplit[i];
// parentPath += '/';
// }
// }
// 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(400).send({ err: err });
// } else {
// res.status(200).send({
// folders: rows,
// cur: curPath,
// parentPath: parentPath
// })
// }
// });
// });
router.get('/show', function(req, res, next) {
console.log(req.query);
user_id = req.query.id;
curPath = req.query.cur;
if (curPath == '/') {
parentPath = '/';
user_id = req.query.user_id;
folder_id = req.query.folder_id;
let checkfolder = 'SELECT * FROM folders WHERE folder_id = ? AND user_id = ?;';
connection.query(checkfolder, [curPath, user_id], function(err, rows) {
if (err) {
console.log('select1 error');
res.status(400).send({ err: err });
} else {
let pathSplit = curPath.split('/')
console.log(pathSplit);
parentPath = '/';
for (let i = 1; i < pathSplit.length - 2; i++) {
parentPath += pathSplit[i];
parentPath += '/';
}
}
let checkfolder = 'SELECT * FROM folders WHERE location = ? AND user_id = ?;';
connection.query(checkfolder, [curPath, user_id], function(err, rows, fields) {
let location = rows[0].location + rows[0].folder_name + '/';
if (rows.length == 0) {
console.log('does not exist');
res.status(400).send({ err: 'does not exist' });
} else {
let gerFolder = 'SELECT * FROM folders WHERE location = ? AND user_id = ?;';
connection.query(gerFolder, [location, user_id], function(err, folder) {
if (err) {
console.log('select2 error');
res.status(400).send({ err: err });
} else {
let gerFile = 'SELECT * FROM files WHERE location = ? AND user_id = ?;';
connection.query(gerFile, [location, user_id], function(err, folder) {
if (err) {
console.log('select error');
console.log('select3 error');
res.status(400).send({ err: err });
} else {
res.status(200).send({
folders: rows,
cur: curPath,
parentPath: parentPath
})
folders: folder,
files: file
});
}
});
}
});
}
}
});
});
router.post('/makefolder', function(req, res, next) {
user_id = req.body.user_id;
......@@ -107,6 +143,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 +190,9 @@ router.post('/delfolder', function(req, res, next) {
}
}
});
}
}
});
});
......@@ -155,6 +204,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 +263,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 +317,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);
......
{
"accessKeyId": "ASIAXZL2SWFEWQZ6ZNEU",
"secretAccessKey": "lqUJTmGVElVEJ6RIgacZd1n1ARvVSNrT3JisfpsO",
"sessionToken": "FwoGZXIvYXdzEJv//////////wEaDJAjP1JBdrIxgxqlTyLDAQCU1f4zp5nu4cNnp4U0pRa9ZGqjQKlxjsUWwH478XU6XUNJcN2NMmmZ0Cl8/kHz+GMvmgax7RxSpo0VsaReh/9+1SMcOB3Kcc+sqRivkCBAZAXfaKrdKhuR2WyCe+M+sZKXdqXNpzHPa/6tUVDBNIMC/aH1KMCwi6XChO3M4BBMZNeY73bu7dLcvPVfaBmRQpaTrqTRky7YiwcPHnnMabOLR6k8OX7Uq/gIYx4pWCJ7AGbVts/quDqoK4nWMs+9Ah6A1CjP4Pn2BTItGKcDLysH3w7vuuw+5dcrxRcFawD0sbOGkJ2YX7fvxHPf410Sm4Vyo2Jf94hM",
"region": "us-east-1"
"accessKeyId": "",
"secretAccessKey": "",
"sessionToken": "",
"region": "ap-northeast-2"
}
\ No newline at end of file
......
......@@ -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) {
......