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-11 02:08:51 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
2929790639c6704dedc845f17fa91afe21b06dda
29297906
1 parent
17294880
merge
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
44 additions
and
67 deletions
backend/routes/file/deleteFile.js
backend/routes/file/downloadFile.js
backend/routes/file/files.js
backend/routes/file/modifyFile.js
backend/routes/modules/s3/s3.js
backend/routes/file/deleteFile.js
View file @
2929790
...
...
@@ -7,9 +7,7 @@ var S3 = require('../modules/s3/s3');
// /file/delete/:name
router
.
get
(
'/:name'
,
function
(
req
,
res
)
{
console
.
log
(
req
.
query
);
console
.
log
(
req
.
params
);
router
.
get
(
'/:name'
,
function
(
req
,
res
)
{
var
file_name
=
req
.
params
.
name
;
var
user_id
=
req
.
query
.
id
;
var
curPath
=
req
.
query
.
cur
;
...
...
@@ -17,56 +15,35 @@ router.get('/:name', function(req, res) {
var
targetPath
=
'trashcan'
;
var
sourceFile
=
curPath
.
substring
(
1
)
+
file_name
;
var
sql1
=
'UPDATE files SET location = ? WHERE location = ? AND file_name = ? AND user_id = ?;'
;
connection
.
query
(
sql1
,
[
'/trashcan/'
,
curPath
,
file_name
,
user_id
],
function
(
err
)
{
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
,
curPath
,
user_id
],
function
(
err
)
{
if
(
err
)
{
console
.
log
(
'update db error'
);
res
.
send
({
erorr
:
'db update error'
});
}
else
{
S3
.
moveFile2
(
S3
.
BUCKET_NAME
,
user_id
,
sourceFile
,
file_name
,
targetPath
,
function
(
result
)
{
if
(
result
)
{
res
.
send
(
"move to trashcan success"
);
console
.
log
(
'delete db error'
);
res
.
send
({
erorr
:
'db delete error'
});
}
else
{
//connection.query(sql2, [file_name, '/trashcan'+curPath, user_id], function (err) {
connection
.
query
(
sql2
,
[
file_name
,
'/trashcan/'
,
user_id
],
function
(
err
)
{
if
(
err
)
{
console
.
log
(
'insert in trashcan db error'
);
res
.
send
({
error
:
'db insert error'
});
}
else
{
// /drive/user_id/sourceFile --> /drive/user_id/trashcan/sourceFile
S3
.
moveFile4
(
S3
.
BUCKET_NAME
,
user_id
,
sourceFile
,
targetPath
,
function
(
result
)
{
if
(
result
)
{
res
.
send
({
message
:
"move to trashcan success"
});
}
else
{
res
.
send
({
err
:
"no such file"
})
}
})
}
})
}
})
});
// // /file/delete/:name
// router.get('/:name', function (req, res) {
// var file_name = req.params.name;
// var user_id = req.query.id;
// var curPath = req.query.cur;
// var targetPath = 'trashcan';
// 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, curPath, user_id], function (err) {
// if (err) {
// console.log('delete db error');
// res.send({erorr: 'db delete error'});
// }
// else {
// connection.query(sql2, [file_name, '/trashcan'+curPath, user_id], function (err) {
// if (err) {
// console.log('insert in trashcan db error');
// res.send({error: 'db insert error'});
// }
// else {
// // /drive/user_id/sourceFile --> /drive/user_id/trashcan/sourceFile
// S3.moveFile2(S3.BUCKET_NAME, user_id, sourceFile, targetPath, function (result) {
// if (result) {
// res.send("move to trashcan success");
// }
// })
// }
// })
// }
// })
// });
module
.
exports
=
router
;
\ No newline at end of file
...
...
backend/routes/file/downloadFile.js
View file @
2929790
...
...
@@ -16,6 +16,7 @@ router.get('/:name', function (req, res) {
var
user_id
=
req
.
query
.
id
;
var
targetFile
=
curPath
.
substring
(
1
)
+
file_name
;
// folder1/folder2/test.txt
console
.
log
(
targetFile
);
S3
.
downloadFile3
(
S3
.
BUCKET_NAME
,
user_id
,
targetFile
,
function
(
result
,
downloadDir
)
{
...
...
@@ -29,7 +30,7 @@ router.get('/:name', function (req, res) {
}
})
}
else
{
res
.
send
({
err
:
'
download error
'
})
res
.
send
({
err
:
'
no such file
'
})
}
})
});
...
...
backend/routes/file/files.js
View file @
2929790
...
...
@@ -9,39 +9,38 @@ var fs = require('fs');
// /file
router
.
get
(
'/'
,
function
(
req
,
res
)
{
console
.
log
(
req
.
query
);
router
.
get
(
'/'
,
function
(
req
,
res
)
{
var
user_id
=
req
.
query
.
id
;
var
curPath
=
req
.
query
.
cur
;
// /folder1/folder2/
var
curPath
=
req
.
query
.
cur
;
// /folder1/folder2/
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
{
connection
.
query
(
sql
,
[
user_id
,
curPath
],
function
(
err
,
result
)
{
if
(
err
){
res
.
send
({
error
:
'select error'
});
}
else
{
res
.
status
(
200
).
send
({
files
:
result
});
res
.
status
(
200
).
send
({
files
:
result
});
}
})
});
router
.
get
(
'/:name'
,
function
(
req
,
res
)
{
router
.
get
(
'/:name'
,
function
(
req
,
res
)
{
var
file_name
=
req
.
params
.
name
;
var
curPath
=
req
.
query
.
cur
;
// /folder1/folder2/
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
targetFile
=
curPath
.
substring
(
1
)
+
file_name
;
// folder1/folder2/test.txt
var
extension
=
targetFile
.
split
(
'.'
)[
1
].
toLowerCase
();
S3
.
downloadFile2
(
S3
.
BUCKET_NAME
,
user_id
,
targetFile
,
function
(
result
,
downloadDir
)
{
if
(
result
)
{
S3
.
downloadFile2
(
S3
.
BUCKET_NAME
,
user_id
,
targetFile
,
function
(
result
,
downloadDir
){
if
(
result
){
var
content
;
content
=
fs
.
readFileSync
(
downloadDir
,
'utf8'
);
res
.
send
({
file_name
:
file_name
,
content
:
content
});
res
.
send
({
file_name
:
file_name
,
content
:
content
});
//if (extension == 'jpg' || extension == 'jpeg' || extension == 'png') {
// res.send({ type: 'image', src: downloadDir})
//}else{
...
...
@@ -52,7 +51,7 @@ router.get('/:name', function(req, res) {
//}
}
})
});
});
module
.
exports
=
router
;
\ No newline at end of file
...
...
backend/routes/file/modifyFile.js
View file @
2929790
...
...
@@ -22,7 +22,7 @@ router.post('/:name', function(req, res){
if
(
curPath
==
'/'
)
{
targetPath
=
''
;
}
else
{
targetPath
=
curPath
.
substring
(
1
,
curPa
ht
.
length
-
1
);
// folder1/folder2
targetPath
=
curPath
.
substring
(
1
,
curPa
th
.
length
-
1
);
// folder1/folder2
}
var
originalDir
=
__dirname
+
'/../modules/s3/download/'
+
user_id
+
curPath
+
file_name
;
...
...
@@ -50,7 +50,7 @@ router.post('/:name', function(req, res){
res
.
send
({
error
:
'update error'
});
}
else
{
fs
.
unlinkSync
(
tempDownloadDir
);
res
.
send
(
'modify file success'
);
res
.
send
(
{
message
:
'modify file success'
}
);
}
})
}
else
{
...
...
backend/routes/modules/s3/s3.js
View file @
2929790
...
...
@@ -16,7 +16,7 @@
var
AWS
=
require
(
'aws-sdk'
);
AWS
.
config
.
update
({
region
:
'ap-northeast-2'
});
var
BUCKET_NAME
=
'
qkrrlqja-test
'
;
var
BUCKET_NAME
=
'
khuloud
'
;
var
s3
=
new
AWS
.
S3
();
var
fs
=
require
(
'fs'
);
...
...
Please
register
or
login
to post a comment