|
|
|
@ -16,88 +16,123 @@ import * as formData from 'form-data';
|
|
|
|
|
export class BookComponent implements OnInit, OnDestroy {
|
|
|
|
|
currentUser: any;
|
|
|
|
|
allUserFile: any;
|
|
|
|
|
allUserFolder: any;
|
|
|
|
|
mainFolder: any;
|
|
|
|
|
books: any;
|
|
|
|
|
filesToUpload: Array<File>;
|
|
|
|
|
fileChooseName: string;
|
|
|
|
|
httpOptions: any;
|
|
|
|
|
// tokenFromLogin: any;
|
|
|
|
|
constructor(private http: HttpClient, private router: Router, private route: ActivatedRoute) {
|
|
|
|
|
isClickCreateFolder: boolean;
|
|
|
|
|
inputCreateFolder: String;
|
|
|
|
|
|
|
|
|
|
constructor(private http: HttpClient, private router: Router, private route: ActivatedRoute) {
|
|
|
|
|
this.isClickCreateFolder = false;
|
|
|
|
|
this.fileChooseName = 'None';
|
|
|
|
|
this.filesToUpload = [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
|
|
|
|
|
|
this.route.params.subscribe(params => {
|
|
|
|
|
// this.tokenFromLogin = params['tokenFromLogin'];
|
|
|
|
|
|
|
|
|
|
this.httpOptions = {
|
|
|
|
|
headers: new HttpHeaders({ 'Authorization': localStorage.getItem('jwtToken') })
|
|
|
|
|
headers: new HttpHeaders({ 'Authorization': localStorage.getItem('jwtToken') }),
|
|
|
|
|
pathFolder: ''
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
this.http.get('/api/book', this.httpOptions).subscribe(user => {
|
|
|
|
|
this.http.get('/api/getCurrentUser', this.httpOptions).subscribe(user => {
|
|
|
|
|
this.currentUser = user;
|
|
|
|
|
console.log('mothafuka cureent user : ' + JSON.stringify(this.currentUser));
|
|
|
|
|
this.openFolder('Home');
|
|
|
|
|
}, err => {
|
|
|
|
|
if (err.status === 401) {
|
|
|
|
|
this.router.navigate(['login']);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
this.getfile();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getfiles() {
|
|
|
|
|
this.http.post('/api/getFileList', {mainPath : this.mainFolder.path, owner: this.currentUser.username.toString()}).subscribe(files => {
|
|
|
|
|
if (files) {
|
|
|
|
|
this.allUserFile = files;
|
|
|
|
|
} else {
|
|
|
|
|
this.allUserFile = [];
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
getfile() {
|
|
|
|
|
this.http.get('/api/allUserFile', this.httpOptions).subscribe(files => {
|
|
|
|
|
this.allUserFile = files;
|
|
|
|
|
console.log('mothafuka cureent user : ' + JSON.stringify(this.allUserFile));
|
|
|
|
|
}, err => {
|
|
|
|
|
if (err.status === 401) {
|
|
|
|
|
this.router.navigate(['login']);
|
|
|
|
|
|
|
|
|
|
getfolders() {
|
|
|
|
|
this.http.post('/api/getFolderList', {mainPath : this.mainFolder.path, owner: this.currentUser.username.toString()}).subscribe(folders => {
|
|
|
|
|
if (folders) {
|
|
|
|
|
this.allUserFolder = folders;
|
|
|
|
|
} else {
|
|
|
|
|
this.allUserFolder = [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
ngOnDestroy() {
|
|
|
|
|
localStorage.removeItem('jwtToken');
|
|
|
|
|
// this.tokenFromLogin = '';
|
|
|
|
|
this.httpOptions = null;
|
|
|
|
|
this.currentUser = null;
|
|
|
|
|
|
|
|
|
|
backToParentFolder(){
|
|
|
|
|
this.openFolder(this.mainFolder.parent);
|
|
|
|
|
}
|
|
|
|
|
upload() {
|
|
|
|
|
|
|
|
|
|
this.makeFileRequest('http://localhost:3000/api/upload', [], this.filesToUpload).then((result) => {
|
|
|
|
|
// var source = 'http://localhost:3000/public/'+result[0].filename;
|
|
|
|
|
console.log('current USer Filleeee ::: '+ JSON.stringify(this.currentUser));
|
|
|
|
|
var fileUploadData = { uid: '222', name:result[0].filename.toString(), path: result[0].path.toString(), extention:this.filesToUpload[0].type.toString(), taille:this.filesToUpload[0].size.toString(), idUser: this.currentUser.id };
|
|
|
|
|
var message = '';
|
|
|
|
|
//console.log('mothafukaaaaaaaaaaa : ' + JSON.stringify(this.currentUser));
|
|
|
|
|
//console.log('mothafukaaaaaaaaaaa : ' + this.currentUser._id);
|
|
|
|
|
console.log('avaaaaanttttt : ' + this.currentUser.username.toString() + ' ---- ' + this.currentUser._id.toString());
|
|
|
|
|
console.log('lastModifiedDateee : ' + this.filesToUpload[0].lastModifiedDate.toString());
|
|
|
|
|
// if(this.currentUser.username)
|
|
|
|
|
this.http.post('api/uploadFileMongo', { name: result[0].filename.toString(), path: result[0].path.toString(), extention: this.filesToUpload[0].type.toString(), taille: this.filesToUpload[0].size.toString(), idUser: this.currentUser._id.toString(), owner: this.currentUser.username.toString(), lastDate: this.filesToUpload[0].lastModifiedDate.toString() }).subscribe(resp => {
|
|
|
|
|
console.log('ok db !!' + resp.toString());
|
|
|
|
|
this.getfile();
|
|
|
|
|
this.filesToUpload = null;
|
|
|
|
|
this.fileChooseName = 'None';
|
|
|
|
|
|
|
|
|
|
openFolder(path: String) {
|
|
|
|
|
this.httpOptions.pathFolder = path;
|
|
|
|
|
|
|
|
|
|
this.isClickCreateFolder = false;
|
|
|
|
|
|
|
|
|
|
this.http.post('/api/getMainFolder', {path: path, owner: this.currentUser.username.toString()}).subscribe(folder => {
|
|
|
|
|
if (folder) {
|
|
|
|
|
this.mainFolder = folder;
|
|
|
|
|
this.getfolders();
|
|
|
|
|
this.getfiles();
|
|
|
|
|
} else {
|
|
|
|
|
if (path === 'Home'){
|
|
|
|
|
this.http.post('api/createFolder', { name: 'Home', parent: '', path: 'Home', taille: 'taiile', idUser: this.currentUser._id.toString(), fileList: [], folderList: [], owner: this.currentUser.username.toString() }).subscribe(resp => {
|
|
|
|
|
this.mainFolder = resp;
|
|
|
|
|
}, err => {
|
|
|
|
|
console.log('errrrr folllder : ' + err);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
createBool() {
|
|
|
|
|
this.isClickCreateFolder = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
createFolder() {
|
|
|
|
|
var newPath = this.mainFolder.path + '/' + this.inputCreateFolder;
|
|
|
|
|
this.isClickCreateFolder = false;
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}, err => {
|
|
|
|
|
console.log('errrrr : ' + err);
|
|
|
|
|
message = err.error.msg;
|
|
|
|
|
console.log('errrrr folllder : ' + err);
|
|
|
|
|
});
|
|
|
|
|
console.log('apres');
|
|
|
|
|
console.log('fileUploadData: ' + fileUploadData);
|
|
|
|
|
console.log('fileUploadData.path: ' + fileUploadData.path);
|
|
|
|
|
console.log('fileUploadData.name: ' + fileUploadData.name);
|
|
|
|
|
console.log('fileUploadData.taille: ' + fileUploadData.taille);
|
|
|
|
|
console.log('fileUploadData.extention: ' + fileUploadData.extention);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log('result: ' + result[0].filename);
|
|
|
|
|
ngOnDestroy() {
|
|
|
|
|
localStorage.removeItem('jwtToken');
|
|
|
|
|
this.httpOptions = null;
|
|
|
|
|
this.currentUser = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
upload() {
|
|
|
|
|
if(this.mainFolder !== undefined){
|
|
|
|
|
this.http.post('api/uploadFileMongo', { name: this.fileChooseName.toString(), path: this.mainFolder.path.toString(), extention: this.filesToUpload[0].type.toString(), taille: this.filesToUpload[0].size.toString(), idUser: this.currentUser._id.toString(), owner: this.currentUser.username.toString(), lastDate: Date.now().toString() }).subscribe(resp => {
|
|
|
|
|
this.makeFileRequest('http://localhost:3000/api/upload', [], this.filesToUpload, resp).then((result) => {
|
|
|
|
|
this.getfiles();
|
|
|
|
|
this.filesToUpload = null;
|
|
|
|
|
this.fileChooseName = 'None';
|
|
|
|
|
}, (error) => {
|
|
|
|
|
console.error(error);
|
|
|
|
|
});
|
|
|
|
|
}, err => {
|
|
|
|
|
console.error(err);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}, (error) => {
|
|
|
|
|
console.error(error);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fileChangeEvent(fileInput: any){
|
|
|
|
@ -105,12 +140,12 @@ export class BookComponent implements OnInit, OnDestroy {
|
|
|
|
|
this.fileChooseName = this.filesToUpload[0].name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
makeFileRequest(url: string, params: Array<string>, files: Array<File>) {
|
|
|
|
|
makeFileRequest(url: string, params: Array<string>, files: Array<File>, monFile: any) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
var formData: any = new FormData();
|
|
|
|
|
var xhr = new XMLHttpRequest();
|
|
|
|
|
|
|
|
|
|
formData.append("public[]", files[0], files[0].name);
|
|
|
|
|
formData.append("public[]", files[0], monFile._id);
|
|
|
|
|
xhr.onreadystatechange = function () {
|
|
|
|
|
if (xhr.readyState == 4) {
|
|
|
|
|
if (xhr.status == 200) {
|
|
|
|
@ -126,10 +161,4 @@ export class BookComponent implements OnInit, OnDestroy {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
logout() {
|
|
|
|
|
this.httpOptions = null;
|
|
|
|
|
localStorage.removeItem('jwtToken');
|
|
|
|
|
this.router.navigate(['login']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|