From 3c305686c158936cf57e21ce96e730273a09bf39 Mon Sep 17 00:00:00 2001 From: Tmadkaud Date: Sat, 19 May 2018 15:08:00 +0200 Subject: [PATCH] deplacer file et folder --- config/passport.js | 6 +++ routes/api.js | 43 +++++++++++++++++--- src/app/book/book.component.html | 20 +++++++++ src/app/book/book.component.ts | 70 ++++++++++++++++++-------------- 4 files changed, 103 insertions(+), 36 deletions(-) diff --git a/config/passport.js b/config/passport.js index 84f263d..460c516 100644 --- a/config/passport.js +++ b/config/passport.js @@ -9,6 +9,8 @@ module.exports = function(passport) { var opts = {}; opts.jwtFromRequest = ExtractJwt.fromAuthHeaderWithScheme("jwt"); opts.secretOrKey = config.secret; + + passport.use(new JwtStrategy(opts, function(jwt_payload, done) { User.findOne({id: jwt_payload.id, username: jwt_payload.username}, function(err, user) { @@ -24,5 +26,9 @@ module.exports = function(passport) { done(null, false); } }); + + + + })); }; diff --git a/routes/api.js b/routes/api.js index 45ae823..e71a083 100644 --- a/routes/api.js +++ b/routes/api.js @@ -82,8 +82,6 @@ router.post('/uploadFileMongo', function(req, res, next) { /* SAVE URL FILE */ router.post('/saveURLFileMongo', function(req, res, next) { - console.log("New File data req.body", JSON.stringify(req.body)); - FileMongo.findOneAndUpdate({_id : req.body._id, owner: req.body.owner}, {url: req.body.url},{new: true}).then((data) =>{ if(data === null){ throw new Error('File Not Found'); @@ -144,12 +142,37 @@ router.post('/renameFolderMongo', function(req, res, next) { }); }); +/* Move Folder */ +router.post('/moveFolder', function(req, res, next) { + FolderMongo.findOneAndUpdate({_id : req.body._id, owner: req.body.owner}, {path: req.body.path, parent: req.body.parent},{new: true}).then((data) =>{ + if(data === null){ + throw new Error('Folder Not Found'); + } + res.json({ message: 'Folder updated!' }); + }).catch( (error) => { + //Deal with all your errors here with your preferred error handle middleware / method + res.status(500).json({ message: 'Some Error!' }); + console.log(error); + }); +}); + +/* Move File */ +router.post('/moveFile', function(req, res, next) { + FileMongo.findOneAndUpdate({_id : req.body._id, owner: req.body.owner}, {path: req.body.path},{new: true}).then((data) =>{ + if(data === null){ + throw new Error('File Not Found'); + } + res.json({ message: 'File updated!' }); + }).catch( (error) => { + //Deal with all your errors here with your preferred error handle middleware / method + res.status(500).json({ message: 'Some Error!' }); + console.log(error); + }); +}); /* Rename FILE */ router.post('/renameFileMongo', function(req, res, next) { - console.log("New File data req.body", JSON.stringify(req.body)); - FileMongo.findOneAndUpdate({_id : req.body._id, owner: req.body.owner}, {name: req.body.name},{new: true}).then((data) =>{ if(data === null){ throw new Error('File Not Found'); @@ -184,6 +207,15 @@ router.post('/getFolderList', function(req, res) { }); +/* Get tout les folders du user */ +router.post('/getFolderAppList', function(req, res) { + FolderMongo.find({ + owner: req.body.owner + }, function(err, folder) { + res.json(folder); + }); +}); + /* Get tout les files du mainFolder */ router.post('/getFileList', function(req, res) { FileMongo.find({ @@ -208,7 +240,7 @@ router.post('/signin', function(req, res) { // check if password matches user.comparePassword(req.body.password, function (err, isMatch) { if (isMatch && !err) { - console.log('req.user.username logggggg ::: ' + JSON.stringify(user)); + console.log('req.user.username log : ' + JSON.stringify(user)); // if user is found and password is right create a token var token = jwt.sign(user.toJSON(), config.secret); // return the information including token as JSON @@ -224,7 +256,6 @@ router.post('/signin', function(req, res) { /* Multer upload */ router.post('/upload' , multer({storage: storage, limits: {fileSize: 30000000000}}).array("public[]", 12) ,function(req,res,next){ - console.log('bebeb : ' + JSON.stringify(req)); res.send(req.files); }); diff --git a/src/app/book/book.component.html b/src/app/book/book.component.html index 0661259..994c873 100644 --- a/src/app/book/book.component.html +++ b/src/app/book/book.component.html @@ -57,6 +57,14 @@ +
+ + +
@@ -80,6 +88,15 @@ + +
+ + +