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-05-30 15:07:57 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
6d47ceea94e0d23b68212991ea51debcbb8dc2ff
6d47ceea
1 parent
83ae25dc
'.'
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
281 additions
and
198 deletions
backend/routes/file/deleteFile.js
backend/routes/file/downloadFile.js
backend/routes/file/files.js
backend/routes/file/uploadFile.js
backend/routes/folders.js
backend/routes/modules/awsconfig.json
backend/routes/modules/config.js
backend/routes/modules/s3/download/IU/folder1/test4.txt
backend/routes/modules/s3/s3.js
backend/routes/file/deleteFile.js
View file @
6d47cee
...
...
@@ -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
.
status
(
404
).
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
.
status
(
404
).
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
.
satus
(
200
).
send
(
"move to trashcan success"
);
}
})
}
...
...
backend/routes/file/downloadFile.js
View file @
6d47cee
...
...
@@ -8,22 +8,25 @@ 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
sourceFile
=
file_name
;
var
tempDownloadDir
=
__dirname
+
'/../modules/s3/download/'
+
user_id
+
'/'
+
file_name
;
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"
);
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
)
{
fs
.
unlink
(
downloadDir
,
function
(
err
)
{
console
.
log
(
'download success'
);
});
});
}
else
{
res
.
status
(
404
).
send
({
error
:
'download error'
});
}
});
});
...
...
backend/routes/file/files.js
View file @
6d47cee
...
...
@@ -5,33 +5,43 @@ 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
s3
=
new
AWS
.
S3
();
var
targetFile
=
curPath
.
substring
(
1
)
+
file_name
;
// folder1/folder2/test.txt
var
extension
=
targetFile
.
split
(
'.'
)[
1
].
toLowerCase
();
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
})
}
}
})
});
...
...
backend/routes/file/uploadFile.js
View file @
6d47cee
...
...
@@ -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
form
=
new
formidable
.
IncomingForm
();
form
.
multiples
=
true
;
form
.
parse
(
req
,
function
(
err
,
fields
,
files
)
{
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
=
''
;
var
targetPath
;
// 'folder1/folder2'
var
bodies
=
[];
var
errMessage
=
'upload error'
;
if
(
curPath
==
'/'
)
{
targetPath
=
''
;
}
else
{
targetPath
=
curPath
.
substring
(
1
,
curPath
.
length
-
1
);
}
var
form
=
new
formidable
.
IncomingForm
();
form
.
multiples
=
true
;
form
.
parse
(
req
,
function
(
err
,
fields
,
files
)
{
if
(
!
files
.
file
[
0
]){
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
)
{
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
)
{
// 에러 파일이 있는 경우
var
noErrSourceFiles
=
[];
for
(
var
sourceFile
of
sourceFiles
)
{
if
(
!
(
sourceFile
in
errFiles
))
{
newSourceFiles
.
push
(
sourceFile
);
}
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
});
})
})
})
/*
// /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);
if
(
errFiles
.
length
){
res
.
send
({
err
:
errMessage
,
errFiles
:
errFiles
})
}
else
{
console.log("Upload Fail: Check FIle Duplication");
res
.
send
({
message
:
'Upload Success'
,
finalFiles
:
sourceFiles
});
}
})
}
});
})
})
;
*/
})
module
.
exports
=
router
;
\ No newline at end of file
...
...
backend/routes/folders.js
View file @
6d47cee
...
...
@@ -29,17 +29,26 @@ 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
})
}
}
});
});
...
...
@@ -61,9 +70,6 @@ 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
)
{
...
...
@@ -71,6 +77,8 @@ 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
)
{
...
...
@@ -78,175 +86,172 @@ 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
)
{
console
.
log
(
rows
);
if
(
rows
.
length
!=
0
)
{
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
.
id
;
let
cur
=
req
.
body
.
cur
;
curPath
=
user_id
+
cur
;
user_id
=
req
.
body
.
user_id
;
curPath
=
user_id
+
req
.
body
.
cur
;
let
folder_name
=
req
.
body
.
folder_name
;
let
params
=
{
Bucket
:
BUCKET_NAME
,
Key
:
curPath
+
folder_name
+
'/'
Bucket
:
BUCKET_NAME
+
curPath
,
Key
:
folder_name
+
'/'
};
let
checksql
=
'SELECT * FROM folders WHERE location = ? AND folder_name = ? AND user_id = ?;'
;
let
values
=
[
cur
,
folder_name
,
user_id
];
let
checksql
=
'SELECT * FROM folders WHERE location = ? AND folder_name = ?;'
;
let
values
=
[
curPath
,
folder_name
];
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
{
console
.
log
(
data
);
let
sql
=
'DELETE FROM folders WHERE location = ? AND folder_name = ? AND user_id = ?;'
;
let
sql
=
'DELETE FROM folders WHERE location = ? AND folder_name = ?;'
;
connection
.
query
(
sql
,
values
,
function
(
err
,
result
,
field
)
{
if
(
err
)
{
//throw err;
}
else
{
console
.
log
(
cur
);
console
.
log
(
user_id
);
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
folders
:
rows
,
cur
:
curPath
})
}
else
{
res
.
send
({
error
:
"Does not exist"
});
}
});
}
});
}
});
}
else
{
console
.
log
(
req
.
body
);
res
.
status
(
304
).
send
({
error
:
"Does not exist"
});
}
res
.
send
({
error
:
"Does not exist"
});
}
});
});
router
.
post
(
'/move'
,
function
(
req
,
res
,
next
)
{
console
.
log
(
req
.
body
);
user_id
=
req
.
body
.
id
;
let
cur
=
req
.
body
.
cur
;
curPath
=
user_id
+
cur
;
let
n
ame
=
req
.
body
.
folder_name
;
let
newPath
=
user_id
+
req
.
body
.
newPath
;
user_id
=
req
.
body
.
user_
id
;
curPath
=
user_id
+
req
.
body
.
cur
;
let
name
=
req
.
body
.
mfile
;
let
n
ewPath
=
req
.
body
.
newPath
;
let
checkfolder
=
'SELECT * FROM folders WHERE location = ? AND folder_name = ?;'
;
if
(
req
.
body
.
isfolder
)
{
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
);
connection
.
query
(
checkfolder
,
[
curPath
,
name
],
function
(
err1
,
rows
,
fields
)
{
if
(
rows
.
length
!=
0
)
{
let
copy_params
=
{
Bucket
:
BUCKET_NAME
,
CopySource
:
BUCKET_NAME
+
'/'
+
curPath
+
nam
e
+
'/'
,
Key
:
newPath
+
nam
e
+
'/'
Bucket
:
BUCKET_NAME
+
curPath
,
CopySource
:
BUCKET_NAME
+
curPath
+
fil
e
+
'/'
,
Key
:
newPath
+
fil
e
+
'/'
};
let
del_params
=
{
Bucket
:
BUCKET_NAME
,
Key
:
curPath
+
nam
e
+
'/'
Bucket
:
BUCKET_NAME
+
curPath
,
Key
:
fil
e
+
'/'
};
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
values
=
[
req
.
body
.
newPath
,
cur
,
name
,
user_id
];
let
updatesql
=
'UPDATE folders SET location = ? WHERE location = ? AND folder_name = ? AND user_id = ?;'
;
});
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
)
{
console
.
log
(
"updatesql error"
);
res
.
status
(
304
).
send
({
error
:
"updatesql error"
});
throw
err
;
}
else
{
let
resultsql
=
'SELECT * FROM folders WHERE location = ? AND user_id = ?;'
;
connection
.
query
(
resultsql
,
[
cur
,
user_id
],
function
(
err
,
rows
,
fields
)
{
folders
=
{}
connection
.
query
(
checkfolder
,
[
cur
,
user_id
],
function
(
err
,
rows
,
fields
)
{
if
(
rows
.
length
!=
0
)
{
res
.
status
(
200
).
send
({
folders
:
rows
});
});
}
});
folders
:
rows
,
cur
:
curPath
})
}
else
{
res
.
send
({
error
:
"Does not exist"
});
}
});
}
});
}
else
{
console
.
log
(
"Does not exist"
);
res
.
status
(
304
).
send
({
error
:
"Does not exist"
});
res
.
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 = ?'
;
connection
.
query
(
checkfile
,
[
curPath
,
name
],
function
(
err1
,
rows
,
fields
)
{
if
(
rows
.
length
!=
0
)
{
let
copy_params
=
{
Bucket
:
BUCKET_NAME
,
CopySource
:
BUCKET_NAME
+
'/'
+
curPath
+
file
,
Bucket
:
BUCKET_NAME
+
curPath
,
CopySource
:
BUCKET_NAME
+
curPath
+
file
,
Key
:
newPath
+
file
};
let
del_params
=
{
Bucket
:
BUCKET_NAME
,
Key
:
curPath
+
file
Bucket
:
BUCKET_NAME
+
curPath
,
Key
:
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
);
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 = ?;'
;
});
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
)
{
res
.
status
(
304
).
send
({
error
:
"updatesql error"
})
;
throw
err
;
}
else
{
let
resultsql
=
'SELECT * FROM folders WHERE location = ? AND user_id = ?;'
;
connection
.
query
(
resultsql
,
[
cur
,
user_id
],
function
(
err
,
rows
,
fields
)
{
folders
=
{}
connection
.
query
(
checkfolder
,
[
cur
,
user_id
],
function
(
err
,
rows
,
fields
)
{
if
(
rows
.
length
!=
0
)
{
res
.
status
(
200
).
send
({
folders
:
rows
});
});
}
});
folders
:
rows
,
cur
:
curPath
})
}
else
{
res
.
send
({
error
:
"Does not exist"
});
}
});
}
});
}
else
{
res
.
s
tatus
(
304
).
s
end
({
error
:
"Does not exist"
});
res
.
send
({
error
:
"Does not exist"
});
}
});
...
...
backend/routes/modules/awsconfig.json
View file @
6d47cee
{
"accessKeyId"
:
"ASIAZQ5XTMMFR
BJO2LG5
"
,
"secretAccessKey"
:
"
ltsYvzKAoQ5UnNWEk13Zf8n4wJdkQkemsJ7GdsbS
"
,
"sessionToken"
:
"FwoGZXIvYXdzE
I///////////wEaDLleFCvWDhdhFpXCvCLDAX/Hka6vXTZKxdyEBUh7ZSxPYLH184u1Tpo2qWHYFziUVKWJSCm5wqPNv0QWoAp8sL5NB0W5kty8hoeKv16SYB9Z+yzT1qtfuKTmrro2jGSo7AnxDSBla6UQHAv82yVetiGwu+IKhm6tHUvdNSlkIV0Qi9rNrDc9eynhFN/emFI/6NsocbQ47mmW6BZx0Z4/hHKW9TL6Uec/E87Z+oxVRFsVOGyNtow980bQgZFYJMbh3AN6poTlofP1q/qn2nUWwAdsDCjfhr/2BTItlcDfO5PEH5Gwffzv69JMTVBIemfIpS/Ybx6F6i7GbI2fZKGtGfRSecobbj4m
"
,
"accessKeyId"
:
"ASIAZQ5XTMMFR
YJNKBIQ
"
,
"secretAccessKey"
:
"
NNsqT/NamEdilVYzp/dS8ys2MMlEDEmyreZb6VLJ
"
,
"sessionToken"
:
"FwoGZXIvYXdzE
LP//////////wEaDJMOjkb8lIC9vGm9uCLDAWLA9QiZ4tlf+5oJaJE3MQeD6PKFGE1xTVNBTIKOY6ROuMC+sHfKVONokm+comkRD5z2Mi4l7XxSQDmOM3TtcuxwsJWw5aIKKUUUqCQbzqEy2JSAsJxBMUDiUGQnIlYJDCuB+uWWvfgAxUrDz/ReJQeXmpuFOVIymn12jTXy4scLZcz22cpiZj4pr9d05VOkzUyXozIHGEVEHgIV1qdy5sJLMicz4RQi4+bIuE5w4lCYdpk0nzduAHStgyWEN0/VjEbJSCiG48b2BTIt675GjnR/TJwYd8BOnqKzAwQyF4WxMzAgJ2NaCwPcE0ZR2/KVYQoIO1Os/Vk6
"
,
"region"
:
"us-east-1"
}
\ No newline at end of file
...
...
backend/routes/modules/config.js
View file @
6d47cee
var
mysql
=
require
(
'mysql'
);
connection
=
mysql
.
createConnection
({
host
:
'1.201.142.243'
,
user
:
'khuloud'
,
//host: '1.201.142.243',
//user: 'khuloud',
//port: 3306,
//password: 'password1234',
//database: 'khuloud',
//connectionLimit: 30
host
:
'localhost'
,
user
:
'root'
,
port
:
3306
,
password
:
'password1234'
,
database
:
'khuloud'
,
connectionLimit
:
30
password
:
'1234'
,
database
:
'temp'
});
\ No newline at end of file
...
...
backend/routes/modules/s3/download/IU/folder1/test4.txt
0 → 100644
View file @
6d47cee
안녕
\ No newline at end of file
backend/routes/modules/s3/s3.js
View file @
6d47cee
...
...
@@ -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,8 +106,51 @@ var S3 = {
}
else
{
if
(
data
)
{
console
.
log
(
"Get File Success"
);
callback
(
1
,
data
.
Body
);
callback
(
true
,
data
.
body
);
}
}
})
},
// /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
);
}
})
},
...
...
@@ -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 = {
},
}
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
;
\ No newline at end of file
...
...
Please
register
or
login
to post a comment