deplacer file et folder

anis
Tmadkaud 6 years ago
parent 147a1d4d7d
commit 3c305686c1

@ -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);
}
});
}));
};

@ -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);
});

@ -57,6 +57,14 @@
<button type="button" class="btn btn-sm btn-warning" mdbTooltip="Supprimer : {{folder.name}}" placement="top" (click)="deleteFolder(folder)"><i class="fa fa-close" aria-hidden="true"></i></button>
<button type="button" class="btn btn-sm btn-warning" mdbTooltip="Ouvrir : {{folder.name}}" placement="top" (click)="openFolder(folder.path)"><i class="fa fa-folder-open-o" aria-hidden="true"></i></button>
<!--<button type="button" class="btn btn-warning" (click)="renameFolder(folder)">Rename</button>-->
<div class="btn-group" dropdown>
<button type="button" dropdownToggle class="btn btn-success btn-sm dropdown-toggle-split px-3 waves-light" mdbTooltip="Déplacer : {{folder.name}}" placement="top" mdbWavesEffect>
<i class="fa fa-arrows" aria-hidden="true"></i>
</button>
<div class="dropdown-menu">
<a class="dropdown-item" *ngFor="let folderDest of allUserAppFolder; let i = index;" (click)="moveFolder(folder, folderDest)">{{folderDest.name}}</a>
</div>
</div>
</td>
<td>
@ -80,6 +88,15 @@
<i class="fa fa-download" aria-hidden="true"></i>
</button>
</a>
<div class="btn-group" dropdown>
<button type="button" dropdownToggle class="btn btn-success btn-sm dropdown-toggle-split px-3 waves-light" mdbTooltip="Déplacer : {{file.name}}" placement="top" mdbWavesEffect>
<i class="fa fa-arrows" aria-hidden="true"></i>
</button>
<div class="dropdown-menu">
<a class="dropdown-item" *ngFor="let folder of allUserAppFolder; let i = index;" (click)="moveFile(file, folder)">{{folder.name}}</a>
</div>
</div>
</td>
<td>
<button class="btn btn-primary btn-sm waves-light" mdbTooltip="Renommer : {{file.name}}" placement="top" type="button" mdbWavesEffect (click)="renameFile(file)">
@ -88,6 +105,9 @@
<input type="search" class="form-control col-xs-2" placeholder= "{{file.name}}" [(ngModel)]="file.name">
</td>
<!--<td>{{ file.name }}</td>-->
<td>{{ file.taille / ( 1024 * 1024 ) | number : '1.2-2'}} Mo</td>
<td>{{ file.type }}</td>

@ -25,6 +25,7 @@ export class BookComponent implements OnInit, OnDestroy {
currentUser: any;
allUserFile: any;
allUserFolder: any;
allUserAppFolder: any;
mainFolder: any;
books: any;
filesToUpload: Array<File>;
@ -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);
});

Loading…
Cancel
Save