Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2020-1-CloudComputing
/
D_Team_Khuloud
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
박기범
2020-06-04 19:04:42 +0900
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
cf94c6a38239b99bc6c4a5798c8a600644da33bd
cf94c6a3
2 parents
e7a684f1
4997a81f
Merge branch 'new_file'
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
399 additions
and
140 deletions
backend/package-lock.json
backend/package.json
backend/routes/file/deleteFile.js
backend/routes/file/downloadFile.js
backend/routes/file/files.js
backend/routes/file/uploadFile.js
backend/routes/modules/awsconfig.json
backend/routes/modules/s3/download/kbpark9898/test.txt
backend/routes/modules/s3/download/kbpark9898/test4.txt
backend/routes/modules/s3/download/kbpark9898/test6.txt
backend/routes/modules/s3/download/shlee/test100(1).txt
backend/routes/modules/s3/s3.js
front-end/package-lock.json
front-end/src/api/index.js
front-end/src/components/FileList.vue
backend/package-lock.json
View file @
cf94c6a
This diff is collapsed. Click to expand it.
backend/package.json
View file @
cf94c6a
...
...
@@ -19,7 +19,7 @@
"morgan"
:
"~1.9.1"
,
"mysql"
:
"^2.18.1"
,
"passport"
:
"^0.4.1"
,
"pug"
:
"
2.0.0-beta11
"
,
"pug"
:
"
^3.0.0
"
,
"request"
:
"^2.88.2"
}
}
...
...
backend/routes/file/deleteFile.js
View file @
cf94c6a
...
...
@@ -8,37 +8,32 @@ var S3 = require('../modules/s3/s3');
// /file/delete/:name
router
.
get
(
'/:name'
,
function
(
req
,
res
)
{
var
user_id
=
req
.
session
.
user_id
;
var
file_name
=
req
.
params
.
name
;
var
user_id
=
req
.
query
.
id
;
var
curPath
=
req
.
query
.
cur
;
var
sourceFile
=
req
.
params
.
name
;
var
targetPath
=
'trashcan'
;
var
paths
=
sourceFile
.
split
(
'/'
);
var
index
=
sourceFile
.
length
-
(
paths
[
paths
.
length
-
1
].
length
+
1
);
var
file_name
=
paths
[
paths
.
length
-
1
];
var
location
=
sourceFile
.
substring
(
6
+
user_id
.
length
,
index
);
var
sourceFile
=
curPath
.
substring
(
1
)
+
file_name
;
var
sql1
=
'DELETE FROM files WHERE file_name = (?) AND location=(?) AND user_Id = (?)'
;
var
sql2
=
'INSERT INTO trashcan (trash_name, location, user_Id) VALUES (?, ?, ?)'
;
connection
.
query
(
sql1
,
[
file_name
,
location
,
user_id
],
function
(
err
)
{
connection
.
query
(
sql1
,
[
file_name
,
curPath
,
user_id
],
function
(
err
)
{
if
(
err
)
{
console
.
log
(
'delete db error'
);
throw
err
;
res
.
send
({
erorr
:
'db delete error'
})
;
}
else
{
connection
.
query
(
sql2
,
[
file_name
,
location
,
user_id
],
function
(
err
)
{
connection
.
query
(
sql2
,
[
file_name
,
'/trashcan'
+
curPath
,
user_id
],
function
(
err
)
{
if
(
err
)
{
console
.
log
(
'insert in trashcan db error'
);
throw
err
;
res
.
send
({
error
:
'db insert error'
})
;
}
else
{
// /drive/user_id/sourceFile --> /drive/user_id/trashcan/sourceFile
S3
.
moveFile
(
S3
.
BUCKET_NAME
,
user_id
,
sourceFile
,
targetPath
,
function
(
result
)
{
S3
.
moveFile
2
(
S3
.
BUCKET_NAME
,
user_id
,
sourceFile
,
targetPath
,
function
(
result
)
{
if
(
result
)
{
console
.
log
(
"file move to trashcan success"
);
res
.
send
(
"Upload Success"
);
res
.
send
(
"move to trashcan success"
);
}
})
}
...
...
backend/routes/file/downloadFile.js
View file @
cf94c6a
...
...
@@ -8,23 +8,68 @@ AWS.config.loadFromPath(__dirname + "/../modules/awsconfig.json");
var
S3
=
require
(
'../modules/s3/s3'
);
// /file/download/:name
router
.
get
(
'/:name'
,
function
(
req
,
res
)
{
var
file_name
=
req
.
params
.
name
;
var
user_id
=
req
.
session
.
user_id
;
var
curPath
=
req
.
query
.
cur
;
// /folder1/folder2/
var
user_id
=
req
.
query
.
id
;
var
targetFile
=
curPath
.
substring
(
1
)
+
file_name
;
// folder1/folder2/test.txt
S3
.
downloadFile3
(
S3
.
BUCKET_NAME
,
user_id
,
targetFile
,
function
(
result
,
downloadDir
)
{
if
(
result
)
{
res
.
send
({
src
:
downloadDir
})
}
else
{
res
.
send
({
err
:
'download error'
})
}
})
});
/*
router.get('/:name', function (req, res, next) {
var file_name = req.params.name; // test.txt
var user_id = req.query.id;
var curPath = req.query.cur; // /folder1/folder2/
var targetFile = (curPath + file_name).substring(1); // folder1/folder2/test.txt
var
sourceFile
=
file_name
;
var
tempDownloadDir
=
__dirname
+
'/../modules/s3/download/'
+
user_id
+
'/'
+
file_name
;
var s3 = new AWS.S3();
var params = {
Bucket: S3.BUCKET_NAME,
Key: 'drive/' + user_id + '/' + targetFile,
};
S3
.
downloadFile
(
S3
.
BUCKET_NAME
,
user_id
,
sourceFile
,
function
(
result
,
data
)
{
!
fs
.
existsSync
(
tempDownloadDir
+
'/../'
)
&&
fs
.
mkdirSync
(
tempDownloadDir
+
'/../'
);
fs
.
writeFileSync
(
tempDownloadDir
,
data
);
res
.
download
(
tempDownloadDir
,
function
(
err
)
{
fs
.
unlink
(
tempDownloadDir
,
function
(
err
)
{
console
.
log
(
"Download Success"
);
res.attachment(file_name);
var fileStream = s3.getObject(params).createReadStream();
fileStream.pipe(res);
});
*/
/*
// /file/download/:name
router.get('/:name', function (req, res) {
var file_name = req.params.name; // test.txt
var user_id = req.query.id;
var curPath = req.query.cur; // /folder1/folder2/
var targetFile = (curPath + file_name).substring(1); // folder1/folder2/test.txt
S3.downloadFile2(S3.BUCKET_NAME, user_id, targetFile, function (result, downloadDir) {
if (result){
res.download(downloadDir, function (err) {
if (err){
console.log(err);
}else{
console.log('download success');
}
});
});
}else{
res.send({error: 'download error'});
}
});
});
*/
module
.
exports
=
router
;
\ No newline at end of file
...
...
backend/routes/file/files.js
View file @
cf94c6a
...
...
@@ -5,36 +5,46 @@ var AWS = require('aws-sdk');
AWS
.
config
.
loadFromPath
(
__dirname
+
"/../modules/awsconfig.json"
);
var
S3
=
require
(
'../modules/s3/s3'
);
var
fs
=
require
(
'fs'
);
// /file
router
.
get
(
'/'
,
function
(
req
,
res
)
{
var
user_id
=
req
.
session
.
user_id
;
var
user_id
=
req
.
query
.
id
;
var
curPath
=
req
.
query
.
cur
;
// /folder1/folder2/
var
sql
=
'SELECT * FROM files WHERE user_id
=
(?) ORDER BY date DESC'
;
connection
.
query
(
sql
,
user_id
,
function
(
err
,
result
)
{
if
(
result
.
length
==
0
){
res
.
send
({
error
:
'
Exist Nothing
'
});
var
sql
=
'SELECT * FROM files WHERE user_id
=(?) AND location=
(?) ORDER BY date DESC'
;
connection
.
query
(
sql
,
[
user_id
,
curPath
]
,
function
(
err
,
result
)
{
if
(
err
){
res
.
send
({
error
:
'
select error
'
});
}
else
{
res
.
status
(
200
).
send
({
files
:
result
});
}
})
});
// /file/:name
router
.
get
(
'/:name'
,
function
(
req
,
res
)
{
var
file_name
=
req
.
params
.
name
;
var
user_id
=
req
.
session
.
user_id
;
var
curPath
=
req
.
query
.
cur
;
// /folder1/folder2/
var
user_id
=
req
.
query
.
id
;
var
targetFile
=
curPath
.
substring
(
1
)
+
file_name
;
// folder1/folder2/test.txt
var
extension
=
targetFile
.
split
(
'.'
)[
1
].
toLowerCase
();
var
s3
=
new
AWS
.
S3
();
var
sourceFile
=
'drive/'
+
user_id
+
'/'
+
file_name
;
var
params
=
{
Bucket
:
S3
.
BUCKET_NAME
,
Key
:
sourceFile
};
var
stream
=
s3
.
getObject
(
params
).
createReadStream
();
stream
.
pipe
(
res
,
function
(
err
)
{
if
(
err
)
{
throw
err
;
S3
.
downloadFile3
(
S3
.
BUCKET_NAME
,
user_id
,
targetFile
,
function
(
result
,
downloadDir
){
if
(
result
){
if
(
extension
==
'jpg'
||
extension
==
'jpeg'
||
extension
==
'png'
)
{
res
.
status
(
200
).
send
({
type
:
'image'
,
src
:
downloadDir
})
}
else
{
res
.
status
(
200
).
send
({
type
:
'text'
,
src
:
downloadDir
})
}
}
})
});
});
module
.
exports
=
router
;
\ No newline at end of file
...
...
backend/routes/file/uploadFile.js
View file @
cf94c6a
...
...
@@ -11,80 +11,79 @@ var S3 = require('../modules/s3/s3');
// /file/upload
router
.
post
(
'/'
,
function
(
req
,
res
)
{
var
user_id
=
req
.
session
.
user_id
;
var
sourceFiles
=
[];
var
errFiles
=
[];
var
targetPath
=
''
;
var
bodies
=
[];
var
form
=
new
formidable
.
IncomingForm
();
form
.
multiples
=
true
;
form
.
parse
(
req
,
function
(
err
,
fields
,
files
)
{
if
(
!
files
.
file
[
0
]){
sourceFiles
.
push
(
files
.
file
.
name
);
bodies
.
push
(
files
.
file
.
path
);
console
.
log
(
files
);
/* form-data로 받아야 함 */
var
user_id
=
fields
.
user_id
;
var
curPath
=
fields
.
cur
// /folder1/folder2/
console
.
log
(
user_id
);
console
.
log
(
curPath
);
var
sourceFiles
=
[];
var
errFiles
=
[];
var
targetPath
;
// 'folder1/folder2'
var
bodies
=
[];
var
errMessage
=
'upload error'
;
if
(
curPath
==
'/'
)
{
targetPath
=
''
;
}
else
{
targetPath
=
curPath
.
substring
(
1
,
curPath
.
length
-
1
);
}
if
(
!
files
.
file
[
0
]){
// 파일 하나일 때
var
checkFileName
=
files
.
file
.
name
;
checkFileName
=
checkFileName
.
split
(
'('
).
join
(
','
).
split
(
')'
).
join
(
','
).
split
(
','
);
if
(
checkFileName
.
length
>
1
)
{
errFiles
.
push
(
files
.
file
.
name
);
errMessage
=
'check your file name(\'(\', \')\' x!)'
}
else
{
sourceFiles
.
push
(
files
.
file
.
name
);
bodies
.
push
(
files
.
file
.
path
);
}
}
else
{
for
(
var
file
of
files
.
file
)
{
sourceFiles
.
push
(
file
.
name
);
bodies
.
push
(
file
.
path
);
for
(
var
file
of
files
.
file
)
{
// 파일 여러개일 때
var
checkFileName
=
file
.
name
;
checkFileName
=
checkFileName
.
split
(
'('
).
join
(
','
).
split
(
')'
).
join
(
','
).
split
(
','
);
if
(
checkFileName
.
length
>
1
){
errFiles
.
push
(
file
.
name
);
}
else
{
sourceFiles
.
push
(
file
.
name
);
bodies
.
push
(
file
.
path
);
}
}
}
S3
.
uploadFiles
(
0
,
errFiles
,
S3
.
BUCKET_NAME
,
user_id
,
sourceFiles
,
targetPath
,
bodies
,
function
(
result
,
errFiles
)
{
var
newSourceFiles
=
[];
if
(
!
result
)
{
// 에러 파일이 있는 경우
for
(
var
sourceFile
of
sourceFiles
)
{
if
(
!
(
sourceFile
in
errFiles
))
{
newSourceFiles
.
push
(
sourceFile
);
}
var
noErrSourceFiles
=
[];
for
(
var
sourceFile
of
sourceFiles
)
{
if
(
!
(
sourceFile
in
errFiles
))
{
noErrSourceFiles
.
push
(
sourceFile
);
}
}
for
(
var
sourceFile
of
s
ourceFiles
)
{
for
(
var
sourceFile
of
noErrS
ourceFiles
)
{
var
sql
=
'INSERT INTO files (file_name, user_id, location) VALUES (?, ?, ?)'
;
connection
.
query
(
sql
,
[
file_name
,
user_id
,
target
Path
],
function
(
err
,
result
)
{
connection
.
query
(
sql
,
[
sourceFile
,
user_id
,
cur
Path
],
function
(
err
,
result
)
{
if
(
err
)
{
console
.
log
(
'insert file {'
,
sourceFile
,
'} in db failed'
);
console
.
log
(
'insert error'
);
res
.
send
({
error
:
'insert error'
});
}
})
}
res
.
send
({
Errfiles
:
errFiles
});
if
(
errFiles
.
length
){
res
.
send
({
err
:
errMessage
,
errFiles
:
errFiles
})
}
else
{
res
.
send
({
message
:
'Upload Success'
,
finalFiles
:
sourceFiles
});
}
})
})
})
/*
// /file/upload
router.post('/', function (req, res) {
//var user_id = req.session.user_id;
var user_id = 'shlee';
var form = new formidable.IncomingForm();
form.parse(req, function (err, fields, files) {
var file_name = files.file.name;
var sourceFile = file_name;
var targetPath = '';
var sql = 'INSERT INTO files (file_name, user_id) VALUES (?)';
connection.query(sql, [[file_name, user_id]], function (err) {
if (err) {
console.log("Upload db error");
throw err;
} else {
S3.uploadFile(S3.BUCKET_NAME, user_id, sourceFile, targetPath, files.file.path, function (result) {
if (result) {
console.log("Upload Success");
res.send(result);
} else {
console.log("Upload Fail: Check FIle Duplication");
}
})
}
});
})
});
*/
module
.
exports
=
router
;
\ No newline at end of file
...
...
backend/routes/modules/awsconfig.json
View file @
cf94c6a
{
"accessKeyId"
:
"ASIA
ZQ5XTMMFRBJO2LG5
"
,
"secretAccessKey"
:
"
ltsYvzKAoQ5UnNWEk13Zf8n4wJdkQkemsJ7GdsbS
"
,
"sessionToken"
:
"FwoGZXIvYXdzE
I///////////wEaDLleFCvWDhdhFpXCvCLDAX/Hka6vXTZKxdyEBUh7ZSxPYLH184u1Tpo2qWHYFziUVKWJSCm5wqPNv0QWoAp8sL5NB0W5kty8hoeKv16SYB9Z+yzT1qtfuKTmrro2jGSo7AnxDSBla6UQHAv82yVetiGwu+IKhm6tHUvdNSlkIV0Qi9rNrDc9eynhFN/emFI/6NsocbQ47mmW6BZx0Z4/hHKW9TL6Uec/E87Z+oxVRFsVOGyNtow980bQgZFYJMbh3AN6poTlofP1q/qn2nUWwAdsDCjfhr/2BTItlcDfO5PEH5Gwffzv69JMTVBIemfIpS/Ybx6F6i7GbI2fZKGtGfRSecobbj4m
"
,
"accessKeyId"
:
"ASIA
XZL2SWFEYG2GUYVJ
"
,
"secretAccessKey"
:
"
ceYvfLs25iiBDfigO7PbP67kJoKswJdfduqROrJt
"
,
"sessionToken"
:
"FwoGZXIvYXdzE
DMaDGvezwF9kQrAJ+uhfSLDASWFKBk7UNbRzZVEM1eoGJ3E+UI9d4xSpqEDqRYjsOTn5wYIGM3mUCZ8S6/XCnGP5yFz+qv9mBLDf311iP9ajY091OhQ8c2nB6l+JHuRKAz6FhGLrjHtD1AecHtjHOu5dXODU2+9ctvGj7V60KYqjToah5Tvv84EVac/41Les3rtrqcXS/bbmVwv5kDz9K1FJStln4sXZ/foueGHZAkAJQ6LAtIQWg4/reFUcWAi8E0bUjMckmymDQhnVNWcSbgQ+htBYiiPg+P2BTItOqWuZojM5lw32rTv7+PuOaeyHjx3+Vcd4bo3orSJr57P2ZPfmglZNKY7W5aw
"
,
"region"
:
"us-east-1"
}
\ No newline at end of file
}
...
...
backend/routes/modules/s3/download/kbpark9898/test.txt
0 → 100644
View file @
cf94c6a
asdf
\ No newline at end of file
backend/routes/modules/s3/download/kbpark9898/test4.txt
0 → 100644
View file @
cf94c6a
File mode changed
backend/routes/modules/s3/download/kbpark9898/test6.txt
0 → 100644
View file @
cf94c6a
File mode changed
backend/routes/modules/s3/download/shlee/test100(1).txt
0 → 100644
View file @
cf94c6a
File mode changed
backend/routes/modules/s3/s3.js
View file @
cf94c6a
...
...
@@ -17,7 +17,7 @@
var
AWS
=
require
(
'aws-sdk'
);
AWS
.
config
.
update
({
region
:
'ap-northeast-2'
});
var
BUCKET_NAME
=
'
d
khuloud'
;
var
BUCKET_NAME
=
'khuloud'
;
var
s3
=
new
AWS
.
S3
();
var
fs
=
require
(
'fs'
);
...
...
@@ -52,6 +52,8 @@ var S3 = {
},
copyFile2
:
function
(
bucketName
,
userId
,
sourceFile
,
targetFile
,
callback
)
{
// sourceFile => folder1/folder2/test.txt
// targetFile => trashcan/folder1/folder2/test.txt
var
copyParams
=
{
Bucket
:
bucketName
,
CopySource
:
bucketName
+
'/drive/'
+
userId
+
'/'
+
sourceFile
,
...
...
@@ -72,6 +74,7 @@ var S3 = {
},
deleteFile
:
function
(
bucketName
,
userId
,
targetFile
,
callback
)
{
// targetFile => folder1/folder2/test.txt
var
deleteParams
=
{
Bucket
:
bucketName
,
Key
:
'drive/'
+
userId
+
'/'
+
targetFile
...
...
@@ -95,7 +98,7 @@ var S3 = {
Bucket
:
bucketName
,
Key
:
'drive/'
+
userId
+
'/'
+
targetFile
};
console
.
log
(
'drive/'
+
userId
+
'/'
+
targetFile
);
s3
.
getObject
(
downloadParams
,
function
(
err
,
data
)
{
if
(
err
)
{
console
.
log
(
"Download File Error"
,
err
);
...
...
@@ -103,12 +106,55 @@ var S3 = {
}
else
{
if
(
data
)
{
console
.
log
(
"Get File Success"
);
callback
(
1
,
data
.
Body
);
callback
(
true
,
data
.
body
.
toString
()
);
}
}
})
},
// /routes/modules/s3/download에 저장
downloadFile2
:
function
(
bucketName
,
userId
,
targetFile
,
callback
){
tempDownloadDir
=
__dirname
+
'/download/'
+
userId
+
'/'
+
targetFile
;
S3
.
downloadFile
(
bucketName
,
userId
,
targetFile
,
function
(
result
,
data
){
if
(
result
)
{
makeFolder
(
tempDownloadDir
,
function
(
result
){
if
(
result
)
{
fs
.
writeFileSync
(
tempDownloadDir
,
data
);
callback
(
true
,
tempDownloadDir
);
}
})
}
else
{
console
.
log
(
'Download File Error'
);
callback
(
false
);
}
})
},
// 최종
downloadFile3
:
function
(
bucketName
,
userId
,
targetFile
,
callback
){
// targetFile 예1 => test.txt
// targetFile 예2 => folder1/folder2/test.txt
var
tempDownloadDir
=
__dirname
+
'/download/'
+
userId
+
'/'
+
targetFile
;
makeFolder
(
tempDownloadDir
,
function
(
result
){
if
(
result
){
var
file
=
fs
.
createWriteStream
(
tempDownloadDir
);
var
params
=
{
Bucket
:
bucketName
,
Key
:
'drive/'
+
userId
+
'/'
+
targetFile
};
try
{
s3
.
getObject
(
params
).
createReadStream
().
pipe
(
file
);
callback
(
true
,
tempDownloadDir
);
}
catch
(
err
){
console
.
log
(
'no such file'
);
callback
(
false
);
}
}
else
{
callback
(
false
);
}
})
},
getFileList
:
function
(
bucketName
,
userId
,
targetPath
,
callback
)
{
var
prefix
;
...
...
@@ -174,6 +220,20 @@ var S3 = {
})
},
// 중복된 파일 버전 만들기(test.txt -> text(1).txt)
makeVersion
:
function
(
bucketName
,
userId
,
sourceFile
,
lvNum
,
callback
)
{
var
sourceFile
;
var
splited
=
sourceFile
.
split
(
'('
).
join
(
','
).
split
(
')'
).
join
(
','
).
split
(
','
);
if
(
splited
.
length
!=
3
)
{
sourceFile
=
sourceFile
.
split
(
'.'
)[
0
]
+
'('
+
lvNum
.
toString
()
+
').'
+
sourceFile
.
split
(
'.'
)[
1
];
}
else
{
sourceFile
=
sourceFile
.
split
(
'('
)[
0
]
+
'('
+
lvNum
.
toString
()
+
')'
+
sourceFile
.
split
(
')'
)[
1
];
}
console
.
log
(
'makeVersion '
,
sourceFile
);
callback
(
true
,
sourceFile
);
},
// sourceFile이 단순히 filename과 같은 경우
moveFile
:
function
(
bucketName
,
userId
,
sourceFile
,
targetPath
,
callback
)
{
S3
.
copyFile
(
bucketName
,
userId
,
sourceFile
,
targetPath
,
function
(
res
)
{
...
...
@@ -194,25 +254,10 @@ var S3 = {
})
},
makeVersion
:
function
(
bucketName
,
userId
,
sourceFile
,
lvNum
,
callback
){
var
sourceFile
;
var
splited
=
sourceFile
.
split
(
'('
).
join
(
','
).
split
(
')'
).
join
(
','
).
split
(
','
);
if
(
splited
.
length
!=
3
){
sourceFile
=
sourceFile
.
split
(
'.'
)[
0
]
+
'('
+
lvNum
.
toString
()
+
')'
+
sourceFile
.
split
(
'.'
)[
1
];
}
else
{
sourceFile
=
sourceFile
.
split
(
'('
)[
0
]
+
'('
+
lvNum
.
toString
()
+
')'
+
sourceFile
.
split
(
')'
)[
1
];
}
console
.
log
(
'makeVersion '
,
sourceFile
);
callback
(
true
,
sourceFile
);
},
// sourceFile에 임의의 경로가 포함된 경우
moveFile2
:
function
(
bucketName
,
userId
,
sourceFile
,
targetPath
,
callback
)
{
var
paths
=
sourceFile
.
split
(
'/'
);
var
filename
=
paths
[
paths
.
length
-
1
];
console
.
log
(
'paths = '
+
paths
);
console
.
log
(
'filename = '
+
filename
);
var
targetFile
=
targetPath
+
filename
;
// sourceFile => folder1/folder2/test.txt
var
targetFile
=
targetPath
+
'/'
+
sourceFile
;
S3
.
copyFile2
(
bucketName
,
userId
,
sourceFile
,
targetFile
,
function
(
res
)
{
if
(
!
res
)
{
...
...
@@ -235,10 +280,11 @@ var S3 = {
uploadFile
:
function
(
bucketName
,
userId
,
sourceFile
,
targetPath
,
body
,
callback
)
{
var
pathbody
=
fs
.
createReadStream
(
body
);
if
(
targetPath
!=
'
'
)
{
if
(
targetPath
!=
''
&&
targetPath
[
targetPath
.
length
-
1
]
!=
'/
'
)
{
targetPath
=
targetPath
+
'/'
;
}
var
targetFile
=
targetPath
+
sourceFile
;
console
.
log
(
'targetFile'
,
targetFile
);
var
uploadParams
=
{
Bucket
:
bucketName
,
...
...
@@ -299,4 +345,23 @@ var S3 = {
},
}
module
.
exports
=
S3
;
\ No newline at end of file
var
makeFolder
=
function
(
dir
,
callback
){
var
paths
=
dir
.
substring
(
__dirname
.
length
+
1
);
// download/userId/folder1/folder2/test.txt
paths
=
paths
.
split
(
'/'
);
var
folders
=
__dirname
;
for
(
var
i
=
0
;
i
<
paths
.
length
-
1
;
i
++
){
folders
+=
'/'
+
paths
[
i
];
if
(
!
fs
.
existsSync
(
folders
)){
fs
.
mkdirSync
(
folders
)
}
}
if
(
fs
.
existsSync
(
folders
)){
callback
(
true
);
}
else
{
callback
(
false
);
}
}
module
.
exports
=
S3
;
...
...
front-end/package-lock.json
View file @
cf94c6a
...
...
@@ -5775,9 +5775,9 @@
}
},
"http-proxy"
:
{
"version"
:
"1.18.
0
"
,
"resolved"
:
"https://registry.npmjs.org/http-proxy/-/http-proxy-1.18.
0
.tgz"
,
"integrity"
:
"sha512-
84I2iJM/n1d4Hdgc6y2+qY5mDaz2PUVjlg9znE9byl+q0uC3DeByqBGReQu5tpLK0TAqTIXScRUV+dg7+bUPp
Q=="
,
"version"
:
"1.18.
1
"
,
"resolved"
:
"https://registry.npmjs.org/http-proxy/-/http-proxy-1.18.
1
.tgz"
,
"integrity"
:
"sha512-
7mz/721AbnJwIVbnaSv1Cz3Am0ZLT/UBwkC92VlxhXv/k/BBQfM2fXElQNC27BVGr0uwUpplYPQM9LnaBMR5N
Q=="
,
"dev"
:
true
,
"requires"
:
{
"eventemitter3"
:
"^4.0.0"
,
...
...
front-end/src/api/index.js
View file @
cf94c6a
...
...
@@ -35,6 +35,52 @@ function moveFolder(folderData) {
return
axios
.
post
(
'/api/folder/move'
,
folderData
);
}
function
file
(
curData
){
return
axios
.
get
(
'/api/file'
,
{
params
:
{
id
:
curData
.
id
,
cur
:
curData
.
cur
}
});
}
function
uploadFile
(
fileData
){
return
axios
.
post
(
'/api/file/upload'
,
fileData
,
{
headers
:{
'Content-Type'
:
'multipart/form-data'
}
});
}
function
detailFile
(
fileData
){
return
axios
.
get
(
`/api/file/
${
fileData
.
name
}
`
,
{
params
:{
id
:
fileData
.
id
,
cur
:
fileData
.
cur
}
})
}
function
deleteFile
(
fileData
){
return
axios
.
get
(
`/api/file/delete/
${
fileData
.
fileName
}
`
,
{
params
:{
//현재 접속한 사람의 id와 삭제할 파일의 이름, 현재 폴더위치를 파라미터로 넘긴다.
id
:
fileData
.
user_id
,
cur
:
fileData
.
cur
}
});
}
function
downloadFile
(
fileData
){
return
axios
.
get
(
`api/file/download/
${
fileData
.
fileName
}
`
,
{
params
:{
//현재 접속한 사람의 id와 다운로드를 위해 선택한 파일의 이름을 파라미터로 넘긴다.
id
:
fileData
.
id
,
cur
:
fileData
.
cur
}
});
}
export
{
registerUser
,
loginUser
,
folder
,
makeFolder
,
deleteFolder
,
moveFolder
};
export
{
registerUser
,
loginUser
,
folder
,
makeFolder
,
deleteFolder
,
moveFolder
,
file
,
uploadFile
,
deleteFile
,
downloadFile
};
...
...
front-end/src/components/FileList.vue
View file @
cf94c6a
...
...
@@ -29,7 +29,7 @@
<v-list-item-title v-text="item.folder_name"></v-list-item-title>
</v-list-item-content>
<v-menu
v-model="showMenu"
...
...
@@ -94,18 +94,22 @@
<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-title v-text="item
.file_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 icon
@click="download_file(item.file_name)"
>
<v-icon color="grey lighten-1">mdi-
download
</v-icon>
</v-btn>
<v-btn icon>
<v-icon color="grey lighten-1">mdi-del
ted
</v-icon>
<v-btn icon
@click="delete_file(item.file_name)"
>
<v-icon color="grey lighten-1">mdi-del
ete
</v-icon>
</v-btn>
</v-list-item-action>
</v-list-item>
</v-list>
<input id = "file-selector" ref='uploadedfile' type="file"
v-on:change="handleFileUpload()">
<br>
<!--
<v-file-input
v-model="files"
color="deep-purple accent-4"
...
...
@@ -134,7 +138,10 @@
+{{ 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"
...
...
@@ -177,11 +184,12 @@
</div>
</template>
<script>
import { folder, makeFolder, deleteFolder, moveFolder } from '../api/index';
import { folder, makeFolder, deleteFolder, moveFolder
, file, uploadFile, deleteFile, downloadFile
} from '../api/index';
import Axios from 'axios';
export default {
data() {
return {
uploadedfile:null,
foldername:'',
curfName:'',
folders: [],
...
...
@@ -189,12 +197,18 @@ import Axios from 'axios';
search:'',
id: '',
dialog:false,
search: '',
howMenu: false,
showMenu: false,
x: 0,
y: 0,
dialog2:false
dialog2:false,
detail : {
dataname: null,
date: null,
owner_id:null,
datasize:null,
datatype:null
}
}
},
async created(){
...
...
@@ -203,18 +217,28 @@ import Axios from 'axios';
id : this.$store.state.id,
cur: '/'
}
console.log(curData);
const response = await folder(curData);
cons
ole.log(response.d
ata);
cons
t file_response = await file(curD
ata);
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);
this.files = this.$store.getters.fileL;
} catch (error) {
console.log("에러");
console.log(error
.response.data
);
console.log(error);
}
},
methods: {
handleFileUpload(){
this.uploadedfile= this.$refs.uploadedfile.files[0]
console.log(this.uploadedfile)
},
initFolderName(){
this.foldername = '';
},
...
...
@@ -316,6 +340,80 @@ import Axios from 'axios';
this.dialog2 = false;
}
},
async upload_file(){
try{
const formData = new FormData();
formData.append('file', this.uploadedfile);
formData.append('user_id', this.$store.state.id);
formData.append('cur', this.$store.state.cur);
const currentData={
id: this.$store.state.id,
cur: this.$store.state.cur
}
console.log(currentData)
const response = await uploadFile(formData);
const filelist = await file(currentData);
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 delete_file(itemName){
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){
currentData.fileName = itemlist[i].file_name;
currentData.user_id = itemlist[i].user_id;
}
}
const filelistData={
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){
try{
const currentData={
fileName : namedata,
id: this.$store.state.id,
cur: this.$store.state.cur
}
const result = await downloadFile(currentData);
console.log(result)
}catch(error){
console.log("에러");
console.log(error);
}
}
},
show (folderN, e) {
e.preventDefault()
this.curfName = folderN;
...
...
@@ -326,6 +424,6 @@ import Axios from 'axios';
this.showMenu = true
})
}
}
}
</script>
\ No newline at end of file
</script>
...
...
Please
register
or
login
to post a comment