leeseohyeon

file api 병합

......@@ -13,6 +13,8 @@ var fileRouter = require('./routes/file/router');
//var trashcanRouter = require('./routes/trashcan/router');
var folderRouter = require('./routes/folders');
var quickRouter = require('./routes/quick');
var favoritesRouter = require('./routes/favorites');
var shareRouter = require('./routes/share');
var passport = require('passport');
......@@ -60,6 +62,8 @@ app.use('/api/user', userRouter);
app.use('/api/login', loginRouter);
app.use('/api/RegistUser', registerRouter);
app.use('/api/folder', folderRouter);
app.use('/api/favorites', favoritesRouter);
app.use('/api/share', shareRouter);
//app.use('/users', usersRouter);
app.use('/api/file', fileRouter);
app.use('/api/quick', quickRouter);
......
const express = require('express');
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) {
if (err) {
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
});
}
});
}
});
});
router.post('/addfolder', function(req, res, next) {
let user_id = req.body.id;
let folder_name = req.body.name;
let cur = req.body.cur;
console.log(req.body);
let checkfolder = 'SELECT * FROM folders WHERE location = ? AND user_id = ? AND folder_name = ? AND favorite = 1;';
connection.query(checkfolder, [cur, user_id, folder_name], function(err, rows, fields) {
if (err) {
console.log('select error');
res.status(400).send({ error: err });
} else {
if (rows.length == 0) {
let sql = 'UPDATE folders SET favorite = 1 WHERE location = ? AND folder_name = ? AND user_id = ?;';
connection.query(sql, [cur, folder_name, user_id], function(err, result, fields) {
if (err) {
console.log('update error');
res.status(400).send({ error: err });
} else {
let getfolder = 'SELECT * FROM folders WHERE location = ? AND user_id = ?;';
connection.query(getfolder, [cur, user_id], function(err, folders, fields) {
res.status(200).send({
folders: folders
})
});
}
});
} else {
console.log('already exist error');
res.status(400).send({ error: err });
}
}
});
});
router.post('/addfile', function(req, res, next) {
let user_id = req.body.id;
let file_name = req.body.name;
let cur = req.body.cur;
console.log(req.body);
let checkfolder = 'SELECT * FROM files WHERE location = ? AND user_id = ? AND file_name = ? AND favorite = 1;';
connection.query(checkfolder, [cur, user_id, file_name], function(err, rows, fields) {
if (err) {
console.log('select error');
res.status(400).send({ error: err });
} else {
if (rows.length == 0) {
let sql = 'UPDATE files SET favorite = 1 WHERE location = ? AND file_name = ? AND user_id = ?;';
connection.query(sql, [cur, file_name, user_id], function(err, result, fields) {
if (err) {
console.log('update error');
res.status(400).send({ error: err });
} else {
let getfolder = 'SELECT * FROM files WHERE location = ? AND user_id = ?;';
connection.query(getfolder, [cur, user_id], function(err, files, fields) {
res.status(200).send({
files: files
})
});
}
});
} else {
console.log('already exist error');
res.status(400).send({ error: err });
}
}
});
});
router.post('/delfolder', function(req, res, next) {
let user_id = req.body.id;
let folder_name = req.body.name;
let cur = req.body.cur;
let checkfolder = 'SELECT * FROM folders WHERE location = ? AND user_id = ? AND folder_name = ? AND favorite = 1;';
connection.query(checkfolder, [cur, user_id, folder_name], function(err, rows, fields) {
if (err) {
console.log('select error');
res.status(400).send({ error: err });
} else {
if (rows.length != 0) {
let sql = 'UPDATE folders SET favorite = 0 WHERE location = ? AND folder_name = ? AND user_id = ?;';
connection.query(sql, [cur, folder_name, user_id], function(err, result, fields) {
if (err) {
console.log('update error');
res.status(400).send({ error: err });
} else {
let getfolder = 'SELECT * FROM folders WHERE location = ? AND user_id = ?;';
connection.query(getfolder, [cur, user_id], function(err, folders, fields) {
res.status(200).send({
folders: folders
})
});
}
});
} else {
console.log('dont exist error');
res.status(400).send({ error: err });
}
}
});
});
router.post('/delfile', function(req, res, next) {
let user_id = req.body.id;
let file_name = req.body.name;
let cur = req.body.cur;
let checkfile = 'SELECT * FROM files WHERE location = ? AND user_id = ? AND file_name = ? AND favorite = 1;';
connection.query(checkfile, [cur, user_id, file_name], function(err, rows, fields) {
if (err) {
console.log('select error');
res.status(400).send({ error: err });
} else {
if (rows.length != 0) {
let sql = 'UPDATE files SET favorite = 0 WHERE location = ? AND file_name = ? AND user_id = ?;';
connection.query(sql, [cur, file_name, user_id], function(err, result, fields) {
if (err) {
console.log('update error');
res.status(400).send({ error: err });
} else {
let getfile = 'SELECT * FROM files WHERE location = ? AND user_id = ?;';
connection.query(getfile, [cur, user_id], function(err, files, fields) {
res.status(200).send({
files: files
})
});
}
});
} else {
console.log('dont exist error');
res.status(400).send({ error: err });
}
}
});
});
module.exports = router;
\ No newline at end of file
......@@ -3,7 +3,7 @@ const router = express.Router();
const AWS = require("aws-sdk");
const moment = require("moment");
const BUCKET_NAME = "hong-s3-cloud";
const BUCKET_NAME = "qkrrlqja-test";
let curPath = "";
let user_id = "";
let parentPath = "";
......@@ -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,
......@@ -54,7 +54,7 @@ router.post('/makefolder', function(req, res, next) {
let date = moment().format();
let params = {
Bucket: BUCKET_NAME,
Key: curPath + folder_name + '/',
Key: 'drive/' + curPath + folder_name + '/',
Body: "",
ACL: "public-read-write"
};
......@@ -62,13 +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');
throw err;
res.status(400).send({ err: err });
} else {
console.log(data);
let sql = 'INSERT INTO folders (folder_name,location,user_id,created) values (?,?,?,?);';
......@@ -76,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) {
......@@ -105,7 +105,7 @@ router.post('/delfolder', function(req, res, next) {
let folder_name = req.body.folder_name;
let params = {
Bucket: BUCKET_NAME,
Key: curPath + folder_name + '/'
Key: 'drive/' + curPath + folder_name + '/'
};
let checksql = 'SELECT * FROM folders WHERE location = ? AND folder_name = ? AND user_id = ?;';
let values = [cur, folder_name, user_id];
......@@ -117,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);
......@@ -152,7 +152,7 @@ router.post('/move', function(req, res, next) {
user_id = req.body.id;
let cur = req.body.cur;
curPath = user_id + cur;
let name = req.body.folder_name;
let name = req.body.name;
let newPath = user_id + req.body.newPath;
if (req.body.isfolder) {
let checkfolder = 'SELECT * FROM folders WHERE location = ? AND folder_name = ? AND user_id = ?;';
......@@ -161,12 +161,12 @@ router.post('/move', function(req, res, next) {
if (rows.length != 0) {
let copy_params = {
Bucket: BUCKET_NAME,
CopySource: BUCKET_NAME + '/' + curPath + name + '/',
Key: newPath + name + '/'
CopySource: BUCKET_NAME + '/drive/' + curPath + name + '/',
Key: 'drive/' + newPath + name + '/'
};
let del_params = {
Bucket: BUCKET_NAME,
Key: curPath + name + '/'
Key: 'drive/' + curPath + name + '/'
};
s3.copyObject(copy_params, function(err, data) {
if (err) {
......@@ -200,22 +200,22 @@ router.post('/move', function(req, res, next) {
}
});
} else {
console.log("Does not exist");
console.log("Does not exist folder");
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, [curPath, name, user_id], function(err1, rows, fields) {
let checkfile = 'SELECT * FROM files WHERE location = ? AND file_name = ? AND user_id = ?;';
connection.query(checkfile, [cur, name, user_id], function(err1, rows, fields) {
if (rows.length != 0) {
let copy_params = {
Bucket: BUCKET_NAME,
CopySource: BUCKET_NAME + '/' + curPath + file,
Key: newPath + file
CopySource: BUCKET_NAME + '/drive/' + curPath + name,
Key: 'drive/' + newPath + name
};
let del_params = {
Bucket: BUCKET_NAME,
Key: curPath + file
Key: 'drive/' + curPath + name
};
s3.copyObject(copy_params, function(err, data) {
if (err) {
......@@ -227,7 +227,7 @@ router.post('/move', function(req, res, next) {
console.log(err, data);
res.status(304).send({ error: "delete error" });
} else {
let values = [newPath, cur, name, user_id];
let values = [req.body.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) {
......@@ -246,6 +246,7 @@ router.post('/move', function(req, res, next) {
}
});
} else {
console.log("Does not exist file");
res.status(304).send({ error: "Does not exist" });
}
});
......@@ -254,20 +255,89 @@ router.post('/move', function(req, res, next) {
});
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) {
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) {
res.status(200).send({
folders: folders
})
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 {
res.send({ error: "Does not exist" });
console.log("Does not exist");
res.status(304).send({ error: "Does not exist" });
}
});
});
router.get('/search', function(req, res, next) {
console.log(req.query);
user_id = req.query.id;
let target = connection.escape('%' + req.query.target + '%');
console.log(target);
let folders = []
let files = []
let checkfolder = 'SELECT * FROM folders WHERE folder_name LIKE ' + target + ' AND user_id = ?;';
connection.query(checkfolder, [user_id], function(err, folder, fields) {
console.log(folder);
folders.push(folder)
let checkfile = 'SELECT * FROM files WHERE file_name LIKE ' + target + ' AND user_id = ?;';
connection.query(checkfile, [user_id], function(err, file, fields) {
console.log(file);
files.push(file)
res.status(200).send({
folders: folders,
files: files
})
});
});
});
module.exports = router;
\ No newline at end of file
module.exports = router;
......
{
"accessKeyId": "ASIAXZL2SWFE2KIQ3YTL",
"secretAccessKey": "BqniXH7AqxjndKHjxBWKjRkBOgRmSN8J6mgldm7C",
"sessionToken": "FwoGZXIvYXdzEIL//////////wEaDC6uNIWZKpDL9FekbiLDAb7ckeHQwp1tV2wu236TIia7VBtYMFQrLzkEm6sU7GiamzWfzrTCsQOOJXYMKzElNXD7dRckn30aVaw8xfNDgimqWdtk9O3x8jgCOp4gXk4KIUgtIFpN46qdGNxy28gL43voIf4O6n3boJaUum9bmejzmNlR8U4d6NfqMzrtJENs47Nl4fAiK8bIGlsznhr7MC5AUeZbV0d9uK7bkx1rn5zRRpR9WbbwofVIlK+YSEEHfQIJyLeJKDlprBXfqSTynCqkAyj8ovT2BTItQ8+cOmQXWuzPMA/Rbru2naLM3Hd2H8jEW6CMfPXvNAS+leVNDXuCY5r5Ebo9",
"accessKeyId": "ASIAXZL2SWFEZSIHHRDT",
"secretAccessKey": "cdcXCezNz9OhFowZxE2KSftDmT3xSYAtiLJl1dFk",
"sessionToken": "FwoGZXIvYXdzEJf//////////wEaDG1NOyJj0/Xdzqu+uyLDAa8vgymCVldXPpET+AOsq5CXhMzhMEDmWogIaq6lWJVy8sdnK9tOXY/u9vz8p6cTm7xWb0YiX6TKDhlfFZX6ynv0Xw/p/qvbn4lPsoT8K9PpdDOWJUMA8qX/5RrKNO4OAolUkw+EMjQbK38u+g3HEVP8mo+DiGLrBGj+0Ar0xhGiU/Lg5qKRdp+tEYIn0ypDNu/2q13apRiMH7n+OVFzilil10g1qq8NLaW98QvVC4xRIgkjAMcRqA9yPdVrhc9yFyqjrCjA+vj2BTIt8CDkFsEAFqJR3W0YPDbsu2YdTq3SKgpOsxNXGsEFMaEhFxodp5/Qsk7tfMsO",
"region": "us-east-1"
}
......
const express = require('express');
const router = express.Router();
const AWS = require("aws-sdk");
const moment = require("moment");
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"
});
router.post('/', function(req, res, next) {
console.log(req.body);
let user_id = req.body.id;
let cur = req.body.cur;
let curPath = user_id + cur;
let name = req.body.file_name;
let target_id = req.body.target_id;
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,
CopySource: BUCKET_NAME + '/' + curPath + name,
Key: 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 sharesql = 'INSERT INTO files (file_name,location,user_id) values (?,?,?);';
connection.query(sharesql, values, function(err3, result, field) {
if (err3) {
console.log("sharesql error");
res.status(304).send({ error: "sharesql error" });
} else {
res.status(200).send({});
}
});
}
});
} else {
res.status(304).send({ error: "Does not exist" });
}
});
});
module.exports = router;
\ No newline at end of file
var express = require('express');
var request = require('request');
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();
var router = express.Router();
......@@ -14,32 +19,90 @@ router.get('/', function(req, res, next) {
router.post('/', function(req, res, next) {
console.log(req.body);
var user_id=req.body.user_id;
var user_pw=req.body.user_pw;
var user_email=req.body.user_email;
var user_name=req.body.user_name;
var user_phone=req.body.user_phone;
var user_id = req.body.user_id;
var user_pw = req.body.user_pw;
var user_email = req.body.user_email;
var user_name = req.body.user_name;
var user_phone = req.body.user_phone;
var sqlquery = "SELECT * FROM users WHERE user_id = ?";
connection.query(sqlquery, [user_id], function (err, rows) {
if (rows.length == 0) {
user_pw=cryptoM.encrypt(user_pw);
console.log(user_pw);
var sql = 'INSERT INTO users(user_id,user_pw, user_email, user_phone, user_name) values (?,?,?,?,?)';
var values = [user_id, user_pw, user_email, user_phone,user_name];
connection.query(sql, values, function (err) {
if (err) {
console.log("inserting user failed");
throw err;
} else {
res.status(200).send('saved');
}
});
} else {
res.status(404).send(err);
}
});
connection.query(sqlquery, [user_id], function(err, rows) {
if (rows.length == 0) {
user_pw = cryptoM.encrypt(user_pw);
console.log(user_pw);
var sql = 'INSERT INTO users(user_id,user_pw, user_email, user_phone, user_name) values (?,?,?,?,?)';
var values = [user_id, user_pw, user_email, user_phone, user_name];
connection.query(sql, values, function(err) {
if (err) {
console.log("inserting user failed");
res.status(400).send({ err: err });
} else {
let params = {
Bucket: BUCKET_NAME,
Key: 'drive/' + user_id + '/',
Body: "",
ACL: "public-read-write"
};
s3.putObject(params, function(err, data) {
if (err) {
console.log('s3 error');
res.status(400).send({ err: err });
} else {
let params2 = {
Bucket: BUCKET_NAME,
Key: 'drive/' + user_id + '/share/',
Body: "",
ACL: "public-read-write"
};
s3.putObject(params2, function(err, data) {
if (err) {
console.log('s3 error');
res.status(400).send({ err: err });
} else {
let params3 = {
Bucket: BUCKET_NAME,
Key: 'drive/' + user_id + '/trashcan/',
Body: "",
ACL: "public-read-write"
};
s3.putObject(params3, function(err, data) {
if (err) {
console.log('s3 error');
res.status(400).send({ err: err });
} else {
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');
}
});
}
});
}
});
}
});
}
});
}
});
} else {
res.status(404).send(err);
}
});
});
module.exports = router;
module.exports = router;
\ No newline at end of file
......
......@@ -79,25 +79,35 @@ function downloadFile(fileData) {
},
});
}
function accessedList(curData) {
return axios.get(`api/quick`, {
params: {
//현재 접속한 사람의 id와 다운로드를 위해 선택한 파일의 이름을 파라미터로 넘긴다.
function accessedList(curData){
return axios.get('api/quick', {
params:{
id: curData.id
},
});
}
function modifyFile(fileData){
return axios.post(`/api/file/modify/${fileName}`, {
params: {
user_id: fileData.id,
cur: fileData.cur,
name: fileData.rename,
content: fileData.content
},
});
return axios.post(`/api/file/modify/${fileData.name}`, fileData)
}
function delFavorite(folderData) {
return axios.post('api/favorites/delfolder', folderData);
}
function addFavorite(folderData) {
return axios.post('api/favorites/addfolder', folderData);
}
function moveFile(fileData) {
return axios.post('/api/folder/move', fileData);
}
function delFavoriteFile(fileData) {
return axios.post('api/favorites/delfile', fileData);
}
function addFavoriteFile(fileData) {
return axios.post('api/favorites/addfile', fileData);
}
export {
registerUser,
......@@ -110,6 +120,11 @@ export {
uploadFile,
deleteFile,
downloadFile,
delFavorite,
addFavorite,
moveFile,
delFavoriteFile,
addFavoriteFile,
accessedList,
detailFile,
modifyFile
......
<template>
<div>
<v-toolbar flat>
<v-toolbar-title>파일 </v-toolbar-title>
<v-toolbar-title>내 드라이브</v-toolbar-title>
<v-spacer></v-spacer>
<v-text-field
v-model="search"
append-icon="mdi-magnify"
label="파일 검색"
label="검색"
single-line
hide-details
></v-text-field>
</v-toolbar>
<v-list two-line subheader>
<v-subheader inset>Folders</v-subheader>
<v-btn @click="moveParent">...</v-btn>
<!-- <v-subheader inset>Folders</v-subheader> -->
<!-- Folder view -->
<v-list-item v-if="this.$store.state.cur !== '/'" @click="moveParent"
>...</v-list-item
>
<v-list-item
v-for="item in this.$store.getters.folderL"
:key="item.title"
:search="search"
@click.right="show(item.folder_name, $event)"
@click.left="moveF(item.folder_name)"
@click.right="show(item, $event)"
@click=""
@dblclick="moveF(item.folder_name)"
>
<v-list-item-avatar>
<v-icon>mdi-folder</v-icon>
......@@ -27,55 +31,23 @@
<v-list-item-content>
<v-list-item-title v-text="item.folder_name"></v-list-item-title>
</v-list-item-content>
<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-action>
<v-icon v-if="item.favorite === 0">
mdi-star-outline
</v-icon>
<v-icon v-else>
mdi-star
</v-icon>
</v-list-item-action>
</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 v-for="item in this.$store.getters.fileL" :key="item.title" @click.stop="dialog_file = true; file_detail(item)">
<!-- File view -->
<v-list-item
v-for="item in this.$store.getters.fileL"
:key="item.title"
@click.right="showF(item, $event)"
@dblclick="detailF(item, $event); file_detail(item);"
@click=""
>
<v-list-item-avatar>
<v-icon> mdi-file</v-icon>
</v-list-item-avatar>
......@@ -83,36 +55,198 @@
<v-list-item-title v-text="item.file_name"></v-list-item-title>
</v-list-item-content>
<v-list-item-action>
</v-list-item-action>
<v-dialog
v-model="dialog_file"
max-width="290"
>
<v-card>
<v-card-title class="headline">
<v-text-field v-model="current_filename" v-text="current_filename"></v-text-field>
</v-card-title>
<v-card-text v-model="current_filedata" v-text="current_filedata"></v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn
color="green darken-1"
text
@click="dialog_file = false; modify_file(item);"
>
save
</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
<v-btn icon @click="download_file(item.file_name)">
<v-icon color="grey lighten-1">mdi-download</v-icon>
</v-btn>
<v-btn icon @click="delete_file(item.file_name)">
<v-icon color="grey lighten-1">mdi-delete</v-icon>
</v-btn>
</v-list-item>
<v-icon v-if="item.favorite === 0">
mdi-star-outline
</v-icon>
<v-icon v-else>
mdi-star
</v-icon>
</v-list-item-action>
</v-list-item>
</v-list>
<!--file detial -->
<v-dialog
v-model="showdetailF"
max-width="290"
>
<v-card>
<v-card-title class="headline">
<v-text-field v-model="current_filename" ></v-text-field>
</v-card-title>
<v-card-text>
<v-text-field v-model="current_filedata" ></v-text-field>
</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn
color="green darken-1"
text
@click="showdetailF = false; modify_file();"
>
save
</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
<!-- Move Folder -->
<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>
<v-list-item
v-for="item2 in folders"
:key="item2.folder_id"
@click.left="transferF(item2.folder_name)"
v-if="item2.folder_name !== curfName.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-list-item>
</v-list>
</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>
<!-- sub menu for folder -->
<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-icon>
<v-icon>mdi-send</v-icon>
</v-list-item-icon>
<v-list-item-content>
<v-list-item-title>이동</v-list-item-title>
</v-list-item-content>
</v-list-item>
<v-list-item @click.prevent="deleteF">
<v-list-item-icon>
<v-icon>mdi-delete</v-icon>
</v-list-item-icon>
<v-list-item-content>
<v-list-item-title>삭제</v-list-item-title>
</v-list-item-content>
</v-list-item>
<v-list-item v-if="curfName.favorite === 1" @click="delete_favorite">
<v-list-item-icon>
<v-icon>mdi-star-outline</v-icon>
</v-list-item-icon>
<v-list-item-content>
<v-list-item-title>즐겨 찾기 삭제</v-list-item-title>
</v-list-item-content>
</v-list-item>
<v-list-item v-if="curfName.favorite === 0" @click="add_favorite">
<v-list-item-icon>
<v-icon>mdi-star</v-icon>
</v-list-item-icon>
<v-list-item-content>
<v-list-item-title>즐겨 찾기 추가</v-list-item-title>
</v-list-item-content>
</v-list-item>
</v-list>
</v-menu>
<!-- -->
<!-- Move File -->
<v-dialog v-model="dialog3" width="500px">
<v-card>
<v-card-title class="grey darken-2">
Move File
</v-card-title>
<v-container>
<v-list>
<v-list-item
v-for="item2 in folders"
:key="item2.folder_id"
@click.left="transferFile(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-list-item>
</v-list>
</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>
<!-- sub menu for file -->
<v-menu
v-model="showMenuF"
:position-x="x"
:position-y="y"
absolute
offset-y
>
<v-list dense>
<v-list-item @click.prevent="dialog3 = !dialog3">
<v-list-item-icon>
<v-icon>mdi-send</v-icon>
</v-list-item-icon>
<v-list-item-content>
<v-list-item-title>이동</v-list-item-title>
</v-list-item-content>
</v-list-item>
<v-list-item @click.prevent="delete_file">
<v-list-item-icon>
<v-icon>mdi-delete</v-icon>
</v-list-item-icon>
<v-list-item-content>
<v-list-item-title>삭제</v-list-item-title>
</v-list-item-content>
</v-list-item>
<v-list-item @click.prevent="download_file">
<v-list-item-icon>
<v-icon>mdi-download</v-icon>
</v-list-item-icon>
<v-list-item-content>
<v-list-item-title>다운로드</v-list-item-title>
</v-list-item-content>
</v-list-item>
<v-list-item
v-if="cfilename.favorite === 1"
@click="delete_favorite_file"
>
<v-list-item-icon>
<v-icon>mdi-star-outline</v-icon>
</v-list-item-icon>
<v-list-item-content>
<v-list-item-title>즐겨 찾기 삭제</v-list-item-title>
</v-list-item-content>
</v-list-item>
<v-list-item v-if="cfilename.favorite === 0" @click="add_favorite_file">
<v-list-item-icon>
<v-icon>mdi-star</v-icon>
</v-list-item-icon>
<v-list-item-content>
<v-list-item-title>즐겨 찾기 추가</v-list-item-title>
</v-list-item-content>
</v-list-item>
</v-list>
</v-menu>
<input
id="file-selector"
ref="uploadedfile"
......@@ -120,42 +254,11 @@
v-on:change="handleFileUpload()"
/>
<br />
<!--
<v-file-input
v-model="files"
color="deep-purple accent-4"
counter
label="업로드"
multiple
placeholder="파일을 화면으로 드래그앤 드롭 하거나, 이곳을 클릭하세요."
prepend-icon="mdi-paperclip"
outlined
:show-size="1000"
>
<template v-slot:selection="{ index, text }">
<v-chip
v-if="index < 2"
color="deep-purple accent-4"
dark
label
small
>
{{ text }}
</v-chip>
<span
v-else-if="index === 2"
class="overline grey--text text--darken-3 mx-2"
>
+{{ files.length - 2 }} File(s)
</span>
</template>
</v-file-input>
-->
<v-btn color="blue" @click="upload_file">upload</v-btn>
<v-btn bottom color="blue" dark fab fixed right @click="dialog = !dialog">
<v-icon>mdi-plus</v-icon>
</v-btn>
<!-- Create Folder -->
<v-dialog v-model="dialog" width="500px">
<v-card>
<v-card-title class="grey darken-2">
......@@ -191,31 +294,37 @@ import {
uploadFile,
deleteFile,
downloadFile,
delFavorite,
addFavorite,
moveFile,
delFavoriteFile,
addFavoriteFile,
detailFile,
modifyFile
} from '../api/index';
import Axios from 'axios';
export default {
data() {
return {
uploadedfile: null,
foldername: '',
curfName: '',
curfName: {},
cfilename: {},
folders: [],
files: [],
search: '',
id: '',
current_filename: null, //파일 상세정보 (이름)
current_filedata: null, //파일 상세정보 (내용)
dialog: false,
howMenu: false,
showMenu: false,
showMenuF: false, //파일 관련 메뉴
showdetailF:false, //txt 파일 상세정보 및 수정
x: 0,
y: 0,
dialog2: false,
dialog_file: false,
current_filename: null,
current_filedata: null,
dialog3: false, //파일 관련 메뉴
detail: {
dataname: null,
date: null,
......@@ -237,7 +346,6 @@ export default {
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;
this.$store.commit('setFile', file_response.data.files);
this.folders = this.$store.getters.folderL;
console.log(this.$store.getters.fileL);
......@@ -256,8 +364,10 @@ export default {
this.foldername = '';
},
cancelMove() {
this.curfName = '';
this.curfName = {};
this.cfilename = {};
this.dialog2 = false;
this.dialog3 = false;
},
async makeF() {
try {
......@@ -286,11 +396,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);
......@@ -303,11 +416,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);
......@@ -318,7 +434,7 @@ export default {
const cData = {
id: this.$store.state.id,
cur: this.$store.state.cur,
folder_name: this.curfName,
folder_name: this.curfName.folder_name,
};
const response = await deleteFolder(cData);
console.log(response);
......@@ -336,7 +452,7 @@ export default {
const cData = {
id: this.$store.state.id,
cur: this.$store.state.cur,
folder_name: this.curfName,
name: this.curfName.folder_name,
isfolder: true,
newPath: this.$store.state.cur + folderName + '/',
};
......@@ -348,8 +464,7 @@ export default {
console.log('에러');
console.log(error.response.data);
} finally {
this.initFolderName();
this.curfName = '';
this.curfName = {};
this.dialog2 = false;
}
},
......@@ -375,20 +490,16 @@ export default {
console.log(error);
}
},
async delete_file(itemName) {
async delete_file() {
try {
var itemlist = this.$store.getters.fileL;
console.log(itemlist);
console.log(itemName);
const currentData = {
fileName: null,
user_id: null,
cur: this.$store.state.cur,
};
for (var i = 0; i < itemlist.length; i++) {
console.log(itemlist[i].file_name);
if (itemlist[i].file_name == itemName) {
if (itemlist[i].file_name == this.cfilename.file_name) {
currentData.fileName = itemlist[i].file_name;
currentData.user_id = itemlist[i].user_id;
}
......@@ -397,23 +508,20 @@ export default {
id: currentData.user_id,
cur: currentData.cur,
};
console.log(currentData);
const response = await deleteFile(currentData);
setTimeout(function() {}, 500);
const filelist = await file(filelistData);
console.log(filelist.data.files);
this.$store.commit('setFile', filelist.data.files);
console.log(this.$store.getters.fileL);
this.files = this.$store.getters.fileL;
} catch (error) {
console.log('에러');
console.log(error);
}
},
async download_file(namedata) {
async download_file() {
try {
const currentData = {
fileName: namedata,
fileName: this.cfilename.file_name,
id: this.$store.state.id,
cur: this.$store.state.cur,
};
......@@ -424,55 +532,150 @@ export default {
console.log(error);
}
},
async file_detail(fileData){
async delete_favorite() {
try {
const cData = {
id: this.$store.state.id,
cur: this.$store.state.cur,
name: this.curfName.folder_name,
};
console.log(cData);
const response = await delFavorite(cData);
this.$store.commit('setFolder', response.data.folders);
} catch (error) {
console.log('에러');
}
},
async add_favorite() {
try {
const cData = {
id: this.$store.state.id,
cur: this.$store.state.cur,
name: this.curfName.folder_name,
};
console.log(cData);
const response = await addFavorite(cData);
this.$store.commit('setFolder', response.data.folders);
} catch (error) {
console.log('에러');
}
},
async delete_favorite_file() {
try {
const fData = {
id: this.$store.state.id,
cur: this.$store.state.cur,
name: this.cfilename.file_name,
};
console.log(fData);
const response = await delFavoriteFile(fData);
this.$store.commit('setFile', response.data.files);
} catch (error) {
console.log('에러');
}
},
async add_favorite_file() {
try {
const fData = {
id: this.$store.state.id,
cur: this.$store.state.cur,
name: this.cfilename.file_name,
};
console.log(fData);
const response = await addFavoriteFile(fData);
this.$store.commit('setFile', response.data.files);
} catch (error) {
console.log('에러');
}
},
async transferFile(folderName) {
try {
const fData = {
id: this.$store.state.id,
cur: this.$store.state.cur,
name: this.cfilename.file_name,
isfolder: false,
newPath: this.$store.state.cur + folderName + '/',
};
const response = await moveFile(fData);
console.log(response);
this.$store.commit('setFile', response.data.files);
this.files = this.$store.getters.fileL;
} catch (error) {
console.log('에러');
console.log(error.response.data);
} finally {
this.cfilename = {};
this.dialog3 = false;
}
},
async file_detail(){
try{
const currentData = {
id: fileData.user_id,
cur: fileData.location,
fileName: fileData.file_name
id: this.cfilename.user_id,
cur: this.cfilename.location,
fileName: this.cfilename.file_name
}
const detailData = await detailFile(currentData)
console.log(detailData)
this.current_filename = detailData.file_name;
this.current_filedata = detailFile.content;
this.current_filename = detailData.data.file_name;
this.current_filedata = detailData.data.content;
console.log(this.current_filename);
console.log(this.current_filedata);
}catch(error){
console.log('에러');
console.log(error);
}
},
async modify_file(fileData){
try{
const modifyData = {
user_id: fileData.user_id,
cur: fileData.location,
name: this.current_filename,
content: this.current_filedata
}
const result = await modifyFile(modifyData);
const after_data={
id: fileData.user_id,
cur: fileData.location,
fileName: this.current_filename
}
const detailData = await detailFile(after_data)
this.current_filename = detailData.file_name;
this.current_filedata = detailData.content;
}catch(error){
console.log('에러');
console.log(error);
}
}
},
show(folderN, e) {
e.preventDefault();
this.curfName = folderN;
this.showMenu = false;
this.x = e.clientX;
this.y = e.clientY;
this.$nextTick(() => {
this.showMenu = true;
});
async modify_file(){
try{
const modifyData = {
user_id: cfilename.user_id,
cur: cfilename.location,
name: this.current_filename,
content: this.current_filedata
}
const result = await modifyFile(modifyData);
const after_data={
id: cfilename.user_id,
cur: cfilename.location,
fileName: this.current_filename
}
const detailData = await detailFile()
}catch(error){
console.log('에러');
console.log(error);
}
},
show(folderObj, e) {
e.preventDefault();
this.curfName = folderObj;
this.showMenu = false;
this.x = e.clientX;
this.y = e.clientY;
this.$nextTick(() => {
this.showMenu = true;
});
},
showF(fileObj, e) {
e.preventDefault();
this.cfilename = fileObj;
this.showMenuF = false;
this.x = e.clientX;
this.y = e.clientY;
this.$nextTick(() => {
this.showMenuF = true;
});
},
detailF(fileObj, e) {
e.preventDefault();
this.cfilename = fileObj;
this.showdetailF = false;
this.x = e.clientX;
this.y = e.clientY;
this.$nextTick(() => {
this.showdetailF = true;
});
},
},
};
</script>
</script>
\ No newline at end of file
......
......@@ -5,7 +5,9 @@
<template v-slot:default>
<thead>
<tr>
<th class="text-left">File ID</th>
<th class="text-left">Name</th>
<th class="text-left">Dir</th>
<th class="text-left">Date</th>
</tr>
</thead>
......
import Vue from 'vue'
import Vuex from 'vuex'
import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex)
Vue.use(Vuex);
export default new Vuex.Store({
state: {
id: '',
folders: [],
files: [],
cur: '/',
parent: '/',
recentList:[]
},
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;
},
setParent(state, parent) {
state.parent = parent;
},
setRecentList(state, list){
state.recentList = list;
}
},
getters: {
isLogin(state) {
return state.id !== '';
},
userID(state) {
return state.id;
},
folderL(state) {
return state.folders;
},
fileL(state) {
return state.files;
},
recentL(state){
return state.recentList;
},
cur(state) {
return state.cur;
},
setFolder(state, folderlist){
state.folders = folderlist;
},
setFile(state, filelist){
state.files = filelist;
},
},
})
state: {
id: '',
folders: [],
files: [],
cur: '/',
parent: '/',
},
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;
},
setParent(state, parent) {
state.parent = parent;
},
},
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;
},
setFolder(state, folderlist) {
state.folders = folderlist;
},
setFile(state, filelist) {
state.files = filelist;
},
},
});
......