최동원

Merge branch 'folder'

......@@ -29,26 +29,17 @@ router.get('/show', function(req, res, next) {
parentPath += '/';
}
}
folders = {}
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(404).send()
} else {
if (rows.length != 0) {
res.status(200).send({
folders: rows,
cur: curPath,
parentPath: parentPath
})
} else {
res.status(200).send({
folders: rows,
cur: curPath,
parentPath: parentPath
})
}
}
});
});
......@@ -70,6 +61,9 @@ router.post('/makefolder', function(req, res, next) {
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 (err) {
} else {
if (rows.length == 0) {
s3.putObject(params, function(err, data) {
if (err) {
......@@ -77,8 +71,6 @@ router.post('/makefolder', function(req, res, next) {
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) {
......@@ -86,172 +78,175 @@ router.post('/makefolder', function(req, res, next) {
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) {
console.log(rows);
res.status(200).send({
folders: rows
})
} 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;
user_id = req.body.id;
let cur = req.body.cur;
curPath = user_id + cur;
let folder_name = req.body.folder_name;
let params = {
Bucket: BUCKET_NAME + curPath,
Key: folder_name + '/'
Bucket: BUCKET_NAME,
Key: curPath + folder_name + '/'
};
let checksql = 'SELECT * FROM folders WHERE location = ? AND folder_name = ?;';
let values = [curPath, folder_name];
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) {
if (err) {
res.status(404).send({ error: "error" });
} else {
if (rows.length != 0) {
s3.deleteObject(params, function(err, data) {
if (err) {
console.log('s3 error');
//throw err;
} else {
let sql = 'DELETE FROM folders WHERE location = ? AND folder_name = ?;';
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;
} else {
folders = {}
console.log(cur);
console.log(user_id);
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
folders: rows
})
} else {
res.send({ error: "Does not exist" });
}
});
}
});
}
});
} else {
res.send({ error: "Does not exist" });
console.log(req.body);
res.status(304).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 = ?;';
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 newPath = user_id + req.body.newPath;
if (req.body.isfolder) {
connection.query(checkfolder, [curPath, name], function(err1, rows, fields) {
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 + curPath,
CopySource: BUCKET_NAME + curPath + file + '/',
Key: newPath + file + '/'
Bucket: BUCKET_NAME,
CopySource: BUCKET_NAME + '/' + curPath + name + '/',
Key: newPath + name + '/'
};
let del_params = {
Bucket: BUCKET_NAME + curPath,
Key: file + '/'
Bucket: BUCKET_NAME,
Key: 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);
});
let values = [newPath, curPath, name];
let updatesql = 'UPDATE folders SET location = ? WHERE location = ? AND folder_name = ?;';
console.log("delete error");
res.status(304).send({ error: "delete error" });
} else {
let values = [req.body.newPath, cur, 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) {
throw err;
console.log("updatesql error");
res.status(304).send({ error: "updatesql error" });
} else {
folders = {}
connection.query(checkfolder, [cur, user_id], function(err, rows, fields) {
if (rows.length != 0) {
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,
cur: curPath
})
} else {
res.send({ error: "Does not exist" });
folders: rows
});
});
}
});
}
});
}
});
} else {
res.send({ error: "Does not exist" });
console.log("Does not exist");
res.status(304).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) {
let checkfile = 'SELECT * FROM files WHERE location = ? AND file_name = ? AND user_id = ?';
connection.query(checkfile, [curPath, name, user_id], function(err1, rows, fields) {
if (rows.length != 0) {
let copy_params = {
Bucket: BUCKET_NAME + curPath,
CopySource: BUCKET_NAME + curPath + file,
Bucket: BUCKET_NAME,
CopySource: BUCKET_NAME + '/' + curPath + file,
Key: newPath + file
};
let del_params = {
Bucket: BUCKET_NAME + curPath,
Key: file
Bucket: BUCKET_NAME,
Key: curPath + file
};
s3.copyObject(copy_params, function(err, data) {
if (err) {
console.log(err, data);
});
res.status(304).send({ error: "copy error" });
} else {
s3.deleteObject(del_params, function(err, data) {
if (err) {
console.log(err, data);
});
let values = [newPath, curPath, name];
let updatesql = 'UPDATE files SET location = ? WHERE location = ? AND file_name = ?;';
res.status(304).send({ error: "delete error" });
} else {
let values = [newPath, cur, name, user_id];
let updatesql = 'UPDATE files SET location = ? WHERE location = ? AND file_name = ? AND user_id = ?;';
connection.query(updatesql, values, function(err3, result, field) {
if (err3) {
throw err;
res.status(304).send({ error: "updatesql error" });
} else {
folders = {}
connection.query(checkfolder, [cur, user_id], function(err, rows, fields) {
if (rows.length != 0) {
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,
cur: curPath
})
} else {
res.send({ error: "Does not exist" });
folders: rows
});
});
}
});
}
});
}
});
} else {
res.send({ error: "Does not exist" });
res.status(304).send({ error: "Does not exist" });
}
});
......
......@@ -27,20 +27,14 @@ function makeFolder(folderData) {
return axios.post('/api/folder/makefolder', folderData);
}
function file(userData){
return axios.get('/api/file', userData, {
params: {
user_id: userData.user_id
}
})
function deleteFolder(folderData) {
return axios.post('/api/folder/delfolder', folderData);
}
export { registerUser, loginUser, folder, makeFolder, file};
function moveFolder(folderData) {
return axios.post('/api/folder/move', folderData);
}
function dropbox(userData){
return axios.get(`/api/folder/show/${userData}`);
}
// export { registerUser, loginUser, dropbox, makeFolder };
export { registerUser, loginUser, folder, makeFolder, deleteFolder, moveFolder };
......
......@@ -14,26 +14,76 @@
</v-toolbar>
<v-list two-line subheader>
<v-subheader inset>Folders</v-subheader>
<v-btn @click="moveParent">...</v-btn>
<v-list-item
v-for="item in this.$store.getters.folderL"
:key="item.title"
@click="moveF(item.folder_name)"
:search="search"
@click.right="show(item.folder_name,$event)"
@click.left="moveF(item.folder_name)"
>
<v-list-item-avatar>
<v-list-item-avatar >
<v-icon>mdi-folder</v-icon>
</v-list-item-avatar>
<v-list-item-content>
<v-list-item-content >
<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-btn icon>
<v-icon color="grey lighten-1">mdi-delete</v-icon>
</v-btn>
</v-list-item-action>
<v-menu
v-model="showMenu"
:position-x="x"
:position-y="y"
absolute
offset-y
>
<v-list dense>
<v-list-item @click.prevent="dialog2 = !dialog2">
<v-list-item-title>이동</v-list-item-title>
</v-list-item>
<v-list-item @click.prevent="deleteF">
<v-list-item-title>삭제</v-list-item-title>
</v-list-item>
</v-list>
</v-menu>
</v-list-item>
<v-dialog
v-model="dialog2"
width="500px"
>
<v-card>
<v-card-title class="grey darken-2">
Move Folder
</v-card-title>
<v-container>
<v-list-item-group
v-for="item2 in folders"
:key="item2.folder_id"
>
<template v-if="!(item2.folder_name === curfName)">
<v-hover @click.left="transferF(item2.folder_name)">
<v-list-item-avatar>
<v-icon>mdi-folder</v-icon>
</v-list-item-avatar>
<v-list-item-content>
<v-list-item-title v-text="item2.folder_name"></v-list-item-title>
</v-list-item-content>
</v-hover>
</template>
<!-- <template v-else></template> -->
</v-list-item-group>
</v-container>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn
text
color="primary"
@click="cancelMove"
>Cancel</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
<v-divider inset></v-divider>
<v-subheader inset>Files</v-subheader>
<v-list-item
......@@ -98,7 +148,7 @@
</v-btn>
<v-dialog
v-model="dialog"
width="800px"
width="500px"
>
<v-card>
<v-card-title class="grey darken-2">
......@@ -127,16 +177,24 @@
</div>
</template>
<script>
import { folder, makeFolder } from '../api/index';
import { folder, makeFolder, deleteFolder, moveFolder } from '../api/index';
import Axios from 'axios';
export default {
data() {
return {
foldername:'',
curfName:'',
folders: [],
files: [],
search:'',
id: '',
dialog:false
dialog:false,
search: '',
howMenu: false,
showMenu: false,
x: 0,
y: 0,
dialog2:false
}
},
async created(){
......@@ -150,6 +208,7 @@ import { folder, makeFolder } from '../api/index';
this.$store.commit('setFolder', response.data.folders);
this.$store.commit('setCur', response.data.cur);
this.$store.commit('setParent', response.data.parentPath);
this.folders = this.$store.getters.folderL;
} catch (error) {
console.log("에러");
console.log(error.response.data);
......@@ -159,6 +218,10 @@ import { folder, makeFolder } from '../api/index';
initFolderName(){
this.foldername = '';
},
cancelMove(){
this.curfName = '';
this.dialog2 = false;
},
async makeF(){
try {
const folderData = {
......@@ -170,6 +233,7 @@ import { folder, makeFolder } from '../api/index';
console.log(response.data)
console.log("폴더 생성 완료");
this.$store.commit('setFolder', response.data.folders);
this.folders = respons.data.folders;
} catch (error) {
console.log("에러");
console.log(error.response.data);
......@@ -189,10 +253,78 @@ import { folder, makeFolder } from '../api/index';
this.$store.commit('setFolder', response.data.folders);
this.$store.commit('setCur', response.data.cur);
this.$store.commit('setParent', response.data.parentPath);
this.folders = this.$store.getters.folderL;
} catch (error) {
console.log("에러");
console.log(error.response.data);
}
},
async moveParent(){
try {
const cData = {
id : this.$store.state.id,
cur : this.$store.state.parent
};
const response= await folder(cData);
console.log(response.data);
this.$store.commit('setFolder', response.data.folders);
this.$store.commit('setCur', response.data.cur);
this.$store.commit('setParent', response.data.parentPath);
this.folders = this.$store.getters.folderL;
} catch (error) {
console.log("에러");
console.log(error.response.data);
}
},
async deleteF(){
try {
const cData = {
id: this.$store.state.id,
cur : this.$store.state.cur,
folder_name: this.curfName
}
const response = await deleteFolder(cData);
console.log(response);
this.$store.commit('setFolder', response.data.folders);
this.folders = this.$store.getters.folderL;
} catch (error) {
console.log("에러");
console.log(error.response.data);
} finally{
this.curfName = '';
}
},
async transferF(folderName){
try {
const cData = {
id: this.$store.state.id,
cur : this.$store.state.cur,
folder_name: this.curfName,
isfolder: true,
newPath: this.$store.state.cur + folderName + '/'
}
const response = await moveFolder(cData);
console.log(response);
this.$store.commit('setFolder', response.data.folders);
this.folders = this.$store.getters.folderL;
} catch (error) {
console.log("에러");
console.log(error.response.data);
} finally{
this.initFolderName();
this.curfName = '';
this.dialog2 = false;
}
},
show (folderN, e) {
e.preventDefault()
this.curfName = folderN;
this.showMenu = false
this.x = e.clientX
this.y = e.clientY
this.$nextTick(() => {
this.showMenu = true
})
}
}
}
......
......@@ -6,8 +6,8 @@ Vue.use(Vuex)
export default new Vuex.Store({
state: {
id: '',
folders: {},
files: {},
folders: [],
files: [],
cur: '/',
parent: '/'
},
......