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
Hong
2020-06-10 14:32:11 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
0a2cb87ad8fd818a63bbb0d4f09884d23208fbda
0a2cb87a
1 parent
d4983bd1
휴지통
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
190 additions
and
66 deletions
backend/routes/file/deleteFile.js
backend/routes/file/files.js
backend/routes/folders.js
backend/routes/trashcan.js
backend/routes/file/deleteFile.js
View file @
0a2cb87
...
...
@@ -7,7 +7,9 @@ var S3 = require('../modules/s3/s3');
// /file/delete/:name
router
.
get
(
'/:name'
,
function
(
req
,
res
)
{
router
.
get
(
'/:name'
,
function
(
req
,
res
)
{
console
.
log
(
req
.
query
);
console
.
log
(
req
.
params
);
var
file_name
=
req
.
params
.
name
;
var
user_id
=
req
.
query
.
id
;
var
curPath
=
req
.
query
.
cur
;
...
...
@@ -15,32 +17,56 @@ router.get('/:name', function (req, res) {
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
)
{
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
)
{
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
)
{
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"
);
}
})
}
})
}
})
});
// // /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/files.js
View file @
0a2cb87
...
...
@@ -9,24 +9,25 @@ var fs = require('fs');
// /file
router
.
get
(
'/'
,
function
(
req
,
res
)
{
router
.
get
(
'/'
,
function
(
req
,
res
)
{
console
.
log
(
req
.
query
);
var
user_id
=
req
.
query
.
id
;
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
user_id
=
req
.
query
.
id
;
...
...
@@ -35,11 +36,11 @@ router.get('/:name', function (req, res) {
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})
...
...
backend/routes/folders.js
View file @
0a2cb87
...
...
@@ -160,63 +160,59 @@ router.post('/makefolder', function(req, res, next) {
router
.
post
(
'/delfolder'
,
function
(
req
,
res
,
next
)
{
console
.
log
(
req
.
body
);
user_id
=
req
.
body
.
id
;
let
cur
=
req
.
body
.
cur
;
curPath
=
user_id
+
cur
;
let
folder_name
=
req
.
body
.
folder_name
;
let
params
=
{
let
name
=
req
.
body
.
folder_name
;
let
newPath
=
user_id
+
'/trashcan/'
;
let
checkfolder
=
'SELECT * FROM folders WHERE location = ? AND folder_name = ? AND user_id = ?;'
;
connection
.
query
(
checkfolder
,
[
cur
,
name
,
user_id
],
function
(
err1
,
rows
,
fields
)
{
console
.
log
(
rows
);
if
(
rows
.
length
!=
0
)
{
let
copy_params
=
{
Bucket
:
BUCKET_NAME
,
Key
:
'drive/'
+
curPath
+
folder_name
+
'/'
CopySource
:
BUCKET_NAME
+
'/drive/'
+
curPath
+
name
+
'/'
,
Key
:
'drive/'
+
newPath
+
name
+
'/'
};
let
infolderpath
=
cur
+
folder_name
+
'/'
;
let
checkinfolder
=
'SELECT location FROM folders WHERE location = ? AND user_id = ? UNION ALL SELECT location FROM files WHERE location = ? AND user_id = ?;'
;
connection
.
query
(
checkinfolder
,
[
infolderpath
,
user_id
,
infolderpath
,
user_id
],
function
(
err
,
infolder
)
{
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
:
"checkinfolder error"
});
}
else
{
if
(
infolder
.
length
!=
0
)
{
res
.
status
(
204
).
send
({
error
:
"infolder exist!"
})
}
else
{
let
checksql
=
'SELECT * FROM folders WHERE location = ? AND folder_name = ? AND user_id = ?;'
;
let
values
=
[
cur
,
folder_name
,
user_id
];
connection
.
query
(
checksql
,
values
,
function
(
err
,
rows
,
fields
)
{
if
(
err
)
{
res
.
status
(
404
).
send
({
error
:
"error"
});
res
.
status
(
304
).
send
({
error
:
"copy error"
});
}
else
{
if
(
rows
.
length
!=
0
)
{
s3
.
deleteObject
(
params
,
function
(
err
,
data
)
{
s3
.
deleteObject
(
del_params
,
function
(
err
,
data
)
{
if
(
err
)
{
console
.
log
(
's3 error'
);
res
.
status
(
400
).
send
({
err
:
err
});
console
.
log
(
err
,
data
);
console
.
log
(
"delete error"
);
res
.
status
(
304
).
send
({
error
:
"delete error"
});
}
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
)
{
res
.
status
(
400
).
send
({
err
:
err
});
let
values
=
[
'/trashcan/'
,
cur
,
name
,
user_id
];
let
updatesql
=
'UPDATE folders SET location = ? WHERE location = ? AND folder_name = ? AND user_id = ?;'
;
connection
.
query
(
updatesql
,
values
,
function
(
err3
,
result
,
field
)
{
if
(
err3
)
{
console
.
log
(
"updatesql error"
);
res
.
status
(
304
).
send
({
error
:
"updatesql error"
});
}
else
{
console
.
log
(
cur
);
console
.
log
(
user_id
);
let
checkfolder
=
'SELECT * FROM folders WHERE location = ? AND user_id = ?;'
;
connection
.
query
(
checkfolder
,
[
cur
,
user_id
],
function
(
err
,
rows
,
fields
)
{
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
{
console
.
log
(
req
.
body
);
res
.
status
(
304
).
send
({
error
:
"Does not exist"
});
}
}
});
}
});
}
else
{
console
.
log
(
"Does not exist folder"
);
res
.
status
(
304
).
send
({
error
:
"Does not exist"
});
}
});
});
...
...
backend/routes/trashcan.js
0 → 100644
View file @
0a2cb87
const
express
=
require
(
'express'
);
const
router
=
express
.
Router
();
const
AWS
=
require
(
"aws-sdk"
);
const
moment
=
require
(
"moment"
);
AWS
.
config
.
loadFromPath
(
__dirname
+
"/modules/awsconfig.json"
);
var
S3
=
require
(
'../modules/s3/s3'
);
router
.
get
(
'/delfile'
,
function
(
req
,
res
,
next
)
{
var
file_id
=
req
.
query
.
file_id
;
var
user_id
=
req
.
query
.
id
;
var
getsql
=
'SELECT * FROM files WHERE file_id = (?)'
;
connection
.
query
(
getsql
,
[
file_id
],
function
(
err
,
rows
)
{
if
(
err
)
{
console
.
log
(
'select db error'
);
res
.
send
({
erorr
:
'db select error'
});
}
else
{
if
(
rows
.
length
==
0
)
{
console
.
log
(
'exist error'
);
res
.
send
({
erorr
:
'exist error'
});
}
else
{
var
curPath
=
rows
[
0
].
location
;
var
file_name
=
rows
[
0
].
file_name
;
var
sourceFile
=
curPath
.
substring
(
1
)
+
file_name
;
var
sql1
=
'DELETE FROM files WHERE file_name = (?) AND location=(?) AND user_Id = (?)'
;
connection
.
query
(
sql1
,
[
file_name
,
curPath
,
user_id
],
function
(
err
)
{
if
(
err
)
{
console
.
log
(
'delete db error'
);
res
.
send
({
erorr
:
'db delete error'
});
}
else
{
S3
.
deleteFile
(
S3
.
BUCKET_NAME
,
user_id
,
sourceFile
,
function
(
result
)
{
if
(
result
)
{
let
checkfile
=
'SELECT * FROM files WHERE location = ? AND user_id = ?;'
;
connection
.
query
(
checkfile
,
[
'/trashcan/'
,
user_id
],
function
(
err
,
file
)
{
res
.
status
(
200
).
send
({
files
:
file
})
});
}
})
}
})
}
}
})
});
router
.
get
(
'/delfolder'
,
function
(
req
,
res
,
next
)
{
var
folder_id
=
req
.
query
.
folder_id
;
var
user_id
=
req
.
query
.
id
;
var
getsql
=
'SELECT * FROM folders WHERE folder_id = (?)'
;
connection
.
query
(
getsql
,
[
folder_id
],
function
(
err
,
rows
)
{
if
(
err
)
{
console
.
log
(
'select db error'
);
res
.
send
({
erorr
:
'db select error'
});
}
else
{
if
(
rows
.
length
==
0
)
{
console
.
log
(
'exist error'
);
res
.
send
({
erorr
:
'exist error'
});
}
else
{
var
curPath
=
'/trashcan/'
var
folder_name
=
rows
[
0
].
folder_name
;
var
sourcefolder
=
curPath
.
substring
(
1
)
+
folder_name
+
'/'
;
var
sql1
=
'DELETE FROM folders WHERE folder_name = (?) AND location=(?) AND user_Id = (?)'
;
connection
.
query
(
sql1
,
[
folder_name
,
curPath
,
user_id
],
function
(
err
)
{
if
(
err
)
{
console
.
log
(
'delete db error'
);
res
.
send
({
erorr
:
'db delete error'
});
}
else
{
var
params
=
{
Bucket
:
S3
.
BUCKET_NAME
,
Key
:
'drive/'
+
user_id
+
curPath
+
folder_name
+
'/'
};
s3
.
deleteObject
(
params
,
function
(
err
,
data
)
{
if
(
err
)
{
res
.
status
(
400
).
send
({
err
:
err
});
}
else
{
let
checkfolder
=
'SELECT * FROM folders WHERE location = ? AND user_id = ?;'
;
connection
.
query
(
checkfolder
,
[
curPath
,
user_id
],
function
(
err
,
rows
)
{
res
.
status
(
200
).
send
({
folders
:
rows
})
});
}
})
}
})
}
}
})
});
module
.
exports
=
router
;
\ No newline at end of file
Please
register
or
login
to post a comment