2020-12-01 14:03:15 +01:00
|
|
|
import { Component, OnInit } from '@angular/core';
|
2022-04-26 16:53:10 +01:00
|
|
|
import { ModalController, NavParams, Platform, LoadingController } from '@ionic/angular';
|
2020-12-09 12:10:19 +01:00
|
|
|
|
2020-12-11 18:00:38 +01:00
|
|
|
/* import {Plugins, CameraResultType, CameraSource} from '@capacitor/core'; */
|
2020-12-09 12:10:19 +01:00
|
|
|
import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser';
|
|
|
|
|
import { PublicationsService } from 'src/app/services/publications.service';
|
|
|
|
|
import { Publication } from 'src/app/models/publication';
|
2020-12-10 11:22:06 +01:00
|
|
|
import { Image } from 'src/app/models/image';
|
2020-12-11 15:09:53 +01:00
|
|
|
import { PhotoService } from 'src/app/services/photo.service';
|
2021-01-15 11:07:20 +01:00
|
|
|
//Capacitor
|
2020-12-11 18:00:38 +01:00
|
|
|
|
2021-06-29 14:16:49 +01:00
|
|
|
import { ToastService } from 'src/app/services/toast.service';
|
2021-07-06 16:18:00 +01:00
|
|
|
import { FormControl, FormGroup, Validators } from '@angular/forms';
|
|
|
|
|
import { ThemePalette } from '@angular/material/core';
|
2021-07-15 17:01:32 +01:00
|
|
|
import { formatDate } from 'src/plugin/momentG.js'
|
2021-11-09 10:13:48 +01:00
|
|
|
import { ThemeService } from 'src/app/services/theme.service';
|
2021-11-16 14:06:30 +01:00
|
|
|
import { Camera, CameraResultType, CameraSource, Photo } from '@capacitor/camera';
|
2020-12-01 14:03:15 +01:00
|
|
|
|
2024-02-27 13:04:23 +01:00
|
|
|
import { Filesystem, Directory, Encoding, FilesystemDirectory, FilesystemEncoding } from '@capacitor/filesystem';
|
2021-11-26 14:46:08 +01:00
|
|
|
import { NgxImageCompressService } from "ngx-image-compress";
|
2023-02-27 09:34:36 +01:00
|
|
|
import { HttpErrorHandle } from 'src/app/services/http-error-handle.service';
|
2023-08-18 17:37:11 +01:00
|
|
|
import { PublicationFolderService } from 'src/app/store/publication-folder.service';
|
2023-08-22 11:25:13 +01:00
|
|
|
import { RouteService } from 'src/app/services/route.service';
|
2023-08-23 17:19:22 +01:00
|
|
|
import { FileService } from 'src/app/services/functions/file.service';
|
|
|
|
|
import { readAndCompressImage } from 'browser-image-resizer';
|
2023-10-31 10:09:12 +01:00
|
|
|
import { FilePicker } from '@capawesome/capacitor-file-picker';
|
2024-01-26 05:59:14 +01:00
|
|
|
import { CapacitorVideoPlayer } from 'capacitor-video-player';
|
|
|
|
|
import { CaptureError, CaptureImageOptions, MediaCapture, MediaFile } from '@awesome-cordova-plugins/media-capture/ngx';
|
2023-11-06 09:07:04 +01:00
|
|
|
import { Capacitor } from '@capacitor/core';
|
2024-03-26 12:03:30 +01:00
|
|
|
import { File as IonicFile } from '@ionic-native/file/ngx';
|
2023-11-10 15:37:12 +01:00
|
|
|
import { Media } from '@ionic-native/media/ngx';
|
2023-11-20 14:12:32 +01:00
|
|
|
import { checkFileTypeService } from 'src/app/services/checkFileType.service';
|
2023-11-09 11:45:04 +01:00
|
|
|
import { FileValidatorService } from "src/app/services/file/file-validator.service"
|
2024-02-05 10:29:42 +01:00
|
|
|
import { App } from '@capacitor/app';
|
2024-03-01 19:13:43 +01:00
|
|
|
import { NavigationExtras, Router } from '@angular/router';
|
2024-03-01 14:37:42 +01:00
|
|
|
import { VideoconvertService } from 'src/app/services/videoconvert.service'
|
2024-03-26 12:03:30 +01:00
|
|
|
import { PublicationAttachmentEntity } from 'src/app/shared/publication/upload/upload-streaming.service';
|
|
|
|
|
import { PublicationFromMvService } from "src/app/shared/publication/upload/publication-from-mv.service"
|
|
|
|
|
import { File } from '../../../models/chatMethod';
|
2024-03-27 10:21:54 +01:00
|
|
|
import { CropImagePage } from 'src/app/modals/crop-image/crop-image.page';
|
2024-02-27 13:04:23 +01:00
|
|
|
|
2023-08-23 17:19:22 +01:00
|
|
|
const config = {
|
|
|
|
|
quality: 0.5,
|
|
|
|
|
maxWidth: 800,
|
|
|
|
|
maxHeight: 600,
|
|
|
|
|
debug: true
|
|
|
|
|
};
|
2021-11-16 13:07:55 +01:00
|
|
|
const IMAGE_DIR = 'stored-images';
|
2023-10-31 10:09:12 +01:00
|
|
|
/* const { VideoRecorder } = Plugin; */
|
2021-11-16 13:07:55 +01:00
|
|
|
|
|
|
|
|
interface LocalFile {
|
|
|
|
|
name: string;
|
|
|
|
|
path: string;
|
|
|
|
|
data: string;
|
|
|
|
|
}
|
2023-10-31 10:09:12 +01:00
|
|
|
|
2023-11-06 13:33:35 +01:00
|
|
|
/* const config_video: VideoRecorderPreviewFrame = {
|
2023-10-31 10:09:12 +01:00
|
|
|
id: 'video-record',
|
|
|
|
|
stackPosition: 'front', // 'front' overlays your app', 'back' places behind your app.
|
|
|
|
|
width: 'fill',
|
|
|
|
|
height: 'fill',
|
|
|
|
|
x: 0,
|
|
|
|
|
y: 0,
|
|
|
|
|
borderRadius: 0
|
2023-11-06 13:33:35 +01:00
|
|
|
}; */
|
2020-12-01 14:03:15 +01:00
|
|
|
@Component({
|
|
|
|
|
selector: 'app-new-publication',
|
|
|
|
|
templateUrl: './new-publication.page.html',
|
|
|
|
|
styleUrls: ['./new-publication.page.scss'],
|
|
|
|
|
})
|
2023-10-31 10:09:12 +01:00
|
|
|
|
|
|
|
|
|
2020-12-01 14:03:15 +01:00
|
|
|
export class NewPublicationPage implements OnInit {
|
2021-11-16 13:07:55 +01:00
|
|
|
images: LocalFile[] = [];
|
2021-07-06 16:18:00 +01:00
|
|
|
|
|
|
|
|
// date picker
|
|
|
|
|
public date: any;
|
|
|
|
|
public disabled = false;
|
|
|
|
|
public showSpinners = true;
|
|
|
|
|
public showSeconds = false;
|
|
|
|
|
public touchUi = false;
|
|
|
|
|
public enableMeridian = false;
|
2021-11-16 14:06:30 +01:00
|
|
|
public minDate = new Date().toISOString().slice(0, 10)
|
2021-07-06 16:18:00 +01:00
|
|
|
public endMinDate = new Date(new Date().getTime() + 15 * 60000);
|
|
|
|
|
public stepHour = 1;
|
2023-01-24 15:56:47 +01:00
|
|
|
public stepMinute = 15;
|
2021-07-06 16:18:00 +01:00
|
|
|
public stepSecond = 5;
|
|
|
|
|
public color: ThemePalette = 'primary';
|
|
|
|
|
|
|
|
|
|
Form: FormGroup;
|
|
|
|
|
validateFrom = false
|
|
|
|
|
|
2020-12-15 19:37:42 +01:00
|
|
|
showLoader: boolean;
|
2020-12-10 11:22:06 +01:00
|
|
|
folderId: string;
|
|
|
|
|
image: Image = new Image();
|
2020-12-09 12:10:19 +01:00
|
|
|
|
2021-11-16 14:06:30 +01:00
|
|
|
publicationType: string;
|
|
|
|
|
publicationTitle: string;
|
|
|
|
|
imgUrl: any;
|
2020-12-09 12:10:19 +01:00
|
|
|
|
2021-11-16 14:06:30 +01:00
|
|
|
Defaultimage: any = '';
|
2020-12-10 11:22:06 +01:00
|
|
|
|
2020-12-09 12:10:19 +01:00
|
|
|
photo: SafeResourceUrl;
|
|
|
|
|
|
2021-11-16 14:06:30 +01:00
|
|
|
guestPicture: any;
|
2020-12-09 12:10:19 +01:00
|
|
|
|
2021-11-16 14:06:30 +01:00
|
|
|
capturedImage: any = '';
|
2023-10-31 10:09:12 +01:00
|
|
|
capturedVideo: any = '';
|
2021-11-16 14:06:30 +01:00
|
|
|
capturedImageTitle: any;
|
2021-11-09 10:13:48 +01:00
|
|
|
public photos: any[] = [];
|
2023-08-11 16:14:25 +01:00
|
|
|
pictureExiste = false
|
2020-12-11 18:00:38 +01:00
|
|
|
|
2021-11-26 14:46:08 +01:00
|
|
|
imgResultBeforeCompress: string;
|
|
|
|
|
imgResultAfterCompress: string;
|
2022-01-05 12:54:46 +01:00
|
|
|
convertBlobToBase64Worker;
|
2023-10-25 09:08:49 +01:00
|
|
|
intent: any;
|
2023-10-31 10:09:12 +01:00
|
|
|
video: any;
|
|
|
|
|
photoOrVideo: boolean = false;
|
|
|
|
|
fileType = "";
|
2023-11-06 09:07:04 +01:00
|
|
|
filecontent: boolean;
|
2023-11-20 14:12:32 +01:00
|
|
|
// Set a limit for the number of images to display
|
|
|
|
|
displayLimit = 4;
|
2023-12-06 17:01:00 +01:00
|
|
|
filesSizeSum = 0;
|
2021-11-26 14:46:08 +01:00
|
|
|
|
2020-12-01 17:22:45 +01:00
|
|
|
constructor(
|
|
|
|
|
private modalController: ModalController,
|
2020-12-11 15:09:53 +01:00
|
|
|
public photoService: PhotoService,
|
2020-12-01 17:22:45 +01:00
|
|
|
private navParams: NavParams,
|
2020-12-09 12:10:19 +01:00
|
|
|
private publications: PublicationsService,
|
2021-06-29 14:16:49 +01:00
|
|
|
private toastService: ToastService,
|
2021-11-16 13:07:55 +01:00
|
|
|
public ThemeService: ThemeService,
|
|
|
|
|
private platform: Platform,
|
|
|
|
|
private loadingCtrl: LoadingController,
|
2021-11-30 12:30:58 +01:00
|
|
|
public imageCompress: NgxImageCompressService,
|
2023-08-18 17:37:11 +01:00
|
|
|
private httpErrorHandle: HttpErrorHandle,
|
2023-08-22 11:25:13 +01:00
|
|
|
public PublicationFolderService: PublicationFolderService,
|
|
|
|
|
private RouteService: RouteService,
|
2023-10-31 10:09:12 +01:00
|
|
|
public FileService: FileService,
|
2023-11-20 14:12:32 +01:00
|
|
|
private mediaCapture: MediaCapture,
|
2023-11-29 16:06:56 +01:00
|
|
|
public checkFileType: checkFileTypeService,
|
2024-02-05 10:29:42 +01:00
|
|
|
private FileValidatorService: FileValidatorService,
|
|
|
|
|
private router: Router,
|
2024-03-26 12:03:30 +01:00
|
|
|
private videoconvertService: VideoconvertService,
|
|
|
|
|
public PublicationFromMvService: PublicationFromMvService,
|
2021-11-16 14:06:30 +01:00
|
|
|
) {
|
2021-11-09 10:13:48 +01:00
|
|
|
|
2021-11-16 14:06:30 +01:00
|
|
|
this.publicationType = this.navParams.get('publicationType');
|
|
|
|
|
this.folderId = this.navParams.get('folderId');
|
2024-03-26 12:03:30 +01:00
|
|
|
const publication = this.navParams.get('publication');
|
|
|
|
|
if (publication && typeof publication?.Files == 'object') {
|
2023-11-29 12:17:52 +01:00
|
|
|
this.filecontent = true;
|
2024-03-26 12:03:30 +01:00
|
|
|
|
|
|
|
|
const newFiles: PublicationAttachmentEntity[] = publication.Files.map(e => {
|
|
|
|
|
return new PublicationAttachmentEntity(
|
|
|
|
|
{
|
|
|
|
|
base64: e.FileBase64,
|
|
|
|
|
extension: e.FileExtension,
|
|
|
|
|
OriginalFileName: e.OriginalFileName,
|
|
|
|
|
FileType: this.checkFileType.checkFileType(e.FileExtension) as any
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
2024-03-27 10:21:54 +01:00
|
|
|
for (const files of newFiles) {
|
2024-03-26 12:03:30 +01:00
|
|
|
this.PublicationFromMvService.form.Files.push(files)
|
|
|
|
|
}
|
2023-11-29 12:17:52 +01:00
|
|
|
}
|
2024-03-26 12:03:30 +01:00
|
|
|
|
|
|
|
|
|
2021-11-16 14:06:30 +01:00
|
|
|
this.publicationTitle = 'Nova Publicação';
|
2023-10-25 09:08:49 +01:00
|
|
|
this.intent = this.navParams.get('intent');
|
2022-01-05 12:54:46 +01:00
|
|
|
|
|
|
|
|
this.convertBlobToBase64Worker = new Worker(new URL('./convertBlobToBase64.worker.js', import.meta.url));
|
2024-03-26 12:03:30 +01:00
|
|
|
this.PublicationFromMvService.clear()
|
2021-11-16 14:06:30 +01:00
|
|
|
}
|
2020-12-01 14:03:15 +01:00
|
|
|
|
|
|
|
|
ngOnInit() {
|
2023-11-29 12:17:52 +01:00
|
|
|
this.reciveSharedContent();
|
2023-10-25 09:08:49 +01:00
|
|
|
|
2020-12-01 17:22:45 +01:00
|
|
|
this.setTitle();
|
2021-11-16 13:07:55 +01:00
|
|
|
Filesystem.mkdir({
|
|
|
|
|
path: IMAGE_DIR,
|
|
|
|
|
directory: Directory.Data,
|
|
|
|
|
recursive: true
|
|
|
|
|
});
|
2021-11-09 12:21:23 +01:00
|
|
|
|
2024-02-27 13:04:23 +01:00
|
|
|
/* 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) {
|
|
|
|
|
console.log('click butto', error)
|
|
|
|
|
} */
|
2020-12-01 17:22:45 +01:00
|
|
|
}
|
2021-07-06 16:18:00 +01:00
|
|
|
|
2023-08-23 17:19:22 +01:00
|
|
|
// in use
|
2021-11-16 14:06:30 +01:00
|
|
|
async takePicture() {
|
2021-12-13 09:51:57 +01:00
|
|
|
const capturedImage = await Camera.getPhoto({
|
2023-03-09 16:55:31 +01:00
|
|
|
quality: 50,
|
2021-12-13 09:51:57 +01:00
|
|
|
// allowEditing: true,
|
2023-08-28 16:36:31 +01:00
|
|
|
resultType: CameraResultType.Base64,
|
2021-12-13 09:51:57 +01:00
|
|
|
source: CameraSource.Camera
|
2021-02-09 13:16:41 +01:00
|
|
|
});
|
2023-10-31 10:09:12 +01:00
|
|
|
this.capturedImage = 'data:image/jpeg;base64,' + capturedImage.base64String;
|
|
|
|
|
this.capturedImageTitle = 'foto';
|
2024-03-27 10:21:54 +01:00
|
|
|
this.showCroppModal();
|
2023-10-31 15:13:19 +01:00
|
|
|
|
2023-10-31 10:09:12 +01:00
|
|
|
}
|
2021-11-09 10:13:48 +01:00
|
|
|
|
2023-10-31 10:09:12 +01:00
|
|
|
async laodPicture() {
|
|
|
|
|
const capturedImage = await Camera.getPhoto({
|
|
|
|
|
quality: 90,
|
|
|
|
|
resultType: CameraResultType.Base64,
|
|
|
|
|
source: CameraSource.Photos
|
|
|
|
|
});
|
2023-08-28 16:36:31 +01:00
|
|
|
|
2023-10-31 10:09:12 +01:00
|
|
|
this.capturedImage = 'data:image/jpeg;base64,' + capturedImage.base64String;
|
|
|
|
|
this.capturedImageTitle = 'foto';
|
|
|
|
|
|
|
|
|
|
const compressedImage = await this.compressImageBase64(
|
|
|
|
|
this.capturedImage,
|
|
|
|
|
800, // maxWidth
|
|
|
|
|
800, // maxHeight
|
|
|
|
|
0.9 // quality
|
|
|
|
|
).then((picture) => {
|
|
|
|
|
console.log('Selected: ', picture)
|
|
|
|
|
this.capturedImage = picture
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
2022-01-05 12:54:46 +01:00
|
|
|
|
2023-10-31 10:09:12 +01:00
|
|
|
async startVideoRecording() {
|
|
|
|
|
try {
|
2023-12-12 10:11:48 +01:00
|
|
|
let options: CaptureImageOptions = { limit: 1 }
|
2023-11-29 12:17:52 +01:00
|
|
|
const data: any = await this.mediaCapture.captureVideo(options)
|
2023-11-06 16:28:10 +01:00
|
|
|
this.video = data[0];
|
2024-02-27 13:04:23 +01:00
|
|
|
console.log('video record', data)
|
2023-11-29 12:17:52 +01:00
|
|
|
data.forEach(async element => {
|
2023-12-06 17:01:00 +01:00
|
|
|
this.filesSizeSum = this.filesSizeSum + element.size
|
2024-03-26 13:58:09 +01:00
|
|
|
// element.size
|
|
|
|
|
try {
|
2024-03-27 10:21:54 +01:00
|
|
|
if (this.platform.is('ios')) {
|
|
|
|
|
this.recordevideoIos(element.fullPath, element)
|
|
|
|
|
} else {
|
|
|
|
|
this.recordVideoAndroid(element.fullPath, element)
|
|
|
|
|
}
|
2023-11-29 12:17:52 +01:00
|
|
|
|
2024-03-27 10:21:54 +01:00
|
|
|
} catch (e) {
|
|
|
|
|
console.error('Unable to write file', e);
|
|
|
|
|
}
|
2024-03-26 13:58:09 +01:00
|
|
|
|
|
|
|
|
|
2023-11-13 10:59:36 +01:00
|
|
|
});
|
2023-11-10 15:37:12 +01:00
|
|
|
} catch (error) {
|
|
|
|
|
console.log('record video error: ', error)
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-06 13:33:35 +01:00
|
|
|
|
2024-03-26 12:03:30 +01:00
|
|
|
async loadVideo() {
|
2024-03-27 10:21:54 +01:00
|
|
|
const result = await FilePicker.pickMedia({ multiple: true, });
|
2024-03-26 12:03:30 +01:00
|
|
|
console.log(result.files)
|
|
|
|
|
result.files.forEach(async element => {
|
|
|
|
|
this.filesSizeSum = this.filesSizeSum + element.size
|
|
|
|
|
if (this.fileSizeToMB(this.filesSizeSum) <= 20) {
|
|
|
|
|
console.log('pass size verificartion')
|
2024-03-11 16:05:59 +01:00
|
|
|
if (this.checkFileType.checkFileType(element.mimeType) == 'video' && this.platform.is('ios')) {
|
2024-03-27 10:21:54 +01:00
|
|
|
let resultUrl = decodeURIComponent(element.path); console.log('pass type verification ', resultUrl)
|
|
|
|
|
try {
|
2024-03-26 12:03:30 +01:00
|
|
|
this.recordevideoIos(resultUrl, element)
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.log('upload video error: ', error)
|
|
|
|
|
}
|
|
|
|
|
} else if (this.checkFileType.checkFileType(element.mimeType) == 'image' || this.checkFileType.checkFileType(element.mimeType) == 'video') {
|
2023-12-06 17:01:00 +01:00
|
|
|
let resultUrl = decodeURIComponent(element.path);
|
2024-03-27 10:21:54 +01:00
|
|
|
console.log('pass type verification ', resultUrl)
|
|
|
|
|
try {
|
|
|
|
|
this.loadVideoAndroid(resultUrl, element)
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.log('upload video error: ', error)
|
2024-03-26 12:03:30 +01:00
|
|
|
}
|
|
|
|
|
}
|
2024-03-27 10:21:54 +01:00
|
|
|
} else {
|
|
|
|
|
if (this.PublicationFromMvService.form.Files.length === 0)
|
|
|
|
|
this.filesSizeSum = 0
|
|
|
|
|
|
|
|
|
|
this.httpErrorHandle.validationMessagge('filessize')
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
2023-10-31 10:09:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
chossePhotoOrVideo() {
|
2023-10-31 15:13:19 +01:00
|
|
|
this.photoOrVideo = !this.photoOrVideo
|
2023-10-31 10:09:12 +01:00
|
|
|
}
|
|
|
|
|
|
2021-11-23 16:05:32 +01:00
|
|
|
|
2021-11-26 14:46:08 +01:00
|
|
|
imageSize(image) {
|
|
|
|
|
var canvas = document.createElement('canvas');
|
|
|
|
|
var ctx = canvas.getContext('2d');
|
|
|
|
|
canvas.width = 100
|
|
|
|
|
canvas.height = 34
|
2023-03-09 16:55:31 +01:00
|
|
|
ctx.drawImage(image, 0, 0);
|
2021-11-26 14:46:08 +01:00
|
|
|
document.body.appendChild(canvas);
|
2021-11-22 13:53:37 +01:00
|
|
|
}
|
|
|
|
|
|
2021-11-09 10:13:48 +01:00
|
|
|
convertBlobToBase64 = (blob: Blob) => new Promise((resolve, reject) => {
|
|
|
|
|
const reader = new FileReader;
|
|
|
|
|
reader.onerror = reject;
|
|
|
|
|
reader.onload = () => {
|
2023-10-31 10:09:12 +01:00
|
|
|
resolve(reader.result);
|
2021-11-09 10:13:48 +01:00
|
|
|
};
|
|
|
|
|
reader.readAsDataURL(blob);
|
2023-10-31 10:09:12 +01:00
|
|
|
}).catch((error) => {
|
2022-12-20 17:06:19 +01:00
|
|
|
console.error(error);
|
2021-11-09 10:13:48 +01:00
|
|
|
});
|
|
|
|
|
|
2021-08-23 16:06:05 +01:00
|
|
|
|
2023-10-31 10:09:12 +01:00
|
|
|
/* // in use
|
|
|
|
|
async laodPicture() {
|
2024-01-31 17:12:01 +01:00
|
|
|
|
2023-10-31 10:09:12 +01:00
|
|
|
const capturedImage = await Camera.getPhoto({
|
|
|
|
|
quality: 90,
|
|
|
|
|
// allowEditing: true,
|
|
|
|
|
resultType: CameraResultType.Uri,
|
|
|
|
|
source: CameraSource.Photos
|
|
|
|
|
});
|
2024-01-31 17:12:01 +01:00
|
|
|
|
2023-10-31 10:09:12 +01:00
|
|
|
const response = await fetch(capturedImage.webPath!);
|
|
|
|
|
const blob = await response.blob();
|
2024-01-31 17:12:01 +01:00
|
|
|
|
2023-10-31 10:09:12 +01:00
|
|
|
this.convertBlobToBase64Worker.postMessage(blob);
|
|
|
|
|
this.convertBlobToBase64Worker.onmessage = async (oEvent)=> {
|
|
|
|
|
this.capturedImage = oEvent.data
|
|
|
|
|
this.capturedImageTitle = 'foto'
|
2024-01-31 17:12:01 +01:00
|
|
|
|
2023-10-31 10:09:12 +01:00
|
|
|
}
|
2024-01-31 17:12:01 +01:00
|
|
|
|
2023-10-31 10:09:12 +01:00
|
|
|
} */
|
2021-08-23 16:06:05 +01:00
|
|
|
|
2021-07-06 16:18:00 +01:00
|
|
|
|
2020-12-09 12:10:19 +01:00
|
|
|
|
2021-07-06 16:18:00 +01:00
|
|
|
runValidation() {
|
2021-11-16 14:06:30 +01:00
|
|
|
this.validateFrom = true
|
2021-07-06 16:18:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
injectValidation() {
|
|
|
|
|
|
|
|
|
|
this.Form = new FormGroup({
|
2024-03-26 12:03:30 +01:00
|
|
|
Subject: new FormControl(this.PublicationFromMvService.form.Title, [
|
2023-02-27 09:34:36 +01:00
|
|
|
Validators.required,
|
2021-07-06 16:18:00 +01:00
|
|
|
// Validators.minLength(4)
|
|
|
|
|
]),
|
|
|
|
|
capturedImage: new FormControl(this.capturedImage, [
|
|
|
|
|
|
|
|
|
|
]),
|
2024-03-26 12:03:30 +01:00
|
|
|
Message: new FormControl(this.PublicationFromMvService.form.Message, [
|
2023-02-27 09:34:36 +01:00
|
|
|
Validators.required,
|
2021-07-15 15:41:19 +01:00
|
|
|
Validators.maxLength(1000)
|
2021-07-15 15:39:10 +01:00
|
|
|
|
2021-07-06 16:18:00 +01:00
|
|
|
])
|
|
|
|
|
})
|
|
|
|
|
}
|
2021-11-09 10:13:48 +01:00
|
|
|
|
2021-07-06 16:18:00 +01:00
|
|
|
async save() {
|
2021-11-09 10:13:48 +01:00
|
|
|
|
2021-07-06 16:18:00 +01:00
|
|
|
this.injectValidation()
|
|
|
|
|
this.runValidation()
|
|
|
|
|
|
2021-11-16 14:06:30 +01:00
|
|
|
if (this.Form.invalid) return false
|
2021-07-06 16:18:00 +01:00
|
|
|
|
2021-11-09 10:13:48 +01:00
|
|
|
|
2024-03-26 12:03:30 +01:00
|
|
|
if (this.PublicationFromMvService.form.Files.length != 0) {
|
2021-06-29 14:16:49 +01:00
|
|
|
|
2024-04-01 12:18:25 +01:00
|
|
|
if (!window["sharedContent"]) {
|
|
|
|
|
this.close();
|
2024-04-01 15:59:18 +01:00
|
|
|
} else {
|
|
|
|
|
alert('dont close')
|
2024-04-01 12:18:25 +01:00
|
|
|
}
|
|
|
|
|
|
2024-04-01 15:59:18 +01:00
|
|
|
this.PublicationFromMvService.publicationType = this.publicationType as any
|
2024-03-26 12:03:30 +01:00
|
|
|
this.PublicationFromMvService.setFolderId(this.folderId)
|
|
|
|
|
await this.PublicationFromMvService.save()
|
2023-08-23 09:55:14 +01:00
|
|
|
|
2024-02-02 12:05:42 +01:00
|
|
|
} else {
|
|
|
|
|
this.httpErrorHandle.validationMessagge("noFileSelected")
|
|
|
|
|
}
|
2020-12-01 17:22:45 +01:00
|
|
|
}
|
2020-12-09 12:10:19 +01:00
|
|
|
|
2024-03-26 12:03:30 +01:00
|
|
|
ngOnDestroy() {
|
|
|
|
|
// if(!this.PublicationFromMvService.form.send) {
|
|
|
|
|
// this.PublicationFromMvService.cancel()
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-09 12:10:19 +01:00
|
|
|
|
2021-07-06 16:18:00 +01:00
|
|
|
close() {
|
2024-04-01 15:59:18 +01:00
|
|
|
alert('close');
|
2024-03-26 12:03:30 +01:00
|
|
|
this.modalController.dismiss(this.PublicationFromMvService.form).then(() => {
|
2021-11-16 14:06:30 +01:00
|
|
|
this.showLoader = true;
|
2020-12-15 19:37:42 +01:00
|
|
|
});
|
2020-12-01 17:22:45 +01:00
|
|
|
}
|
2021-11-09 10:13:48 +01:00
|
|
|
|
2021-07-06 16:18:00 +01:00
|
|
|
clear() {
|
2023-08-22 15:43:20 +01:00
|
|
|
this.capturedImageTitle = null;
|
2024-03-26 12:03:30 +01:00
|
|
|
this.PublicationFromMvService.form.Files = [];
|
2020-12-11 15:09:53 +01:00
|
|
|
}
|
2021-07-06 16:18:00 +01:00
|
|
|
|
|
|
|
|
setTitle() {
|
2021-11-16 14:06:30 +01:00
|
|
|
if (this.publicationType == '1') {
|
2020-12-10 11:22:06 +01:00
|
|
|
this.publicationTitle = 'Nova Publicação Rápida';
|
2020-12-01 17:22:45 +01:00
|
|
|
}
|
2021-11-16 14:06:30 +01:00
|
|
|
else if (this.publicationType == '2') {
|
2020-12-10 11:22:06 +01:00
|
|
|
this.publicationTitle = 'Nova Publicação';
|
2020-12-01 17:22:45 +01:00
|
|
|
}
|
2021-11-16 14:06:30 +01:00
|
|
|
else if (this.publicationType == '3') {
|
2020-12-09 12:10:19 +01:00
|
|
|
this.publicationTitle = 'Editar Publicação';
|
2023-10-31 10:09:12 +01:00
|
|
|
|
2020-12-02 15:08:45 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-16 13:07:55 +01:00
|
|
|
|
2021-11-22 13:53:37 +01:00
|
|
|
|
2021-11-26 14:46:08 +01:00
|
|
|
compressFile() {
|
|
|
|
|
|
2021-12-08 19:39:30 +01:00
|
|
|
//this.imgResultBeforeCompress = image;s
|
2021-11-26 14:46:08 +01:00
|
|
|
this.imageCompress.getOrientation(this.capturedImage).then((orientation) => {
|
2023-10-31 10:09:12 +01:00
|
|
|
|
2021-12-08 19:39:30 +01:00
|
|
|
this.imageCompress.compressFile(this.capturedImage, orientation, 90, 90).then(
|
2021-11-26 14:46:08 +01:00
|
|
|
result => {
|
|
|
|
|
this.capturedImage = result;
|
2023-10-31 10:09:12 +01:00
|
|
|
|
2021-11-26 14:46:08 +01:00
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-08-15 10:15:08 +01:00
|
|
|
deletePublicationImage() {
|
2024-03-26 12:03:30 +01:00
|
|
|
this.PublicationFromMvService.form.Files = []
|
2023-08-15 10:15:08 +01:00
|
|
|
}
|
2023-08-28 16:36:31 +01:00
|
|
|
|
|
|
|
|
async compressImageBase64(base64String: string, maxWidth: number, maxHeight: number, quality: number): Promise<string> {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
const image = new (window as any).Image();
|
|
|
|
|
image.src = base64String;
|
2023-10-31 10:09:12 +01:00
|
|
|
|
2023-08-28 16:36:31 +01:00
|
|
|
image.onload = async () => {
|
|
|
|
|
const canvas = document.createElement('canvas');
|
|
|
|
|
let newWidth = image.width;
|
|
|
|
|
let newHeight = image.height;
|
2023-10-31 10:09:12 +01:00
|
|
|
|
2023-08-28 16:36:31 +01:00
|
|
|
if (newWidth > maxWidth) {
|
|
|
|
|
newHeight *= maxWidth / newWidth;
|
|
|
|
|
newWidth = maxWidth;
|
|
|
|
|
}
|
2023-10-31 10:09:12 +01:00
|
|
|
|
2023-08-28 16:36:31 +01:00
|
|
|
if (newHeight > maxHeight) {
|
|
|
|
|
newWidth *= maxHeight / newHeight;
|
|
|
|
|
newHeight = maxHeight;
|
|
|
|
|
}
|
2023-10-31 10:09:12 +01:00
|
|
|
|
2023-08-28 16:36:31 +01:00
|
|
|
canvas.width = newWidth;
|
|
|
|
|
canvas.height = newHeight;
|
2023-10-31 10:09:12 +01:00
|
|
|
|
2023-08-28 16:36:31 +01:00
|
|
|
const context = canvas.getContext('2d');
|
|
|
|
|
context?.drawImage(image, 0, 0, newWidth, newHeight);
|
2023-10-31 10:09:12 +01:00
|
|
|
|
2023-08-28 16:36:31 +01:00
|
|
|
const compressedBase64 = canvas.toDataURL('image/jpeg', quality);
|
|
|
|
|
resolve(compressedBase64);
|
|
|
|
|
};
|
2023-10-31 10:09:12 +01:00
|
|
|
|
2023-08-28 16:36:31 +01:00
|
|
|
image.onerror = (error) => {
|
|
|
|
|
reject(error);
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
}
|
2023-10-31 10:09:12 +01:00
|
|
|
|
2023-11-06 13:33:35 +01:00
|
|
|
_getBase64(file) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
var reader = new FileReader();
|
|
|
|
|
reader.readAsDataURL(file);
|
|
|
|
|
reader.onload = function () {
|
|
|
|
|
resolve(reader.result)
|
|
|
|
|
};
|
|
|
|
|
reader.onerror = function (error) {
|
|
|
|
|
console.log('Error: ', error);
|
|
|
|
|
};
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-10 15:37:12 +01:00
|
|
|
|
2023-11-06 13:33:35 +01:00
|
|
|
async copyVideoToDataDirectory(videoFile: any): Promise<string | null> {
|
|
|
|
|
try {
|
|
|
|
|
const { uri } = videoFile;
|
|
|
|
|
const fileName = uri.substring(uri.lastIndexOf('/') + 1);
|
|
|
|
|
const targetPath = Directory.Data + fileName; // Set your target directory path
|
2023-11-10 15:37:12 +01:00
|
|
|
|
2023-11-06 13:33:35 +01:00
|
|
|
await Filesystem.copy({
|
|
|
|
|
from: uri,
|
|
|
|
|
to: targetPath,
|
|
|
|
|
});
|
2023-11-10 15:37:12 +01:00
|
|
|
|
2023-11-06 13:33:35 +01:00
|
|
|
return targetPath;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(error);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-10 15:37:12 +01:00
|
|
|
|
2023-11-06 13:33:35 +01:00
|
|
|
async convertVideoToBase64(videoPath: string): Promise<string | null> {
|
|
|
|
|
try {
|
|
|
|
|
const file = await Filesystem.readFile({ path: videoPath, directory: FilesystemDirectory.Data });
|
|
|
|
|
if (file.data) {
|
|
|
|
|
return 'data:video/mp4;base64,' + file.data;
|
|
|
|
|
} else {
|
|
|
|
|
throw new Error('Failed to read the video file.');
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(error);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-10 15:37:12 +01:00
|
|
|
|
|
|
|
|
async copyAndReadFile(filePath: string): Promise<string> {
|
|
|
|
|
try {
|
|
|
|
|
// Copy the file to the app's data directory
|
|
|
|
|
const copyResult = await Filesystem.copy({
|
|
|
|
|
from: filePath,
|
|
|
|
|
to: '20231110_125118.mp4', // or any desired name
|
|
|
|
|
directory: Directory.Data,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const copiedFilePath = copyResult.uri; // Use 'uri' instead of 'to'
|
|
|
|
|
|
|
|
|
|
// Read the copied file as base64
|
|
|
|
|
const readResult = await Filesystem.readFile({
|
|
|
|
|
path: copiedFilePath,
|
|
|
|
|
directory: Directory.Data,
|
|
|
|
|
encoding: Encoding.UTF8,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const base64Data = readResult.data;
|
|
|
|
|
console.log('Base64 data:', base64Data);
|
|
|
|
|
|
|
|
|
|
return base64Data;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('Error copying/reading file:', error);
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-29 12:17:52 +01:00
|
|
|
removeTextBeforeSlash(inputString, controlString) {
|
|
|
|
|
if (inputString.includes(controlString)) {
|
|
|
|
|
const parts = inputString.split(controlString);
|
|
|
|
|
return parts.length > 1 ? parts[1] : inputString;
|
|
|
|
|
} else {
|
|
|
|
|
return inputString;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-06 13:33:35 +01:00
|
|
|
|
2023-11-29 12:17:52 +01:00
|
|
|
reciveSharedContent() {
|
|
|
|
|
if (this.intent) {
|
|
|
|
|
this.filecontent = true
|
|
|
|
|
console.log(this.intent)
|
|
|
|
|
let filesArray = [];
|
|
|
|
|
let fistFile = {
|
|
|
|
|
title: this.intent.title,
|
|
|
|
|
type: this.intent.type,
|
|
|
|
|
url: this.intent.url
|
|
|
|
|
}
|
2024-01-26 05:59:14 +01:00
|
|
|
if (this.intent?.additionalItems) {
|
2023-12-06 17:01:00 +01:00
|
|
|
filesArray = this.intent?.additionalItems;
|
|
|
|
|
}
|
2023-11-29 12:17:52 +01:00
|
|
|
filesArray.push(fistFile)
|
|
|
|
|
filesArray.forEach(element => {
|
|
|
|
|
let FileExtension = this.removeTextBeforeSlash(element.title, '.')
|
|
|
|
|
if (this.checkFileType.checkFileType(FileExtension) == 'image' || this.checkFileType.checkFileType(FileExtension) == 'video') {
|
|
|
|
|
let resultUrl = decodeURIComponent(element.url);
|
2024-03-03 09:19:34 +01:00
|
|
|
|
2024-03-21 17:06:36 +01:00
|
|
|
if (this.platform.is('ios')) {
|
2024-03-03 09:28:05 +01:00
|
|
|
const stringGerada = this.gerarStringAleatoria();
|
2024-03-21 17:06:36 +01:00
|
|
|
console.log(stringGerada);
|
|
|
|
|
this.shareContentIso(resultUrl, FileExtension, stringGerada)
|
2024-03-03 09:19:34 +01:00
|
|
|
} else {
|
2024-03-21 17:06:36 +01:00
|
|
|
this.shareContentAndroid(resultUrl, FileExtension)
|
2024-03-03 09:19:34 +01:00
|
|
|
}
|
|
|
|
|
|
2024-03-21 17:06:36 +01:00
|
|
|
/*
|
|
|
|
|
Filesystem.readFile({ path: resultUrl }).then(async (content) => {
|
|
|
|
|
let fileObject;
|
|
|
|
|
try {
|
|
|
|
|
if (this.checkFileType.checkFileType(FileExtension) == 'image') {
|
|
|
|
|
fileObject = {
|
|
|
|
|
FileBase64: this.removeTextBeforeSlash(content.data, ','),
|
|
|
|
|
FileExtension: FileExtension,
|
|
|
|
|
OriginalFileName: 'shared',
|
|
|
|
|
}
|
2024-03-26 13:58:09 +01:00
|
|
|
|
2024-03-21 17:06:36 +01:00
|
|
|
} else if (this.checkFileType.checkFileType(FileExtension) == 'video') {
|
|
|
|
|
fileObject = {
|
|
|
|
|
FileBase64: 'data:video/mp4;base64,' + this.removeTextBeforeSlash(content.data, ','),
|
|
|
|
|
FileExtension: FileExtension,
|
|
|
|
|
OriginalFileName: 'shared',
|
|
|
|
|
}
|
2024-03-26 13:58:09 +01:00
|
|
|
|
2024-03-21 17:06:36 +01:00
|
|
|
}
|
|
|
|
|
console.log('shared base', content.data)
|
2024-03-26 13:58:09 +01:00
|
|
|
|
2024-03-21 17:06:36 +01:00
|
|
|
this.seletedContent.push(fileObject)
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.log('error shared filesystem', error)
|
|
|
|
|
}
|
2024-03-26 13:58:09 +01:00
|
|
|
|
2024-03-21 17:06:36 +01:00
|
|
|
}) */
|
2023-11-29 12:17:52 +01:00
|
|
|
} else {
|
|
|
|
|
this.httpErrorHandle.validationMessagge('filetype');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-13 10:59:36 +01:00
|
|
|
|
|
|
|
|
|
2023-12-06 17:01:00 +01:00
|
|
|
fileSizeToMB(sizeInBytes) {
|
|
|
|
|
var sizeInMB = (sizeInBytes / (1024 * 1024)).toFixed(2);
|
|
|
|
|
console.log(sizeInMB + 'MB');
|
|
|
|
|
return parseInt(sizeInMB)
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-26 05:59:14 +01:00
|
|
|
deleteFromSeletedContent(index) {
|
2024-03-26 12:03:30 +01:00
|
|
|
this.PublicationFromMvService.form.Files.splice(index, 1)
|
2023-12-12 10:11:48 +01:00
|
|
|
}
|
2023-12-06 17:01:00 +01:00
|
|
|
|
2024-02-05 10:29:42 +01:00
|
|
|
|
2024-03-26 12:03:30 +01:00
|
|
|
async recordevideoIos(fullPath, element) {
|
|
|
|
|
|
2024-03-01 14:37:42 +01:00
|
|
|
try {
|
2024-03-26 12:03:30 +01:00
|
|
|
const directory = await Filesystem.getUri({
|
|
|
|
|
directory: Directory.Cache,
|
|
|
|
|
path: '',
|
|
|
|
|
});
|
2024-03-01 14:37:42 +01:00
|
|
|
|
2024-03-26 12:03:30 +01:00
|
|
|
const stringGerada = this.gerarStringAleatoria();
|
2024-03-01 14:37:42 +01:00
|
|
|
|
2024-03-27 10:21:54 +01:00
|
|
|
this.videoconvertService.convertVideo(fullPath, directory.uri, stringGerada, 'mp4').then(async () => {
|
|
|
|
|
await Filesystem.readFile({ path: `${directory.uri}${stringGerada}.mp4` })
|
2024-03-26 12:03:30 +01:00
|
|
|
|
2024-03-27 10:21:54 +01:00
|
|
|
.then(async (content) => {
|
|
|
|
|
this.filecontent = true;
|
2024-03-26 12:03:30 +01:00
|
|
|
|
2024-03-27 10:21:54 +01:00
|
|
|
const file = new File([element.blob], element.name);
|
2024-03-26 12:03:30 +01:00
|
|
|
|
2024-03-27 10:21:54 +01:00
|
|
|
const newAttachment = new PublicationAttachmentEntity(
|
|
|
|
|
{
|
|
|
|
|
base64: 'data:video/mp4;base64,' + content.data,
|
|
|
|
|
extension: 'mp4',
|
|
|
|
|
blobFile: file,
|
|
|
|
|
FileType: this.checkFileType.checkFileType('mp4') as any,
|
|
|
|
|
OriginalFileName: 'load video'
|
|
|
|
|
}
|
|
|
|
|
)
|
2024-03-26 12:03:30 +01:00
|
|
|
|
2024-03-27 10:21:54 +01:00
|
|
|
this.PublicationFromMvService.form.Files.push(newAttachment)
|
2024-03-26 12:03:30 +01:00
|
|
|
|
2024-03-27 10:21:54 +01:00
|
|
|
const deleteSecretFile = async () => {
|
|
|
|
|
await Filesystem.deleteFile({
|
|
|
|
|
path: `${stringGerada}.mp4`,
|
|
|
|
|
directory: Directory.Cache,
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
await deleteSecretFile().then((value) => {
|
|
|
|
|
console.log('delete file', value)
|
|
|
|
|
})
|
2024-03-26 12:03:30 +01:00
|
|
|
})
|
2024-03-27 10:21:54 +01:00
|
|
|
.catch((erro) => console.error('read converted video erro ', erro));
|
2024-03-26 12:03:30 +01:00
|
|
|
});
|
2024-03-01 14:37:42 +01:00
|
|
|
|
2024-03-11 10:23:33 +01:00
|
|
|
|
2024-03-26 12:03:30 +01:00
|
|
|
} catch (error) {
|
2024-03-01 14:37:42 +01:00
|
|
|
console.log('record video ios erro, ', error)
|
2024-03-26 12:03:30 +01:00
|
|
|
}
|
2024-03-01 14:37:42 +01:00
|
|
|
}
|
|
|
|
|
|
2024-03-26 12:03:30 +01:00
|
|
|
async recordVideoAndroid(fullPath, element) {
|
2024-03-02 16:46:28 +01:00
|
|
|
|
2024-03-01 14:37:42 +01:00
|
|
|
try {
|
2024-03-26 12:03:30 +01:00
|
|
|
const savedFile = await Filesystem.copy({
|
|
|
|
|
from: fullPath,
|
|
|
|
|
to: "video.mp4",
|
|
|
|
|
toDirectory: FilesystemDirectory.Data
|
|
|
|
|
});
|
|
|
|
|
console.log(savedFile.uri)
|
|
|
|
|
Filesystem.readFile({ path: savedFile.uri })
|
2024-03-01 14:37:42 +01:00
|
|
|
|
2024-03-27 10:21:54 +01:00
|
|
|
.then(async (content) => {
|
2024-03-26 12:03:30 +01:00
|
|
|
|
2024-03-27 10:21:54 +01:00
|
|
|
this.filecontent = true;
|
2024-03-26 12:03:30 +01:00
|
|
|
|
2024-03-27 10:21:54 +01:00
|
|
|
const file = new File([element.blob], element.name);
|
|
|
|
|
window['a'] = element
|
|
|
|
|
const newAttachment = new PublicationAttachmentEntity(
|
|
|
|
|
{
|
|
|
|
|
base64: 'data:video/mp4;base64,' + content.data,
|
|
|
|
|
extension: 'mp4',
|
|
|
|
|
blobFile: file,
|
|
|
|
|
FileType: this.checkFileType.checkFileType('mp4') as any,
|
|
|
|
|
OriginalFileName: 'load video'
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
this.PublicationFromMvService.form.Files.push(newAttachment)
|
2024-03-26 12:03:30 +01:00
|
|
|
|
|
|
|
|
|
2024-03-27 10:21:54 +01:00
|
|
|
})
|
|
|
|
|
.catch((error) => console.error('reade converted video erro ', error));
|
2024-03-01 14:37:42 +01:00
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.log('record video android erro ', error)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-02 16:46:28 +01:00
|
|
|
loadVideoIso() {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-21 17:06:36 +01:00
|
|
|
loadVideoAndroid(resultUrl, element) {
|
2024-03-02 16:46:28 +01:00
|
|
|
Filesystem.readFile({ path: resultUrl })
|
|
|
|
|
|
2024-03-27 10:21:54 +01:00
|
|
|
.then(async (content) => {
|
2024-03-26 12:03:30 +01:00
|
|
|
|
2024-03-27 10:21:54 +01:00
|
|
|
this.filecontent = true;
|
2024-03-26 12:03:30 +01:00
|
|
|
|
2024-03-27 10:21:54 +01:00
|
|
|
if (this.removeTextBeforeSlash(element.mimeType, '/') == "mp4") {
|
2024-03-26 12:03:30 +01:00
|
|
|
|
2024-03-27 10:21:54 +01:00
|
|
|
const newAttachment = new PublicationAttachmentEntity(
|
|
|
|
|
{
|
|
|
|
|
base64: content.data,
|
|
|
|
|
extension: this.removeTextBeforeSlash(element.mimeType, '/'),
|
|
|
|
|
FileType: this.checkFileType.checkFileType(this.removeTextBeforeSlash(element.mimeType, '/')) as any,
|
|
|
|
|
OriginalFileName: 'load video'
|
|
|
|
|
}
|
|
|
|
|
)
|
2024-03-26 12:03:30 +01:00
|
|
|
|
2024-03-27 10:21:54 +01:00
|
|
|
newAttachment.needUpload()
|
|
|
|
|
this.PublicationFromMvService.form.Files.push(newAttachment)
|
2024-03-26 12:03:30 +01:00
|
|
|
|
2024-03-27 10:21:54 +01:00
|
|
|
} else {
|
|
|
|
|
this.capturedImage = 'data:image/jpeg;base64,' + content.data;
|
|
|
|
|
this.showCroppModal()
|
|
|
|
|
/* const newAttachment = new PublicationAttachmentEntity(
|
|
|
|
|
{
|
|
|
|
|
base64: 'data:image/jpeg;base64,' + content.data,
|
|
|
|
|
extension: this.removeTextBeforeSlash(element.mimeType, '/'),
|
|
|
|
|
FileType: this.checkFileType.checkFileType(this.removeTextBeforeSlash(element.mimeType, '/')) as any,
|
|
|
|
|
OriginalFileName: 'image'
|
|
|
|
|
}
|
|
|
|
|
)
|
2024-03-26 12:03:30 +01:00
|
|
|
|
2024-03-27 10:21:54 +01:00
|
|
|
this.PublicationFromMvService.form.Files.push(newAttachment) */
|
|
|
|
|
}
|
2024-03-02 16:46:28 +01:00
|
|
|
|
2024-03-26 12:03:30 +01:00
|
|
|
|
2024-03-27 10:21:54 +01:00
|
|
|
})
|
|
|
|
|
.catch((err) => console.error(err));
|
2024-03-11 10:23:33 +01:00
|
|
|
|
2024-03-02 16:46:28 +01:00
|
|
|
}
|
|
|
|
|
|
2024-03-21 17:06:36 +01:00
|
|
|
gerarStringAleatoria() {
|
2024-03-03 09:25:04 +01:00
|
|
|
const caracteres = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
|
|
|
let stringAleatoria = '';
|
2024-03-11 10:23:33 +01:00
|
|
|
|
2024-03-03 09:25:04 +01:00
|
|
|
for (let i = 0; i < 4; i++) {
|
|
|
|
|
const indiceAleatorio = Math.floor(Math.random() * caracteres.length);
|
|
|
|
|
stringAleatoria += caracteres.charAt(indiceAleatorio);
|
|
|
|
|
}
|
2024-03-11 10:23:33 +01:00
|
|
|
|
2024-03-03 09:25:04 +01:00
|
|
|
return stringAleatoria;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-21 17:06:36 +01:00
|
|
|
async shareContentIso(fullPath, FileExtension, filename) {
|
2024-04-01 12:18:25 +01:00
|
|
|
|
|
|
|
|
console.log({fullPath, FileExtension, filename})
|
|
|
|
|
|
2024-03-03 09:19:34 +01:00
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
if (this.checkFileType.checkFileType(FileExtension) == 'image') {
|
|
|
|
|
|
|
|
|
|
Filesystem.readFile({ path: fullPath }).then(async (content) => {
|
|
|
|
|
try {
|
2024-03-28 16:28:17 +01:00
|
|
|
|
2024-03-03 09:19:34 +01:00
|
|
|
console.log('shared base', content.data)
|
2024-04-01 15:59:08 +01:00
|
|
|
this.capturedImage = 'data:image/jpeg;base64,' + this.removeTextBeforeSlash(content.data, ',');
|
|
|
|
|
this.showCroppModal()
|
2024-03-03 09:19:34 +01:00
|
|
|
} catch (error) {
|
|
|
|
|
console.log('error shared filesystem', error)
|
|
|
|
|
}
|
2024-03-11 10:23:33 +01:00
|
|
|
|
2024-03-03 09:19:34 +01:00
|
|
|
})
|
|
|
|
|
} else if (this.checkFileType.checkFileType(FileExtension) == 'video') {
|
|
|
|
|
const directory = await Filesystem.getUri({
|
|
|
|
|
directory: Directory.Cache,
|
|
|
|
|
path: '',
|
|
|
|
|
});
|
2024-03-11 10:23:33 +01:00
|
|
|
|
2024-03-21 17:06:36 +01:00
|
|
|
this.videoconvertService.convertVideo(fullPath, directory.uri, filename, 'mp4').then(async () => {
|
|
|
|
|
await Filesystem.readFile({ path: `${directory.uri}${filename}.mp4` })
|
2024-03-11 10:23:33 +01:00
|
|
|
|
2024-03-21 17:06:36 +01:00
|
|
|
.then(async (content) => {
|
|
|
|
|
console.log(content.data)
|
|
|
|
|
this.filecontent = true;
|
2024-03-14 15:39:08 +01:00
|
|
|
/* fileObject = {
|
2024-03-03 09:19:34 +01:00
|
|
|
FileBase64: this.removeTextBeforeSlash(content.data, ','),
|
2024-03-14 15:39:08 +01:00
|
|
|
FileExtension: 'mp4',
|
2024-03-03 09:19:34 +01:00
|
|
|
OriginalFileName: 'shared',
|
2024-03-14 15:39:08 +01:00
|
|
|
} */
|
2024-03-26 12:03:30 +01:00
|
|
|
|
|
|
|
|
const newAttachment = new PublicationAttachmentEntity(
|
|
|
|
|
{
|
2024-04-01 15:59:08 +01:00
|
|
|
base64: content.data,
|
2024-03-26 12:03:30 +01:00
|
|
|
extension: 'mp4',
|
|
|
|
|
FileType: this.checkFileType.checkFileType('mp4') as any,
|
|
|
|
|
OriginalFileName: 'shared'
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
newAttachment.needUpload()
|
|
|
|
|
|
|
|
|
|
this.PublicationFromMvService.form.Files.push(newAttachment)
|
2024-03-28 16:28:17 +01:00
|
|
|
|
2024-03-27 10:21:54 +01:00
|
|
|
const deleteSecretFile = async () => {
|
|
|
|
|
await Filesystem.deleteFile({
|
|
|
|
|
path: `${filename}.mp4`,
|
|
|
|
|
directory: Directory.Cache,
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
deleteSecretFile().then((value) => {
|
|
|
|
|
console.log('delete file', value)
|
2024-03-28 16:28:17 +01:00
|
|
|
|
2024-03-27 10:21:54 +01:00
|
|
|
})
|
|
|
|
|
.catch((erro) => console.error('read converted video erro ', erro));
|
|
|
|
|
});
|
2024-03-03 09:19:34 +01:00
|
|
|
|
2024-03-27 10:21:54 +01:00
|
|
|
});
|
2024-03-11 10:23:33 +01:00
|
|
|
|
2024-03-26 13:58:09 +01:00
|
|
|
}
|
2024-03-03 09:19:34 +01:00
|
|
|
} catch (error) {
|
2024-03-21 17:06:36 +01:00
|
|
|
console.log('record video ios erro, ', error)
|
2024-03-03 09:19:34 +01:00
|
|
|
}
|
2024-03-26 13:58:09 +01:00
|
|
|
|
2024-03-03 09:19:34 +01:00
|
|
|
}
|
|
|
|
|
|
2024-03-26 13:58:09 +01:00
|
|
|
|
2024-03-21 17:06:36 +01:00
|
|
|
shareContentAndroid(resultUrl, FileExtension) {
|
2024-03-03 09:19:34 +01:00
|
|
|
|
2024-04-01 12:18:25 +01:00
|
|
|
console.log({resultUrl, FileExtension})
|
|
|
|
|
|
2024-03-03 09:19:34 +01:00
|
|
|
Filesystem.readFile({ path: resultUrl }).then(async (content) => {
|
|
|
|
|
try {
|
|
|
|
|
if (this.checkFileType.checkFileType(FileExtension) == 'image') {
|
2024-04-01 15:59:08 +01:00
|
|
|
this.capturedImage = 'data:image/jpeg;base64,' + this.removeTextBeforeSlash(content.data, ',');
|
|
|
|
|
this.showCroppModal()
|
2024-04-01 12:18:25 +01:00
|
|
|
|
2024-03-03 09:19:34 +01:00
|
|
|
} else if (this.checkFileType.checkFileType(FileExtension) == 'video') {
|
2024-03-28 16:28:17 +01:00
|
|
|
|
2024-04-01 12:18:25 +01:00
|
|
|
let newAttachment = new PublicationAttachmentEntity(
|
2024-03-28 16:28:17 +01:00
|
|
|
{
|
2024-04-01 12:18:25 +01:00
|
|
|
base64: content.data,
|
2024-03-28 16:28:17 +01:00
|
|
|
extension: 'mp4',
|
|
|
|
|
FileType: this.checkFileType.checkFileType('mp4') as any,
|
|
|
|
|
OriginalFileName: 'shared'
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
newAttachment.needUpload()
|
2024-04-01 12:18:25 +01:00
|
|
|
this.PublicationFromMvService.form.Files.push(newAttachment)
|
2024-03-03 09:19:34 +01:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
console.log('shared base', content.data)
|
|
|
|
|
|
2024-04-01 12:18:25 +01:00
|
|
|
|
2024-03-03 09:19:34 +01:00
|
|
|
} catch (error) {
|
|
|
|
|
console.log('error shared filesystem', error)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-27 10:21:54 +01:00
|
|
|
async showCroppModal() {
|
|
|
|
|
const modal = await this.modalController.create({
|
|
|
|
|
component: CropImagePage,
|
|
|
|
|
componentProps: {
|
|
|
|
|
base64ToCroppe: this.capturedImage
|
|
|
|
|
},
|
|
|
|
|
cssClass: 'modal modal-desktop'
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
modal.onDidDismiss().then((res) => {
|
|
|
|
|
if (res) {
|
|
|
|
|
this.capturedImage = res.data
|
|
|
|
|
this.filecontent = true;
|
|
|
|
|
this.photoOrVideo = false;
|
|
|
|
|
|
|
|
|
|
const newAttachment = new PublicationAttachmentEntity(
|
|
|
|
|
{
|
|
|
|
|
base64: res.data.base64ToCroppe,
|
|
|
|
|
extension: 'jpeg',
|
|
|
|
|
OriginalFileName: "image",
|
|
|
|
|
FileType: 'image'
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
this.PublicationFromMvService.form.Files.push(newAttachment)
|
|
|
|
|
}
|
|
|
|
|
}, (error) => {
|
|
|
|
|
console.log(error)
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await modal.present();
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-09 10:13:48 +01:00
|
|
|
}
|
2024-01-26 05:59:14 +01:00
|
|
|
|