diff --git a/app.js b/app.js index 4f79ee0..b3e946f 100644 --- a/app.js +++ b/app.js @@ -56,7 +56,7 @@ app.use('/home', express.static(path.join(__dirname, 'dist'))); app.use('/main/:id', express.static(path.join(__dirname, 'dist'))); app.use('/login', express.static(path.join(__dirname, 'dist'))); app.use('/signup', express.static(path.join(__dirname, 'dist'))); - +app.use('/download/:id', express.static(path.join(__dirname, 'dist'))); app.use('/api', api); app.set('view engine', 'pug'); diff --git a/bin/www b/bin/www index 1c340ee..822cb10 100644 --- a/bin/www +++ b/bin/www @@ -35,8 +35,8 @@ var credentials = { passphrase: 'titi' }; -//var server = https.createServer(credentials, app); -var server = http.createServer(app); +var server = https.createServer(credentials, app); +//var server = http.createServer(app); diff --git a/routes/api.js b/routes/api.js index 2d799e7..978b269 100644 --- a/routes/api.js +++ b/routes/api.js @@ -249,6 +249,15 @@ router.post('/getUserById', function(req, res) { }); }); +router.post('/getFileById', function(req, res) { + console.log('yaa' + req.body.id); + FileMongo.find({ + _id: req.body.id + }, function (err, file) { + res.json(file); + + }); +}); /* Login */ router.post('/signin', function(req, res) { User.findOne({ diff --git a/src/app/app.module.ts b/src/app/app.module.ts index d326bdb..ae365de 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -68,56 +68,56 @@ const appRoutes: Routes = [ data: { title: 'Sign Up' } }, { - path: 'download', + path: 'download/:id', component: DownloadLinkComponent , data: { title: 'download' } }, { path: '', - redirectTo: '/home', - pathMatch: 'full' + redirectTo: '/home', + pathMatch: 'full' } ]; @NgModule({ - declarations: [ - AppComponent, - HomeComponent, - LoginComponent, - SignupComponent, - MainComponent, - BookComponent, - DownloadLinkComponent - ], - imports: [ - BrowserModule, - DropzoneModule, - VgCoreModule, - VgControlsModule, - VgOverlayPlayModule, - VgBufferingModule, - BrowserAnimationsModule, - FormsModule, - HttpModule, - HttpClientModule, - RouterModule.forRoot( - appRoutes, - { enableTracing: false } // <-- debugging purposes only - ), - ToastModule.forRoot(), - MDBBootstrapModule.forRoot(), - MDBBootstrapModulePro.forRoot(), - AgmCoreModule.forRoot({ - // https://developers.google.com/maps/documentation/javascript/get-api-key?hl=en#key - apiKey: 'Your_api_key' - }) - ], - providers: [ - MDBSpinningPreloader, - { - provide: DROPZONE_CONFIG, - useValue: DEFAULT_DROPZONE_CONFIG - }], - bootstrap: [AppComponent], - schemas: [ NO_ERRORS_SCHEMA ] + declarations: [ + AppComponent, + HomeComponent, + LoginComponent, + SignupComponent, + MainComponent, + BookComponent, + DownloadLinkComponent + ], + imports: [ + BrowserModule, + DropzoneModule, + VgCoreModule, + VgControlsModule, + VgOverlayPlayModule, + VgBufferingModule, + BrowserAnimationsModule, + FormsModule, + HttpModule, + HttpClientModule, + RouterModule.forRoot( + appRoutes, + { enableTracing: false } // <-- debugging purposes only + ), + ToastModule.forRoot(), + MDBBootstrapModule.forRoot(), + MDBBootstrapModulePro.forRoot(), + AgmCoreModule.forRoot({ + // https://developers.google.com/maps/documentation/javascript/get-api-key?hl=en#key + apiKey: 'Your_api_key' + }) + ], + providers: [ + MDBSpinningPreloader, + { + provide: DROPZONE_CONFIG, + useValue: DEFAULT_DROPZONE_CONFIG + }], + bootstrap: [AppComponent], + schemas: [ NO_ERRORS_SCHEMA ] }) export class AppModule { } diff --git a/src/app/book/book.component.html b/src/app/book/book.component.html index 3d67708..0c7df3a 100644 --- a/src/app/book/book.component.html +++ b/src/app/book/book.component.html @@ -51,17 +51,17 @@
- - - - - - - - - - - + + + + + + + + + + + @@ -345,14 +345,14 @@
- +
diff --git a/src/app/book/book.component.ts b/src/app/book/book.component.ts index b955a9f..7dcbb8c 100644 --- a/src/app/book/book.component.ts +++ b/src/app/book/book.component.ts @@ -20,38 +20,38 @@ import { CompleterService } from '../typescripts/pro'; @Component({ - selector: 'app-book', - templateUrl: './book.component.html', - styleUrls: ['./book.component.css'] + selector: 'app-book', + templateUrl: './book.component.html', + styleUrls: ['./book.component.css'] }) export class BookComponent implements OnInit, OnDestroy { @Input() socialIdUser: String; - @Output() setAllUserAppFolder = new EventEmitter(); + @Output() setAllUserAppFolder = new EventEmitter(); message: string = 'Hola Mundo!'; sizeFile:any; @Output() messageEvent = new EventEmitter(); - currentUser: any; - allUserFile: any; - allUserFolder: any; + currentUser: any; + allUserFile: any; + allUserFolder: any; //socialIdUser: String; - filterAllUserFolder: any; - allUserAppFolder: any; - allUserAppFile: any; - mainFolder: any; - books: any; - filesToUpload: Array; - fileChooseName: string; - httpOptions: any; - isClickCreateFolder: boolean; - inputCreateFolder: String; - reader: FileReader; - test: String; - previewNode:any; - previewTemplate:any; - // config: DropzoneConfigInterface; - //myDropzone: Dropzone; - droptestt:any; + filterAllUserFolder: any; + allUserAppFolder: any; + allUserAppFile: any; + mainFolder: any; + books: any; + filesToUpload: Array; + fileChooseName: string; + httpOptions: any; + isClickCreateFolder: boolean; + inputCreateFolder: String; + reader: FileReader; + test: String; + previewNode:any; + previewTemplate:any; + // config: DropzoneConfigInterface; + //myDropzone: Dropzone; + droptestt:any; allItems: any; @@ -86,7 +86,7 @@ export class BookComponent implements OnInit, OnDestroy { this.sizeFile = 0; - } + } copyLink(val) { let selBox = document.createElement('textarea'); @@ -95,7 +95,7 @@ export class BookComponent implements OnInit, OnDestroy { selBox.style.left = '0'; selBox.style.top = '0'; selBox.style.opacity = '0'; - selBox.value = 'http://localhost:3000/' + val; + selBox.value = 'https://localhost:3000/download/' + val; document.body.appendChild(selBox); selBox.focus(); @@ -162,30 +162,30 @@ export class BookComponent implements OnInit, OnDestroy { } - ngOnInit() { - this.httpOptions = { - headers: new HttpHeaders({ - 'Authorization': localStorage.getItem('jwtToken'), - 'Access-Control-Allow-Origin' : '*', - 'Access-Control-Allow-Methods' : 'GET, POST, OPTIONS, PUT, PATCH, DELETE', - 'Access-Control-Allow-Headers' : 'Origin, X-Requested-With, Content-Type, Accept' - }), - pathFolder: '' - }; - // this.httpOptions = { - // headers: new HttpHeaders({ 'Authorization': localStorage.getItem('jwtToken'), 'Access-Control-Allow-Origin' : '*'}), - // pathFolder: '' - // }; - - this.http.get('/api/getCurrentUser', this.httpOptions).subscribe(user => { - this.currentUser = user; - this.openFolder('Home'); - }, err => { - if (err.status === 401) { - this.router.navigate(['login']); - } - }); - } + ngOnInit() { + this.httpOptions = { + headers: new HttpHeaders({ + 'Authorization': localStorage.getItem('jwtToken'), + 'Access-Control-Allow-Origin' : '*', + 'Access-Control-Allow-Methods' : 'GET, POST, OPTIONS, PUT, PATCH, DELETE', + 'Access-Control-Allow-Headers' : 'Origin, X-Requested-With, Content-Type, Accept' + }), + pathFolder: '' + }; + // this.httpOptions = { + // headers: new HttpHeaders({ 'Authorization': localStorage.getItem('jwtToken'), 'Access-Control-Allow-Origin' : '*'}), + // pathFolder: '' + // }; + + this.http.get('/api/getCurrentUser', this.httpOptions).subscribe(user => { + this.currentUser = user; + this.openFolder('Home'); + }, err => { + if (err.status === 401) { + this.router.navigate(['login']); + } + }); + } deleteFile(fileToDelete) { this.http.post('/api/deleteFileMongo', fileToDelete).subscribe(file => { @@ -214,7 +214,7 @@ export class BookComponent implements OnInit, OnDestroy { }); } saveURLFileMongo(fileToCreateURL){ - fileToCreateURL.url = '../../../public/' + fileToCreateURL._id.toString() + this.getStringExtention(fileToCreateURL); + fileToCreateURL.url = '../../../public/' + fileToCreateURL._id.toString() + this.getStringExtention(fileToCreateURL); this.http.post('/api/saveURLFileMongo', fileToCreateURL).subscribe(data => { console.log('data : ' + data); @@ -243,28 +243,27 @@ export class BookComponent implements OnInit, OnDestroy { } - getfiles() { - //var preview = document.querySelector('img'); + getfiles() { + //var preview = document.querySelector('img'); - this.sizeFile = 0; - var meee = this; + this.sizeFile = 0; + var meee = this; - this.http.post('/api/getFileList', {mainPath : this.mainFolder.path, owner: this.currentUser.username.toString()}).subscribe(files => { - if (files) { + this.http.post('/api/getFileList', {mainPath : this.mainFolder.path, owner: this.currentUser.username.toString()}).subscribe(files => { + if (files) { - this.allUserFile = files; - for (let f of this.allUserFile) { + this.allUserFile = files; + for (let f of this.allUserFile) { - this.sizeFile += +f.taille; - if(f.type === ('image/jpeg') || f.type === ('image/png')){ - f.data = f.url; - f.urlSafe = this.sanitizer.bypassSecurityTrustUrl(f.url); - }else{ - f.data = f.url; - f.urlSafe = this.sanitizer.bypassSecurityTrustResourceUrl(f.url); + this.sizeFile += +f.taille; + if(f.type === ('image/jpeg') || f.type === ('image/png')){ + f.data = f.url; + f.urlSafe = this.sanitizer.bypassSecurityTrustUrl(f.url); + }else{ + f.data = f.url; + f.urlSafe = this.sanitizer.bypassSecurityTrustResourceUrl(f.url); } - } } else { this.allUserFile = []; @@ -274,7 +273,7 @@ export class BookComponent implements OnInit, OnDestroy { } getfolders() { - this.http.post('/api/getFolderList', {mainPath : this.mainFolder.path, owner: this.currentUser.username.toString()}).subscribe(folders => { + this.http.post('/api/getFolderList', {mainPath : this.mainFolder.path, owner: this.currentUser.username.toString()}).subscribe(folders => { if (folders) { this.allUserFolder = folders; } else { @@ -324,110 +323,110 @@ export class BookComponent implements OnInit, OnDestroy { }); } - backToParentFolder(){ - this.openFolder(this.mainFolder.parent); - } + backToParentFolder(){ + this.openFolder(this.mainFolder.parent); + } - openFolder(path: String) { + openFolder(path: String) { if(this.searchStr !== undefined ? path === 'searchStr' : false){ path = this.searchStr; } - this.httpOptions.pathFolder = path; - this.isClickCreateFolder = false; + 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.getAllUserAppFolder(); - this.getfiles(); + this.http.post('/api/getMainFolder', {path: path, owner: this.currentUser.username.toString()}).subscribe(folder => { + if (folder) { + this.mainFolder = folder; + this.getfolders(); + this.getAllUserAppFolder(); + 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('err open Folder : ' + err); - }); - } - } - }); - } + } 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('err open Folder : ' + err); + }); + } + } + }); + } - createBool() { - this.isClickCreateFolder = true; - } + createBool() { + this.isClickCreateFolder = true; + } - createFolder() { - var newPath = this.mainFolder.path + '/' + this.inputCreateFolder; - this.isClickCreateFolder = false; + 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(); - this.getAllUserAppFolder(); - }, err => { - console.log('err create Folder : ' + err); - }); - } + 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('err create Folder : ' + err); + }); + } - ngOnDestroy() { - localStorage.removeItem('jwtToken'); - this.httpOptions = null; - this.currentUser = null; - } + ngOnDestroy() { + localStorage.removeItem('jwtToken'); + this.httpOptions = null; + this.currentUser = null; + } - upload() { + upload() { var me = this; - 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(), url: ''}).subscribe(resp => { - me.saveURLFileMongo(resp); - var mee = this; - - - //////// - me.makeFileRequest('https://localhost:3000/api/upload', [], this.filesToUpload, resp).then((result) => { - mee.getfiles(); - mee.filesToUpload = null; - mee.fileChooseName = 'None'; - }, (error) => { - console.error(error); - }); - }, err => { - console.error(err); - }); - } - } + 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(), url: ''}).subscribe(resp => { + me.saveURLFileMongo(resp); + var mee = this; + + + //////// + me.makeFileRequest('https://localhost:3000/api/upload', [], this.filesToUpload, resp).then((result) => { + mee.getfiles(); + mee.filesToUpload = null; + mee.fileChooseName = 'None'; + }, (error) => { + console.error(error); + }); + }, err => { + console.error(err); + }); + } + } - fileChangeEvent(fileInput: any){ - this.filesToUpload = > fileInput.target.files; - this.fileChooseName = this.filesToUpload[0].name; - } + fileChangeEvent(fileInput: any){ + this.filesToUpload = > fileInput.target.files; + this.fileChooseName = this.filesToUpload[0].name; + } - makeFileRequest(url: string, params: Array, files: Array, monFile: any) { - return new Promise((resolve, reject) => { - var formData: any = new FormData(); - var xhr = new XMLHttpRequest(); + makeFileRequest(url: string, params: Array, files: Array, monFile: any) { + return new Promise((resolve, reject) => { + var formData: any = new FormData(); + var xhr = new XMLHttpRequest(); - formData.append("public[]", files[0], monFile._id + this.getStringExtention(monFile)); - xhr.onreadystatechange = function () { - if (xhr.readyState == 4) { - if (xhr.status == 200) { - resolve(JSON.parse(xhr.response)); - } else { - reject(xhr.response); - } - } - }; + formData.append("public[]", files[0], monFile._id + this.getStringExtention(monFile)); + xhr.onreadystatechange = function () { + if (xhr.readyState == 4) { + if (xhr.status == 200) { + resolve(JSON.parse(xhr.response)); + } else { + reject(xhr.response); + } + } + }; - xhr.open("POST", url, true); - xhr.send(formData); - }); - } + xhr.open("POST", url, true); + xhr.send(formData); + }); + } getStringExtention(monFile: any){ diff --git a/src/app/download-link/download-link.component.html b/src/app/download-link/download-link.component.html index 2825382..fd94f1b 100644 --- a/src/app/download-link/download-link.component.html +++ b/src/app/download-link/download-link.component.html @@ -3,6 +3,10 @@ + + +
@@ -14,11 +18,11 @@
- -
-

File Download

-
- + +
+

File Download

+
+ @@ -29,16 +33,15 @@
-

Name

-

Lenght

+

{{file?.name}}

+

{{ file?.taille / ( 1024 * 1024 ) | number : '1.2-2'}} Mo


- - + diff --git a/src/app/download-link/download-link.component.ts b/src/app/download-link/download-link.component.ts index a930f83..f8409b6 100644 --- a/src/app/download-link/download-link.component.ts +++ b/src/app/download-link/download-link.component.ts @@ -1,15 +1,40 @@ import { Component, OnInit } from '@angular/core'; +import { Router, ActivatedRoute } from '@angular/router'; +import {HttpClient} from '@angular/common/http'; + @Component({ - selector: 'app-download-link', - templateUrl: './download-link.component.html', - styleUrls: ['./download-link.component.scss'] + selector: 'app-download-link', + templateUrl: './download-link.component.html', + styleUrls: ['./download-link.component.scss'] }) export class DownloadLinkComponent implements OnInit { + idFile: String; + urlFile: String; + file: any; + + constructor(private http: HttpClient, private router: Router, private route: ActivatedRoute) { + this.idFile = ''; + this.urlFile = ''; + this.route.params.subscribe(params => { + this.idFile = params['id']; + this.urlFile = 'http://localhost:3000/' + this.idFile; + console.log('this.idFile : ' + this.idFile ); + + this.http.post('/api/getFileById', {id: this.idFile.toString()}).subscribe(file => { + + if (file) { + this.file = file[0]; + console.log(this.file) + } else { + this.file = []; + } + }); - constructor() { } + }); + } - ngOnInit() { - } + ngOnInit() { + } } diff --git a/src/app/home/home.component.ts b/src/app/home/home.component.ts index 982e42f..3c4ed90 100644 --- a/src/app/home/home.component.ts +++ b/src/app/home/home.component.ts @@ -73,8 +73,8 @@ export class HomeComponent implements OnInit { ngOnInit() { setTimeout(() => { - this.showCookies();); - }, 1000); + this.showCookies(); + }, 1000); ; } } diff --git a/src/app/main/main.component.html b/src/app/main/main.component.html index 001a087..77a63e5 100644 --- a/src/app/main/main.component.html +++ b/src/app/main/main.component.html @@ -13,7 +13,7 @@
  • - +