mais {{ seletedContent.length - displayLimit }}
diff --git a/src/app/pages/publications/new-publication/new-publication.page.ts b/src/app/pages/publications/new-publication/new-publication.page.ts index 620b320ca..81c4e2ad2 100644 --- a/src/app/pages/publications/new-publication/new-publication.page.ts +++ b/src/app/pages/publications/new-publication/new-publication.page.ts @@ -31,6 +31,7 @@ import { File } from '@ionic-native/file/ngx'; import { Media } from '@ionic-native/media/ngx'; import { checkFileTypeService } from 'src/app/services/checkFileType.service'; import { FileValidatorService } from "src/app/services/file/file-validator.service" +import { PublicationAttachmentEntity } from 'src/app/shared/publication/upload/upload-streaming.service'; const config = { quality: 0.5, maxWidth: 800, @@ -92,6 +93,13 @@ export class NewPublicationPage implements OnInit { publicationTitle: string; imgUrl: any; + + ActionType = { + newRapid : "1", + new: "2", + edit: "3" + } + Defaultimage: any = ''; photo: SafeResourceUrl; @@ -112,7 +120,7 @@ export class NewPublicationPage implements OnInit { photoOrVideo: boolean = false; fileType = ""; filecontent: boolean; - seletedContent: any[] = [] + seletedContent: PublicationAttachmentEntity[] = [] // Set a limit for the number of images to display displayLimit = 4; filesSizeSum = 0; @@ -142,6 +150,18 @@ export class NewPublicationPage implements OnInit { if (this.publication) { this.seletedContent = this.publication.Files; this.filecontent = true; + + this.seletedContent = this.publication.Files.map(e => { + return new PublicationAttachmentEntity( + { + base64: e.FileBase64, + extension: e.FileExtension, + OriginalFileName: e.OriginalFileName, + FileType: this.checkFileType.checkFileType(e.FileExtension) as any + } + ) + }) + } console.log('Edit', this.publication) this.publicationTitle = 'Nova Publicação'; @@ -161,12 +181,16 @@ export class NewPublicationPage implements OnInit { recursive: true }); - document.addEventListener("click", clickOutside, false); - function clickOutside(e) { - const inside = document.getElementById('container-multiselect').contains(e.target); - this.photoOrVideo = false; - console.log(this.photoOrVideo) - } + try { + document.addEventListener("click", clickOutside, false); + function clickOutside(e) { + const inside = document.getElementById('container-multiselect').contains(e.target); + this.photoOrVideo = false; + console.log(this.photoOrVideo) + } + } catch (error) {} + + } // in use @@ -193,11 +217,14 @@ export class NewPublicationPage implements OnInit { console.log('take picture', this.removeTextBeforeSlash(picture, ','),) this.filecontent = true; this.photoOrVideo = false; - let fileObject = { - FileBase64: this.removeTextBeforeSlash(picture, ','), - FileExtension: capturedImage.format, + + const fileObject = new PublicationAttachmentEntity({ + base64: this.removeTextBeforeSlash(picture, ','), + extension: capturedImage.format, + FileType: 'image', OriginalFileName: 'image' - } + }) + this.seletedContent.push(fileObject) @@ -251,11 +278,14 @@ export class NewPublicationPage implements OnInit { .then(async (content) => { this.filecontent = true; - let fileObject = { - FileBase64: 'data:video/mp4;base64,'+content.data, - FileExtension: 'mp4', - OriginalFileName: 'video' - } + let fileObject = new PublicationAttachmentEntity({ + base64: 'data:video/mp4;base64,'+content.data, + extension: 'mp4', + OriginalFileName: 'record', + FileType: 'video' + + }) + this.seletedContent.push(fileObject) }) .catch((err) => console.error(err)); @@ -294,19 +324,30 @@ export class NewPublicationPage implements OnInit { this.filecontent = true; let fileObject; if(this.removeTextBeforeSlash(element.mimeType, '/') == "mp4") { - fileObject = { - FileBase64: 'data:video/mp4;base64,'+ content.data, - FileExtension: this.removeTextBeforeSlash(element.mimeType, '/'), - OriginalFileName: 'video' - } + + const extension = this.removeTextBeforeSlash(element.mimeType, '/') + + fileObject = new PublicationAttachmentEntity({ + base64: content.data, + extension: extension, + OriginalFileName: 'video', + FileType: 'video' + }) + } else { - fileObject = { - FileBase64: content.data, - FileExtension: this.removeTextBeforeSlash(element.mimeType, '/'), - OriginalFileName: 'image' - } + + const extension = this.removeTextBeforeSlash(element.mimeType, '/') + + fileObject = new PublicationAttachmentEntity({ + base64: content.data, + extension: extension, + OriginalFileName: 'image', + FileType: 'image' + + }) + } - + this.seletedContent.push(fileObject) }) .catch((err) => console.error(err)); @@ -353,24 +394,24 @@ export class NewPublicationPage implements OnInit { /* // in use async laodPicture() { - + const capturedImage = await Camera.getPhoto({ quality: 90, // allowEditing: true, resultType: CameraResultType.Uri, source: CameraSource.Photos }); - + const response = await fetch(capturedImage.webPath!); const blob = await response.blob(); - + this.convertBlobToBase64Worker.postMessage(blob); this.convertBlobToBase64Worker.onmessage = async (oEvent)=> { this.capturedImage = oEvent.data this.capturedImageTitle = 'foto' - + } - + } */ @@ -497,7 +538,7 @@ export class NewPublicationPage implements OnInit { OriginalFileName: "video", } } - + return e }) */ @@ -533,8 +574,6 @@ export class NewPublicationPage implements OnInit { try { - - await this.publications.CreatePublication(this.folderId, this.publication).toPromise(); this.close(); this.httpErrorHandle.httpsSucessMessagge('Criar publicação') @@ -740,12 +779,16 @@ export class NewPublicationPage implements OnInit { if (this.checkFileType.checkFileType(FileExtension) == 'image' || this.checkFileType.checkFileType(FileExtension) == 'video') { let resultUrl = decodeURIComponent(element.url); Filesystem.readFile({ path: resultUrl }).then(async (content) => { - console.log('shared base', content.data) - let fileObject = { - FileBase64: this.removeTextBeforeSlash(content.data, ','), - FileExtension: FileExtension, - OriginalFileName: 'shared', - } + + let fileObject = new PublicationAttachmentEntity( + { + base64: this.removeTextBeforeSlash(content.data, ','), + extension: FileExtension, + OriginalFileName: "share-content", + FileType: this.checkFileType.checkFileType(FileExtension) as any + } + ) + this.seletedContent.push(fileObject) }) } else { diff --git a/src/app/pages/publications/publications.page.ts b/src/app/pages/publications/publications.page.ts index 5692a8d4e..33a8e9d02 100644 --- a/src/app/pages/publications/publications.page.ts +++ b/src/app/pages/publications/publications.page.ts @@ -98,6 +98,7 @@ export class PublicationsPage implements OnInit { this.hideRefreshButton(); this.intent = window["sharedContent"] + window["refreshPublication"] = this.refreshing } @@ -124,7 +125,7 @@ export class PublicationsPage implements OnInit { } } - refreshing() { + refreshing = () => { setTimeout(() => { this.getActions(); }, 1500); diff --git a/src/app/services/socket-connection-mcr.service.ts b/src/app/services/socket-connection-mcr.service.ts index 2028c3b52..9b6374b81 100644 --- a/src/app/services/socket-connection-mcr.service.ts +++ b/src/app/services/socket-connection-mcr.service.ts @@ -10,60 +10,60 @@ import { HubConnectionBuilder } from '@microsoft/signalr'; providedIn: 'root' }) export class SocketConnectionMCRService { - private callbacks: Function[] = [] - private onDisconnect: Function[] = [] - private onConnect: Function[] = [] + // private callbacks: Function[] = [] + // private onDisconnect: Function[] = [] + // private onConnect: Function[] = [] - constructor(private http: HttpClient,) { - window["http"] = this.http - } + // constructor(private http: HttpClient,) { + // window["http"] = this.http + // } - connect() { + // connect() { - var connection = new signalR.HubConnectionBuilder() - .withUrl("https://gdcmapi-dev.dyndns.info/FileHub", { - accessTokenFactory: () => "Bearer "+SessionStore.user.Authorization - }).configureLogging(signalR.LogLevel.Information) - .build(); + // var connection = new signalR.HubConnectionBuilder() + // .withUrl("https://gdcmapi-dev.dyndns.info/FileHub", { + // accessTokenFactory: () => "Bearer "+SessionStore.user.Authorization + // }).configureLogging(signalR.LogLevel.Information) + // .build(); - connection.on("ReceiveMessage", (message) => { - console.log("ReceiveMessage", message) - }) + // connection.on("ReceiveMessage", (message) => { + // console.log("ReceiveMessage", message) + // }) - connection.onreconnected((connectionId) => { - console.assert(connection.state === signalR.HubConnectionState.Connected); - console.log(`Reconnected with connectionId: ${connectionId}`); - }); + // connection.onreconnected((connectionId) => { + // console.assert(connection.state === signalR.HubConnectionState.Connected); + // console.log(`Reconnected with connectionId: ${connectionId}`); + // }); - connection.start() - .then(() => { - console.log("SignalR connection started."); - }) - .catch((error) => { - console.error("Error starting SignalR connection:", error); - }); + // connection.start() + // .then(() => { + // console.log("SignalR connection started."); + // }) + // .catch((error) => { + // console.error("Error starting SignalR connection:", error); + // }); - connection.onclose((error) => { - connection.start() - console.log("SignalR connection closed:", error); - }); + // connection.onclose((error) => { + // connection.start() + // console.log("SignalR connection closed:", error); + // }); - } + // } - subscribe(callback) { - this.callbacks.push(callback); - } + // subscribe(callback) { + // this.callbacks.push(callback); + // } - unsubscribe(callback) { - this.callbacks = this.callbacks.filter(cb => cb !== callback); - } + // unsubscribe(callback) { + // this.callbacks = this.callbacks.filter(cb => cb !== callback); + // } - onDisconnectCallback(callback) { - this.onDisconnect.push(callback) - } - onConnectCallback(callback) { - this.onConnect.push(callback) - } + // onDisconnectCallback(callback) { + // this.onDisconnect.push(callback) + // } + // onConnectCallback(callback) { + // this.onConnect.push(callback) + // } } @@ -74,6 +74,7 @@ class ReconnectingWebSocketSignalR { private callbacks: Function[] = [] private onDisconnect: Function[] = [] private onConnect: Function[] = [] + private stop = true constructor() { this.isOpen = false; @@ -81,9 +82,13 @@ class ReconnectingWebSocketSignalR { } connect() { + console.log("try to connect=================================") + this.stop = false + this.connection = new signalR.HubConnectionBuilder() .withUrl("https://gdcmapi-dev.dyndns.info/FileHub", { - accessTokenFactory: () => "Bearer "+SessionStore.user.Authorization + transport: signalR.HttpTransportType.LongPolling, + accessTokenFactory: () => SessionStore.user.Authorization }).configureLogging(signalR.LogLevel.Information) .build(); @@ -95,16 +100,15 @@ class ReconnectingWebSocketSignalR { this.onConnect.forEach(callback => callback()); - console.log("SignalR connection started."); }) .catch((error) => { - console.error("Error starting SignalR connection:", error); + console.error("Error starting SignalR connection:", error); }); this.connection.on("ReceiveMessage", (message) => { const data: any = JSON.parse(message) - console.log(data) + console.log("ReceiveMessage", data) this.callbacks.forEach(callback => callback(data)); }) @@ -113,12 +117,27 @@ class ReconnectingWebSocketSignalR { this.isOpen = false; this.onDisconnect.forEach(callback => callback()); // Attempt to reconnect after a delay - setTimeout(() => { - this.connect(); - }, 1000); // Adjust the delay as needed + if(this.stop) { + setTimeout(() => { + this.connect(); + }, 1000); // Adjust the delay as needed + } + }); + } - + disconnect() { + this.stop = true + this.connection.stop() + .then(() => { + console.log('WebSocket connection closed'); + this.isOpen = false; + this.onDisconnect.forEach(callback => callback()); + console.log("SignalR connection stopped."); + }) + .catch((error) => { + console.error("Error stopping SignalR connection:", error); + }); } subscribe(callback) { @@ -143,81 +162,81 @@ interface socketResponse { Guid: string isCompleted: Boolean } -class ReconnectingWebSocket { +// class ReconnectingWebSocket { - private url: string - private socket - isOpen: boolean - private callbacks: Function[] = [] - private onDisconnect: Function[] = [] - private onConnect: Function[] = [] +// private url: string +// private socket +// isOpen: boolean +// private callbacks: Function[] = [] +// private onDisconnect: Function[] = [] +// private onConnect: Function[] = [] - http: HttpClient = window["http"] +// http: HttpClient = window["http"] - constructor(url) { - this.url = url; - this.socket = null; - this.isOpen = false; - this.connect(); - } +// constructor(url) { +// this.url = url; +// this.socket = null; +// this.isOpen = false; +// this.connect(); +// } - connect() { - this.socket = new WebSocket(this.url); +// connect() { +// this.socket = new WebSocket(this.url); - this.socket.addEventListener('open', (event) => { - this.isOpen = true; - console.log('WebSocket connection established'); +// this.socket.addEventListener('open', (event) => { +// this.isOpen = true; +// console.log('WebSocket connection established'); - // Example: Send a message to the server - this.socket.send('Hello, WebSocket Server!'); - this.onConnect.forEach(callback => callback()); - }); +// // Example: Send a message to the server +// this.socket.send('Hello, WebSocket Server!'); +// this.onConnect.forEach(callback => callback()); +// }); - this.socket.addEventListener('message', (event) => { - const data: socketResponse = JSON.parse(event.data) - this.callbacks.forEach(callback => callback(data)); - }); +// this.socket.addEventListener('message', (event) => { +// const data: socketResponse = JSON.parse(event.data) +// this.callbacks.forEach(callback => callback(data)); +// }); - this.socket.addEventListener('close', (event) => { - console.log('WebSocket connection closed'); - this.isOpen = false; - this.onDisconnect.forEach(callback => callback()); - // Attempt to reconnect after a delay - setTimeout(() => { - this.connect(); - }, 1000); // Adjust the delay as needed - }); - } +// this.socket.addEventListener('close', (event) => { +// console.log('WebSocket connection closed'); +// this.isOpen = false; +// this.onDisconnect.forEach(callback => callback()); +// // Attempt to reconnect after a delay +// setTimeout(() => { +// this.connect(); +// }, 1000); // Adjust the delay as needed +// }); +// } - send(message) { - if (this.isOpen) { - this.socket.send(message); - } else { - console.error('WebSocket connection is not open. Unable to send message.'); - } - } +// send(message) { +// if (this.isOpen) { +// this.socket.send(message); +// } else { +// console.error('WebSocket connection is not open. Unable to send message.'); +// } +// } - close() { - if (this.isOpen) { - this.socket.close(); - } - } +// close() { +// if (this.isOpen) { +// this.socket.close(); +// } +// } - subscribe(callback) { - this.callbacks.push(callback); - } +// subscribe(callback) { +// this.callbacks.push(callback); +// } - unsubscribe(callback) { - this.callbacks = this.callbacks.filter(cb => cb !== callback); - } +// unsubscribe(callback) { +// this.callbacks = this.callbacks.filter(cb => cb !== callback); +// } - onDisconnectCallback(callback) { - this.onDisconnect.push(callback) - } - onConnectCallback(callback) { - this.onConnect.push(callback) - } -} +// onDisconnectCallback(callback) { +// this.onDisconnect.push(callback) +// } +// onConnectCallback(callback) { +// this.onConnect.push(callback) +// } +// } // export class ObjectMergeNotification{ @@ -293,9 +312,11 @@ export class ObjectMergeNotification{ this.socket.onConnectCallback(()=> { this.runWatch = false }) + this.socket.subscribe((data: socketResponse) => { if(data.isCompleted == true) { + console.log("==================!!!====================") this.callbacks[data.Guid](data) delete this.callbacks[data.Guid] } @@ -305,36 +326,9 @@ export class ObjectMergeNotification{ } - connect() { - - var connection = new signalR.HubConnectionBuilder() - .withUrl("https://gdcmapi-dev.dyndns.info/FileHub", { - accessTokenFactory: () => "Bearer "+SessionStore.user.Authorization - }).configureLogging(signalR.LogLevel.Information) - .build(); - - connection.on("ReceiveMessage", (message) => { - console.log("ReceiveMessage", message) - }) - - connection.onreconnected((connectionId) => { - console.assert(connection.state === signalR.HubConnectionState.Connected); - console.log(`Reconnected with connectionId: ${connectionId}`); - }); - - connection.start() - .then(() => { - console.log("SignalR connection started."); - }) - .catch((error) => { - console.error("Error starting SignalR connection:", error); - }); - - connection.onclose((error) => { - connection.start() - console.log("SignalR connection closed:", error); - }); - + close() { + console.log("close=============================================") + this.socket.disconnect(); } async watch() { @@ -354,6 +348,8 @@ export class ObjectMergeNotification{ }, 1000) + } else { + console.log("end loop============================") } } diff --git a/src/app/shared/API/CMAPI/cmapi-api.service.ts b/src/app/shared/API/CMAPI/cmapi-api.service.ts index 927de3936..ae13fb503 100644 --- a/src/app/shared/API/CMAPI/cmapi-api.service.ts +++ b/src/app/shared/API/CMAPI/cmapi-api.service.ts @@ -14,7 +14,7 @@ export class CMAPIAPIService { getVideoHeader(url: string) { - // return this.http.head('http://localhost:3001/static/'+url, { observe: 'response' }) + //return this.http.head('http://localhost:3001/static/'+url, { observe: 'response' }) return this.http.head(environment.apiURL+'ObjectServer/StreamFiles?path='+url, { observe: 'response' }) } } diff --git a/src/app/shared/publication/new-publication/new-publication.page.html b/src/app/shared/publication/new-publication/new-publication.page.html index 40b765508..4c4b9a21a 100644 --- a/src/app/shared/publication/new-publication/new-publication.page.html +++ b/src/app/shared/publication/new-publication/new-publication.page.html @@ -56,34 +56,24 @@mais {{ seletedContent.length - displayLimit }}
diff --git a/src/app/shared/publication/new-publication/new-publication.page.ts b/src/app/shared/publication/new-publication/new-publication.page.ts index d62a5523e..54cbb977e 100644 --- a/src/app/shared/publication/new-publication/new-publication.page.ts +++ b/src/app/shared/publication/new-publication/new-publication.page.ts @@ -22,6 +22,7 @@ import { CaptureError, CaptureImageOptions, MediaCapture, MediaFile } from '@awe import { Filesystem, Directory, Encoding, FilesystemDirectory } from '@capacitor/filesystem'; import { Platform } from '@ionic/angular'; import { Capacitor } from '@capacitor/core'; +import { PublicationAttachmentEntity, PublicationFormMV } from '../upload/upload-streaming.service'; enum ActionType { @@ -70,9 +71,9 @@ export class NewPublicationPage implements OnInit { photoOrVideo: boolean = false; video: any; - publicationFormMV = new PublicationFormMV() + constructor( public photoService: PhotoService, private publications: PublicationsService, @@ -97,7 +98,6 @@ export class NewPublicationPage implements OnInit { this.filecontent = true; } - this.SocketConnectionMCRService.connect() } ngOnInit() { @@ -148,13 +148,15 @@ export class NewPublicationPage implements OnInit { } console.log('edit', this.publication) this.pub = this.publication; + + console.log("this.publication.Files", this.publication.Files) this.seletedContent = this.publication.Files.map(e => { return new PublicationAttachmentEntity( { base64: e.FileBase64, extension: e.FileExtension, OriginalFileName: e.OriginalFileName, - FileType: this.checkFileType.checkFileType(e.FileExtension) + FileType: this.checkFileType.checkFileType(e.FileExtension) as any } ) }) @@ -186,11 +188,6 @@ export class NewPublicationPage implements OnInit { 0.9 // quality ).then((picture) => { this.photoOrVideo = false; - let fileObject = { - FileBase64: picture, - FileExtension: this.removeTextBeforeSlash('jpeg', '/'), - OriginalFileName: 'imagem' - } const FileExtension = this.removeTextBeforeSlash('jpeg', '/') @@ -231,11 +228,6 @@ export class NewPublicationPage implements OnInit { 800, // maxHeight 0.9 // quality ).then((picture) => { - let fileObject = { - FileBase64: picture, - FileExtension: this.removeTextBeforeSlash('jpeg', '/'), - OriginalFileName: 'image' - } const FileExtension = this.removeTextBeforeSlash('jpeg', '/') @@ -278,7 +270,7 @@ export class NewPublicationPage implements OnInit { console.log("base64 :data:video/mp4;base64,",this.arrayBufferToBase64(await blob.arrayBuffer())) */ - this.convertBlobToBase64(blobFile.blob).then((value) => { + this.convertBlobToBase64(blobFile.blob).then((value: string) => { console.log(value) @@ -294,7 +286,8 @@ export class NewPublicationPage implements OnInit { base64: value, extension: FileExtension, blobFile: file, - FileType: this.checkFileType.checkFileType(FileExtension) + FileType: this.checkFileType.checkFileType(FileExtension) as any, + OriginalFileName: 'load video' } ) @@ -368,7 +361,7 @@ export class NewPublicationPage implements OnInit { base64: content.data, extension: this.removeTextBeforeSlash(element.mimeType, '/'), OriginalFileName: 'video', - FileType: this.checkFileType.checkFileType( this.removeTextBeforeSlash(element.mimeType, '/')) + FileType: this.checkFileType.checkFileType( this.removeTextBeforeSlash(element.mimeType, '/')) as any }) this.seletedContent.push(fileObject) }) @@ -468,11 +461,10 @@ export class NewPublicationPage implements OnInit { console.log("this.publication.Files", this.publication.Files) } - - this.publication.Files = this.publication.Files.map(e => ({ - FileBase64: e.FileBase64, + this.publication.Files = this.publication.Files.map( (e: PublicationAttachmentEntity) => ({ + FileBase64: e.Base64, FileExtension: e.FileExtension, - OriginalFileName: 'foto' + OriginalFileName: e.OriginalFileName || 'foto' })) try { @@ -523,23 +515,21 @@ export class NewPublicationPage implements OnInit { if(e.FileType == 'video') { e.OriginalFileName = e.chucksManager.path e.FileExtension = "mp4" + e.Base64 = "" } return e }) - console.log("this.publication.Files", this.publication.Files) } - this.publication.Files = this.publication.Files.map(e => ({ - FileBase64: e.FileBase64, + this.publication.Files = this.publication.Files.map( (e:PublicationAttachmentEntity) => ({ + FileBase64: e.Base64, FileExtension: e.FileExtension, - OriginalFileName: 'foto' + OriginalFileName: e.OriginalFileName || 'foto' })) - - const loader = this.toastService.loading() try { @@ -560,12 +550,17 @@ export class NewPublicationPage implements OnInit { loader.remove() } - } else { this.toastService._badRequest("É necessário adicionar uma imagem ou vídeo") } } + + this.publicationFormMV.ObjectMergeNotification.close() + } + + ngOnDestroy() { + this.publicationFormMV.ObjectMergeNotification.close() } close() { @@ -1071,444 +1066,3 @@ export class NewPublicationPage implements OnInit { return true; } } - -class UploadFileUseCase { - CMAPIService: CMAPIService = window["CMAPIAPIRepository"] - constructor() {} - async execute(PublicationAttachmentEntity: PublicationAttachmentEntity): Promise