Hong

백엔드폴더추가

......@@ -9,6 +9,7 @@ var indexRouter = require('./routes/index');
var userRouter = require('./routes/userlogin/user');
var loginRouter = require('./routes/userlogin/login');
var registerRouter = require('./routes/userlogin/register');
var folderRouter = require('./routes/folders');
var passport = require('passport');
......@@ -17,19 +18,19 @@ var config = require('./routes/modules/config');
//port
passport.serializeUser(function(user, done) {
console.log('serialized');
done(null, user);
console.log('serialized');
done(null, user);
});
passport.deserializeUser(function(user, done) {
console.log('deserialized');
done(null, user);
console.log('deserialized');
done(null, user);
});
var app = express();
// view engine setup
app.set('views', [path.join(__dirname, 'views'),path.join(__dirname ,'dist')]);
app.set('views', [path.join(__dirname, 'views'), path.join(__dirname, 'dist')]);
// app.set('view engine', 'ejs');
app.use(logger('dev'));
......@@ -39,9 +40,9 @@ app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use(session({
secret: 'mykey',
saveUninitialized: true,
resave: true
secret: 'mykey',
saveUninitialized: true,
resave: true
}));
app.use(express.static('public'));
......@@ -54,22 +55,23 @@ app.use('/api/', indexRouter);
app.use('/api/user', userRouter);
app.use('/api/login', loginRouter);
app.use('/api/RegistUser', registerRouter);
app.use('/api/folder', folderRouter);
//app.use('/users', usersRouter);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
next(createError(404));
next(createError(404));
});
// error handler
app.use(function(err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
// render the error page
res.status(err.status || 500);
res.render('error');
// render the error page
res.status(err.status || 500);
res.render('error');
});
module.exports = app;
module.exports = app;
\ No newline at end of file
......
This diff is collapsed. Click to expand it.
......@@ -6,6 +6,7 @@
"start": "node ./bin/www"
},
"dependencies": {
"aws-sdk": "^2.683.0",
"cookie-parser": "~1.4.4",
"crypto-js": "^4.0.0",
"debug": "~2.6.9",
......@@ -13,9 +14,11 @@
"express": "~4.16.1",
"express-session": "^1.17.1",
"http-errors": "~1.6.3",
"moment": "^2.26.0",
"morgan": "~1.9.1",
"mysql": "^2.18.1",
"passport": "^0.4.1",
"pug": "2.0.0-beta11"
"pug": "2.0.0-beta11",
"request": "^2.88.2"
}
}
......
const express = require('express');
const router = express.Router();
const AWS = require("aws-sdk");
const moment = require("moment");
const BUCKET_NAME = "hong-s3-cloud";
let curPath = "";
let user_id = "";
const s3 = new AWS.S3({
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
region: "ap-northeast-2"
});
router.get('/show', function(req, res, next) {
console.log(req.query);
user_id = req.query.id;
curPath = req.query.cur;
folders = {}
let checkfolder = 'SELECT * FROM folders WHERE location = ? AND user_id = ?;';
connection.query(checkfolder, [curPath, user_id], function(err, rows, fields) {
if (rows.length != 0) {
res.status(200).send({
folders: rows,
cur: curPath
})
} else {
res.send({ error: "Does not exist" });
}
});
});
router.post('/makefolder', function(req, res, next) {
user_id = req.body.user_id;
let cur = req.body.cur;
curPath = user_id + cur;
let folder_name = req.body.folder_name;
let date = moment().format();
let params = {
Bucket: BUCKET_NAME,
Key: curPath + folder_name + '/',
Body: "",
ACL: "public-read-write"
};
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 (rows.length == 0) {
s3.putObject(params, function(err, data) {
if (err) {
console.log('s3 error');
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) {
if (err) {
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) {
res.status(200).send({
folders: rows,
cur: curPath
})
} 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;
let folder_name = req.body.folder_name;
let params = {
Bucket: BUCKET_NAME + curPath,
Key: folder_name + '/'
};
let checksql = 'SELECT * FROM folders WHERE location = ? AND folder_name = ?;';
let values = [curPath, folder_name];
connection.query(checksql, values, function(err, rows, fields) {
if (rows.length != 0) {
s3.deleteObject(params, function(err, data) {
if (err) {
//throw err;
} else {
let sql = 'DELETE FROM folders WHERE location = ? AND folder_name = ?;';
connection.query(sql, values, function(err, result, field) {
if (err) {
//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) {
res.status(200).send({
folders: rows,
cur: curPath
})
} else {
res.send({ error: "Does not exist" });
}
});
}
});
}
});
} else {
res.send({ error: "Does not exist" });
}
});
});
router.post('/move', function(req, res, next) {
user_id = req.body.user_id;
curPath = user_id + req.body.cur;
let name = req.body.mfile;
let newPath = req.body.newPath;
let checkfolder = 'SELECT * FROM folders WHERE location = ? AND folder_name = ?;';
if (req.body.isfolder) {
connection.query(checkfolder, [curPath, name], function(err1, rows, fields) {
if (rows.length != 0) {
let copy_params = {
Bucket: BUCKET_NAME + curPath,
CopySource: BUCKET_NAME + curPath + file + '/',
Key: newPath + file + '/'
};
let del_params = {
Bucket: BUCKET_NAME + curPath,
Key: file + '/'
};
s3.copyObject(copy_params, function(err, data) {
console.log(err, data);
});
s3.deleteObject(del_params, function(err, data) {
console.log(err, data);
});
let values = [newPath, curPath, name];
let updatesql = 'UPDATE folders SET location = ? WHERE location = ? AND folder_name = ?;';
connection.query(updatesql, values, function(err3, result, field) {
if (err3) {
throw err;
} else {
folders = {}
connection.query(checkfolder, [cur, user_id], function(err, rows, fields) {
if (rows.length != 0) {
res.status(200).send({
folders: rows,
cur: curPath
})
} else {
res.send({ error: "Does not exist" });
}
});
}
});
} else {
res.send({ error: "Does not exist" });
}
});
} else {
let checkfile = 'SELECT * FROM files WHERE location = ? AND file_name = ?';
connection.query(checkfile, [curPath, name], function(err1, rows, fields) {
if (rows.length != 0) {
let copy_params = {
Bucket: BUCKET_NAME + curPath,
CopySource: BUCKET_NAME + curPath + file,
Key: newPath + file
};
let del_params = {
Bucket: BUCKET_NAME + curPath,
Key: file
};
s3.copyObject(copy_params, function(err, data) {
console.log(err, data);
});
s3.deleteObject(del_params, function(err, data) {
console.log(err, data);
});
let values = [newPath, curPath, name];
let updatesql = 'UPDATE files SET location = ? WHERE location = ? AND file_name = ?;';
connection.query(updatesql, values, function(err3, result, field) {
if (err3) {
throw err;
} else {
folders = {}
connection.query(checkfolder, [cur, user_id], function(err, rows, fields) {
if (rows.length != 0) {
res.status(200).send({
folders: rows,
cur: curPath
})
} else {
res.send({ error: "Does not exist" });
}
});
}
});
} else {
res.send({ error: "Does not exist" });
}
});
}
});
router.post('/search/:target', function(req, res, next) {
user_id = req.params.id;
let cur = req.params.cur;
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) {
res.status(200).send({
folders: folders
})
} else {
res.send({ error: "Does not exist" });
}
});
});
module.exports = router;
\ No newline at end of file
......@@ -5,17 +5,26 @@ const instance = axios.create({
});
function registerUser(userData) {
// const url = 'http://localhost:3000/api/signup'
// const url = 'http://localhost:3000/api/signup'
return axios.post('/api/RegistUser', userData);
}
function loginUser(userData) {
}
function loginUser(userData) {
// const url = 'http://localhost:3000/api/login'
return axios.post('/api/login', userData);
}
function dropbox(userData){
return axios.get('/api/dropbox', userData);
}
export { registerUser, loginUser, dropbox };
\ No newline at end of file
function folder(curData) {
return axios.get('/api/folder/show', {
params: {
id: curData.id,
cur: curData.cur
}
});
}
function makeFolder(folderData) {
return axios.post('/api/folder/makefolder', folderData);
}
export { registerUser, loginUser, folder, makeFolder };
\ No newline at end of file
......
......@@ -12,10 +12,8 @@
hide-details
></v-text-field>
</v-toolbar>
<v-list two-line subheader>
<v-subheader inset>Folders</v-subheader>
<v-list-item
v-for="item in this.$store.getters.folderL"
:key="item.title"
......@@ -24,35 +22,28 @@
<v-list-item-avatar>
<v-icon>mdi-folder</v-icon>
</v-list-item-avatar>
<v-list-item-content>
<v-list-item-title v-text="item"></v-list-item-title>
<v-list-item-title v-text="item.folder_name"></v-list-item-title>
</v-list-item-content>
<v-list-item-action>
<v-btn icon>
<v-icon color="grey lighten-1">mdi-information</v-icon>
</v-btn>
</v-list-item-action>
</v-list-item>
<v-divider inset></v-divider>
<v-subheader inset>Files</v-subheader>
<v-list-item
v-for="item in items2"
v-for="item in this.$store.getters.fileL"
:key="item.title"
@click=""
>
<v-list-item-avatar>
<v-icon> mdi-file</v-icon>
</v-list-item-avatar>
<v-list-item-content>
<v-list-item-title v-text="item"></v-list-item-title>
</v-list-item-content>
<v-list-item-action>
<v-btn icon>
<v-icon color="grey lighten-1">mdi-information</v-icon>
......@@ -81,7 +72,6 @@
>
{{ text }}
</v-chip>
<span
v-else-if="index === 2"
class="overline grey--text text--darken-3 mx-2"
......@@ -90,44 +80,98 @@
</span>
</template>
</v-file-input>
<v-btn
bottom
color="blue"
dark
fab
fixed
right
@click="dialog = !dialog"
>
<v-icon>mdi-plus</v-icon>
</v-btn>
<v-dialog
v-model="dialog"
width="800px"
>
<v-card>
<v-card-title class="grey darken-2">
Create Folder
</v-card-title>
<v-container>
<div>
<v-icon>mdi-folder</v-icon>
<v-text-field placeholder="name" id="foldername" type="text" v-model="foldername"></v-text-field>
</div>
</v-container>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn
text
color="primary"
@click="dialog = false"
>Cancel</v-btn>
<v-btn
text
@click="makeF"
>Create</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
</div>
</template>
<script>
import { dropbox } from '../api/index';
import { folder, makeFolder } from '../api/index';
export default {
data() {
return {
return {
foldername:'',
folders: [],
files: [],
search:'',
dialog:false
}
},
async created(){
try {
const userData = {
user_id: this.$store.getters.userId,
cur: '/',
};
const { data } = await dropbox(userData);
console.log(data);
this.$store.commit('setFolder', data.folders);
this.$store.commit('setFile', data.files);
const curData = {
id : this.$store.state.id,
cur: this.$store.state.cur
}
const response = await folder(curData);
console.log(response);
this.$store.commit('setFolder', response.data.folders);
} catch (error) {
console.log("에러");
console.log(error.response.data);
console.log(error.response.data);
}
}
// data: () => ({
// items: [
// { icon: 'folder', iconClass: 'mdi-folder', title: 'Photos', subtitle: 'Jan 9, 2014' },
// { icon: 'folder', iconClass: 'mdi-folder', title: 'Recipes', subtitle: 'Jan 17, 2014' },
// { icon: 'folder', iconClass: 'mdi-folder', title: 'Work', subtitle: 'Jan 28, 2014' },
// ],
// items2: [
// { icon: 'assignment', iconClass: 'mdi-file', title: 'Vacation itinerary', subtitle: 'Jan 20, 2014' },
// { icon: 'call_to_action', iconClass: 'mdi-PdfBox', title: 'Kitchen remodel', subtitle: 'Jan 10, 2014' },
// ],
// }),
},
methods: {
initFolderName(){
this.foldername = '';
},
async makeF(){
try {
const folderData = {
user_id : this.$store.state.id,
cur : this.$store.state.cur,
folder_name : this.foldername
};
const response = await makeFolder(folderData);
console.log(response.data)
console.log("폴더 생성 완료");
this.$store.commit('setFolder', response.data.folders);
} catch (error) {
console.log("에러");
console.log(error.response.data);
} finally{
this.initFolderName();
this.dialog = false;
}
}
}
}
</script>
......
......@@ -132,112 +132,6 @@
<router-view></router-view>
</v-container>
</v-content>
<template v-if="isUserLogin">
<v-btn
bottom
color="pink"
dark
fab
fixed
right
@click="dialog = !dialog"
>
<v-icon>mdi-plus</v-icon>
</v-btn>
</template>
<!-- <v-btn
bottom
color="pink"
dark
fab
fixed
right
@click="dialog = !dialog"
>
<v-icon>mdi-plus</v-icon>
</v-btn> -->
<v-dialog
v-model="dialog"
width="800px"
>
<v-card>
<v-card-title class="grey darken-2">
Create contact
</v-card-title>
<v-container>
<v-row class="mx-2">
<v-col
class="align-center justify-space-between"
cols="12"
>
<v-row
align="center"
class="mr-0"
>
<v-avatar
size="40px"
class="mx-3"
>
<img
src="//ssl.gstatic.com/s2/oz/images/sge/grey_silhouette.png"
alt=""
>
</v-avatar>
<v-text-field
placeholder="Name"
></v-text-field>
</v-row>
</v-col>
<v-col cols="6">
<v-text-field
prepend-icon="mdi-account-card-details-outline"
placeholder="Company"
></v-text-field>
</v-col>
<v-col cols="6">
<v-text-field
placeholder="Job title"
></v-text-field>
</v-col>
<v-col cols="12">
<v-text-field
prepend-icon="mdi-mail"
placeholder="Email"
></v-text-field>
</v-col>
<v-col cols="12">
<v-text-field
type="tel"
prepend-icon="mdi-phone"
placeholder="(000) 000 - 0000"
></v-text-field>
</v-col>
<v-col cols="12">
<v-text-field
prepend-icon="mdi-text"
placeholder="Notes"
></v-text-field>
</v-col>
</v-row>
</v-container>
<v-card-actions>
<v-btn
text
color="primary"
>More</v-btn>
<v-spacer></v-spacer>
<v-btn
text
color="primary"
@click="dialog = false"
>Cancel</v-btn>
<v-btn
text
@click="dialog = false"
>Save</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
</v-app>
</template>
......
......@@ -4,37 +4,44 @@ import Vuex from 'vuex'
Vue.use(Vuex)
export default new Vuex.Store({
state: {
id: '',
folders: [],
files: [],
},
mutations: {
setId(state, userid){
state.id = userid;
state: {
id: '',
folders: {},
files: {},
cur: '/',
},
clearid(state){
state.id= '';
mutations: {
setId(state, userid) {
state.id = userid;
},
clearid(state) {
state.id = '';
},
setFolder(state, folderlist) {
state.folders = folderlist;
},
setFile(state, filelist) {
state.files = filelist;
},
setCur(state, cur) {
state.cur = cur;
}
},
setFolder(state, folderlist){
state.folders = folderlist;
},
setFile(state, filelist){
state.files = fileList;
}
},
getters: {
isLogin(state){
return state.id !== '';
},
userID(state){
return state.id;
},
folderL(state){
return state.folders;
},
fileL(state){
return state.files;
getters: {
isLogin(state) {
return state.id !== '';
},
userID(state) {
return state.id;
},
folderL(state) {
return state.folders;
},
fileL(state) {
return state.files;
},
cur(state) {
return state.cur;
}
}
}
})
})
\ No newline at end of file
......