From 9652139827fa575f08a00e86de88248ad96e7796 Mon Sep 17 00:00:00 2001 From: Equilibrium ITO Date: Sun, 3 Mar 2024 09:25:04 +0100 Subject: [PATCH] add generate string method --- .../new-publication/new-publication.page.ts | 24 +++++++++++++++---- src/app/services/videoconvert.service.ts | 13 +++------- .../new-publication/new-publication.page.ts | 17 ++++++++++++- 3 files changed, 39 insertions(+), 15 deletions(-) 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 eb8f9b859..a456f2ded 100644 --- a/src/app/pages/publications/new-publication/new-publication.page.ts +++ b/src/app/pages/publications/new-publication/new-publication.page.ts @@ -803,18 +803,20 @@ export class NewPublicationPage implements OnInit { } async recordevideoIos(fullPath) { + console.log('fullpath', fullPath) try { const directory = await Filesystem.getUri({ directory: Directory.Cache, path: '', }); + const stringGerada = this.gerarStringAleatoria(); +console.log(stringGerada); let fileObject ={}; - this.videoconvertService.convertVideo(fullPath,directory.uri,'mp4').then(() => { - Filesystem.readFile({ path: `${directory.uri}output.mp4`}) + this.videoconvertService.convertVideo(fullPath,directory.uri,stringGerada,'mp4').then(async () => { + await Filesystem.readFile({ path: `${directory.uri}${stringGerada}.mp4`}) .then(async (content) => { - console.log(content.data) this.filecontent = true; fileObject = { FileBase64: 'data:video/mp4;base64,' + content.data, @@ -822,6 +824,7 @@ export class NewPublicationPage implements OnInit { OriginalFileName: 'video' } this.seletedContent.push(fileObject) + console.log('file object 1',fileObject) fileObject ={}; const deleteSecretFile = async () => { await Filesystem.deleteFile({ @@ -829,9 +832,10 @@ export class NewPublicationPage implements OnInit { directory: Directory.Cache, }); }; - deleteSecretFile().then((value) => { + await deleteSecretFile().then((value) => { console.log('delete file',value) fileObject ={}; + console.log('file object 2',fileObject) }) }) .catch((erro) => console.error('read converted video erro ', erro)); @@ -901,5 +905,17 @@ export class NewPublicationPage implements OnInit { } + gerarStringAleatoria() { + const caracteres = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; + let stringAleatoria = ''; + + for (let i = 0; i < 4; i++) { + const indiceAleatorio = Math.floor(Math.random() * caracteres.length); + stringAleatoria += caracteres.charAt(indiceAleatorio); + } + + return stringAleatoria; + } + } diff --git a/src/app/services/videoconvert.service.ts b/src/app/services/videoconvert.service.ts index e15a78cb9..0dce197b0 100644 --- a/src/app/services/videoconvert.service.ts +++ b/src/app/services/videoconvert.service.ts @@ -10,19 +10,12 @@ export class VideoconvertService { private ffmpeg: FFMpeg ) { } - async convertVideo(inputPath, outputPath, formart) { - const ffmpegCommand = `-i "${inputPath}" -c:v copy -c:a aac -strict experimental "${outputPath}output.${formart}"`; + async convertVideo(inputPath, outputPath,filename, formart) { + const ffmpegCommand = `-i "${inputPath}" -c:v copy -c:a aac -strict experimental "${outputPath}${filename}.${formart}"`; const result = await this.ffmpeg.exec(ffmpegCommand) - console.log('Convert returns ', `${outputPath}output.${formart}`); + console.log('Convert returns ', `${outputPath}${filename}.${formart}`); } - async convertVideoAndroid(inputPath, outputPath, formart) { - const ffmpegCommand = `-i "${inputPath}" -c:v copy -c:a aac -strict experimental "${outputPath}/output.${formart}"`; - - const result = await this.ffmpeg.exec(ffmpegCommand) - - console.log('Convert returns ', `${outputPath}output.${formart}`); - } } 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 35ab80390..20e1a0db1 100644 --- a/src/app/shared/publication/new-publication/new-publication.page.ts +++ b/src/app/shared/publication/new-publication/new-publication.page.ts @@ -763,7 +763,10 @@ export class NewPublicationPage implements OnInit { path: '', }); - this.videoconvertService.convertVideo(fullPath,directory.uri,'mp4'); + const stringGerada = this.gerarStringAleatoria(); +console.log(stringGerada); + + this.videoconvertService.convertVideo(fullPath,directory.uri,stringGerada,'mp4'); Filesystem.readFile({ path: `${directory.uri}output.mp4`}) @@ -814,6 +817,18 @@ export class NewPublicationPage implements OnInit { } } + + gerarStringAleatoria() { + const caracteres = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; + let stringAleatoria = ''; + + for (let i = 0; i < 4; i++) { + const indiceAleatorio = Math.floor(Math.random() * caracteres.length); + stringAleatoria += caracteres.charAt(indiceAleatorio); + } + + return stringAleatoria; +} }