|
|
|
@ -9,6 +9,7 @@ import {Form} from "@angular/forms";
|
|
|
|
|
import * as formData from 'form-data';
|
|
|
|
|
import {forEach} from '@angular/router/src/utils/collection';
|
|
|
|
|
import {type} from 'os';
|
|
|
|
|
import { DomSanitizer } from '@angular/platform-browser';
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-book',
|
|
|
|
@ -28,7 +29,7 @@ export class BookComponent implements OnInit, OnDestroy {
|
|
|
|
|
inputCreateFolder: String;
|
|
|
|
|
reader: FileReader;
|
|
|
|
|
test: String;
|
|
|
|
|
constructor(private http: HttpClient, private router: Router, private route: ActivatedRoute) {
|
|
|
|
|
constructor(private http: HttpClient, private router: Router, private route: ActivatedRoute, public sanitizer: DomSanitizer) {
|
|
|
|
|
this.isClickCreateFolder = false;
|
|
|
|
|
this.fileChooseName = 'None';
|
|
|
|
|
this.filesToUpload = [];
|
|
|
|
@ -77,6 +78,14 @@ export class BookComponent implements OnInit, OnDestroy {
|
|
|
|
|
console.log('data : ' + data);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
saveURLFileMongo(fileToCreateURL){
|
|
|
|
|
fileToCreateURL.url = '../../../public/' + fileToCreateURL._id.toString() + this.getStringExtention(fileToCreateURL);
|
|
|
|
|
|
|
|
|
|
this.http.post('/api/saveURLFileMongo', fileToCreateURL).subscribe(data => {
|
|
|
|
|
console.log('data : ' + data);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getfiles() {
|
|
|
|
|
//var preview = document.querySelector('img');
|
|
|
|
@ -86,46 +95,13 @@ export class BookComponent implements OnInit, OnDestroy {
|
|
|
|
|
|
|
|
|
|
this.http.post('/api/getFileList', {mainPath : this.mainFolder.path, owner: this.currentUser.username.toString()}).subscribe(files => {
|
|
|
|
|
if (files) {
|
|
|
|
|
// this.allUserFile = files;
|
|
|
|
|
|
|
|
|
|
this.allUserFile = files;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// for (let f of this.allUserFile) {
|
|
|
|
|
//
|
|
|
|
|
// console.log('f.type : ' + f.type);
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// /*
|
|
|
|
|
// var textFileAsBlob = new Blob([f.blob], {
|
|
|
|
|
// type: 'text/plain'
|
|
|
|
|
// });*/
|
|
|
|
|
//
|
|
|
|
|
// if (f.type === ('text/plain')) {
|
|
|
|
|
// JSON.stringify(f);
|
|
|
|
|
// //f.function( fii => {
|
|
|
|
|
// this.reader = new FileReader();
|
|
|
|
|
// var ff = new Blob([JSON.stringify(f, null, 2)], {type: 'text/plain'})
|
|
|
|
|
// var me = this;
|
|
|
|
|
// this.reader.onload = function(e:any) {
|
|
|
|
|
// me.test = e.target.result;
|
|
|
|
|
// console.log('meee.test : ' + JSON.stringify(e.target.result));
|
|
|
|
|
// };
|
|
|
|
|
// //ff.type = f.type;
|
|
|
|
|
// //ff.size = f.taille;
|
|
|
|
|
// //ff.slice(f);
|
|
|
|
|
// var gugu = new File(('../../../public/' + f._id)[], f.name);
|
|
|
|
|
// this.reader.readAsText('../../../public/' + f._id.toString(), f.name);
|
|
|
|
|
//
|
|
|
|
|
// //console.log('couilles : ' + meee.reader.readAsText(fii));
|
|
|
|
|
//
|
|
|
|
|
// //console.log('couilles : ' + JSON.stringify(f));
|
|
|
|
|
// //});
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
this.allUserFile = files;
|
|
|
|
|
for (let f of this.allUserFile) {
|
|
|
|
|
f.data = f.url;
|
|
|
|
|
f.url = this.sanitizer.bypassSecurityTrustResourceUrl(f.url);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
this.allUserFile = [];
|
|
|
|
|
}
|
|
|
|
@ -157,6 +133,7 @@ export class BookComponent implements OnInit, OnDestroy {
|
|
|
|
|
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 => {
|
|
|
|
@ -192,7 +169,8 @@ export class BookComponent implements OnInit, OnDestroy {
|
|
|
|
|
|
|
|
|
|
upload() {
|
|
|
|
|
if(this.mainFolder !== undefined){
|
|
|
|
|
this.http.post('api/uploadFileMongo', { name: this.fileChooseName.toString(), path: this.mainFolder.path.toString(), type: 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(), data: ''}).subscribe(resp => {
|
|
|
|
|
this.http.post('api/uploadFileMongo', { name: this.fileChooseName.toString(), path: this.mainFolder.path.toString(), type: 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(), url: ''}).subscribe(resp => {
|
|
|
|
|
this.saveURLFileMongo(resp);
|
|
|
|
|
this.makeFileRequest('http://localhost:3000/api/upload', [], this.filesToUpload, resp).then((result) => {
|
|
|
|
|
this.getfiles();
|
|
|
|
|
this.filesToUpload = null;
|
|
|
|
@ -216,7 +194,7 @@ export class BookComponent implements OnInit, OnDestroy {
|
|
|
|
|
var formData: any = new FormData();
|
|
|
|
|
var xhr = new XMLHttpRequest();
|
|
|
|
|
|
|
|
|
|
formData.append("public[]", files[0], monFile._id);
|
|
|
|
|
formData.append("public[]", files[0], monFile._id + this.getStringExtention(monFile));
|
|
|
|
|
xhr.onreadystatechange = function () {
|
|
|
|
|
if (xhr.readyState == 4) {
|
|
|
|
|
if (xhr.status == 200) {
|
|
|
|
@ -232,4 +210,10 @@ export class BookComponent implements OnInit, OnDestroy {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getStringExtention(monFile: any){
|
|
|
|
|
return ( monFile.name.indexOf('.') > 0 ) ? '.' + monFile.name.split('.').pop().toLowerCase() : '';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|