add file chuck upload, file validation, redirect to home page incase route doesnt exist and refresh token interceptor

This commit is contained in:
Peter Maquiran
2023-11-09 11:45:04 +01:00
parent a05f85a37f
commit a16e97a59a
41 changed files with 48604 additions and 1902 deletions
+63 -12
View File
@@ -14,6 +14,10 @@ import { ToastService } from 'src/app/services/toast.service';
import { ThemeService } from 'src/app/services/theme.service'
import { PermissionService } from 'src/app/services/permission.service';
import { Storage } from '@ionic/storage';
import { ChunkService } from 'src/app/services/stream/chunk.service'
import { StreamService } from 'src/app/services/stream/stream.service'
import { HttpClient, HttpHeaders, HttpEventType } from '@angular/common/http';
// import { ActionModel } from 'src/app/models/beast-orm';
@@ -68,6 +72,9 @@ export class PublicationsPage implements OnInit {
public ThemeService: ThemeService,
public p: PermissionService,
private storage: Storage,
private ChunkService: ChunkService,
private StreamService:StreamService,
private http: HttpClient,
) {
this.months = ["Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"];
@@ -143,11 +150,11 @@ export class PublicationsPage implements OnInit {
this.publications.GetPublicationFolderList().subscribe(async res => {
this.showLoader = false;
const folders: PublicationFolder[] = this.getPublicationFolderMap(res)
this.publicationsEventFolderList = folders.filter((e)=>e.ActionType == 'Evento')
await this.storage.set('actionsEvents', this.publicationsEventFolderList);
this.showLoader = false;
// (async ()=> {
@@ -189,35 +196,79 @@ export class PublicationsPage implements OnInit {
}
async getFromDB() {
//const folders: PublicationFolder[] = await ActionModel.all()
//this.showLoader = false;
// this.publicationsEventFolderList = folders
this.storage.get('actionsEvents').then((events = []) => {
if(Array.isArray(events)) {
const folders: PublicationFolder[] = this.getPublicationFolderMap(events)
this.showLoader = false;
this.publicationsEventFolderList = folders
}
}
});
this.storage.get('actionsViagens').then((viagens = []) => {
if(Array.isArray(viagens)) {
const folders: PublicationFolder[] = this.getPublicationFolderMap(viagens)
this.publicationsTravelFolderList = folders
this.showLoader = false;
}
});
}
async onFileSelect(event: any) {
const file:File = event.target.files[0];
const chunkSize = 1024 * 1024; // Adjust the chunk size as needed
const chunks = [];
let offset = 0;
let i = 0;
let j = 0;
function count () {
j++
return j
}
while (offset < file.size) {
const chunk = file.slice(offset, offset + chunkSize);
const reader = new FileReader();
reader.onload = async () => {
const headers = new HttpHeaders()
.append('X-File-Name', "fileName")
.append('X-File-Extension', "mp4")
.append('X-File-Content-Length', i.toString())
.append('X-File-Index', count().toString());
const a = new Uint8Array(reader.result as ArrayBuffer)
await this.http.post('http://localhost:3001/upload', a.buffer, { headers, responseType: 'blob' }).toPromise();
};
reader.readAsArrayBuffer(chunk);
offset += chunkSize;
i++;
}
}
async editAction(folderId?: string) {
const modal = await this.modalController.create({
component: EditActionPage,
@@ -244,7 +295,7 @@ export class PublicationsPage implements OnInit {
if(error.status == 0) {
this.toastService._badRequest('Sem acesso à internet. Por favor verifique sua conexão')
} else {
this.toastService._badRequest()
}
}
@@ -252,7 +303,7 @@ export class PublicationsPage implements OnInit {
loader.remove()
this.refreshing()
}
}
async AddPublicationFolder(item?: any) {
@@ -270,7 +321,7 @@ export class PublicationsPage implements OnInit {
cssClass: 'new-action modal modal-desktop',
backdropDismiss: false
});
modal.onDidDismiss().then(() => {
this.getActions();
});
@@ -336,7 +387,7 @@ export class PublicationsPage implements OnInit {
cssClass: 'new-action modal modal-desktop',
backdropDismiss: false
});
modal.onDidDismiss();
await modal.present();
@@ -470,7 +521,7 @@ export class PublicationsPage implements OnInit {
},
//translucent: true
});
modal.onDidDismiss().then(res => {
if (res['data'] == 'edit') {
this.closeDesktopComponent();