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 @@
+
+
+
+
+
|
|
+
+
+
{{ file.taille / ( 1024 * 1024 ) | number : '1.2-2'}} Mo |
{{ file.type }} |
diff --git a/src/app/book/book.component.ts b/src/app/book/book.component.ts
index 7864461..bc2e7f5 100644
--- a/src/app/book/book.component.ts
+++ b/src/app/book/book.component.ts
@@ -25,6 +25,7 @@ export class BookComponent implements OnInit, OnDestroy {
currentUser: any;
allUserFile: any;
allUserFolder: any;
+ allUserAppFolder: any;
mainFolder: any;
books: any;
filesToUpload: Array;
@@ -61,27 +62,6 @@ export class BookComponent implements OnInit, OnDestroy {
this.fileChooseName = 'None';
this.filesToUpload = [];
this.test = '';
-
-/*
- if(document){
- var myDropzone = new Dropzone('div#madrop', { url: '../../../public/'});
- // "myAwesomeDropzone" is the camelized version of the HTML element's ID
- myDropzone.options.madrop = {
- paramName: "file", // The name that will be used to transfer the file
- maxFilesize: 2, // MB
- accept: function(file, done) {
- console.log('Naha, you don\'t.');
-
- if (file.name == "justinbieber.jpg") {
- console.log('Naha, you don\'t.');
- done('Naha, you don\'t.');
- }
- else { console.log('done();') }
- }
- };
- }
-
-*/
}
public toggleType(): void {
@@ -119,19 +99,18 @@ export class BookComponent implements OnInit, OnDestroy {
}
public onUploadSuccess(args: any): void {
- console.log('onUploadSuccess:', JSON.stringify(args[0]));
this.filesToUpload = args;
this.fileChooseName = args[0].name;
- console.log('this.fileChooseName:', this.fileChooseName);
this.upload();
this.resetDropzoneUploads();
this.openFolder(this.mainFolder.path);
}
+
ngOnInit() {
this.httpOptions = {
- headers: new HttpHeaders({ 'Authorization': localStorage.getItem('jwtToken') }),
+ headers: new HttpHeaders({ 'Authorization': localStorage.getItem('jwtToken'), 'Access-Control-Allow-Origin' : '*'}),
pathFolder: ''
};
@@ -194,17 +173,11 @@ export class BookComponent implements OnInit, OnDestroy {
this.allUserFile = files;
for (let f of this.allUserFile) {
if(f.type === ('image/jpeg') || f.type === ('image/png')){
- console.log('f : ' + JSON.stringify(f));
f.data = f.url;
- console.log('f.url : ' + f.url);
f.urlSafe = this.sanitizer.bypassSecurityTrustUrl(f.url);
- console.log('f.urlSafe : ' + JSON.stringify(f.urlSafe));
}else{
- console.log('f : ' + JSON.stringify(f));
f.data = f.url;
- console.log('f.url : ' + f.url);
f.urlSafe = this.sanitizer.bypassSecurityTrustResourceUrl(f.url);
- console.log('f.urlSafe : ' + JSON.stringify(f.urlSafe));
}
}
@@ -223,6 +196,41 @@ export class BookComponent implements OnInit, OnDestroy {
}
});
}
+ getAllUserAppFolder(){
+ this.http.post('/api/getFolderAppList', {owner: this.currentUser.username.toString()}).subscribe(folders => {
+ if (folders) {
+ this.allUserAppFolder = folders;
+ } else {
+ this.allUserAppFolder = [];
+ }
+ });
+ }
+
+ moveFile(fileToMove, folderDest){
+ fileToMove.path = folderDest.path;
+
+ this.http.post('/api/moveFile', fileToMove).subscribe(data => {
+ console.log('data : ' + data);
+ this.getfiles();
+ //this.openFolder(this.mainFolder.path)
+ // this.getAllUserAppFolder();
+ // this.getfiles();
+ });
+ }
+
+ moveFolder(folderToMove, folderDest){
+ var newPath = folderDest.path + '/' + folderToMove.parent.name;
+ folderToMove.path = newPath;
+ folderToMove.parent = folderDest.path;
+
+ this.http.post('/api/moveFolder', folderToMove).subscribe(data => {
+ console.log('data : ' + data);
+ this.getfolders();
+ //this.openFolder(this.mainFolder.path)
+ // this.getAllUserAppFolder();
+ // this.getfiles();
+ });
+ }
backToParentFolder(){
this.openFolder(this.mainFolder.parent);
@@ -238,6 +246,7 @@ export class BookComponent implements OnInit, OnDestroy {
if (folder) {
this.mainFolder = folder;
this.getfolders();
+ this.getAllUserAppFolder();
this.getfiles();
} else {
@@ -262,6 +271,7 @@ export class BookComponent implements OnInit, OnDestroy {
this.http.post('api/createFolder', { name: this.inputCreateFolder.toString(), parent: this.mainFolder.path, path: newPath.toString(), taille: 'taiile', idUser: this.currentUser._id.toString(), fileList: [], folderList: [], owner: this.currentUser.username.toString() }).subscribe(resp => {
this.getfolders();
+ this.getAllUserAppFolder();
}, err => {
console.log('errrrr folllder : ' + err);
});