Files
doneit-web/src/app/pages/publications/new-publication/new-publication.page.ts
T

720 lines
20 KiB
TypeScript
Raw Normal View History

import { Component, OnInit } from '@angular/core';
2022-04-26 16:53:10 +01:00
import { ModalController, NavParams, Platform, LoadingController } from '@ionic/angular';
/* import {Plugins, CameraResultType, CameraSource} from '@capacitor/core'; */
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
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';
import { Camera, CameraResultType, CameraSource, Photo } from '@capacitor/camera';
2023-11-06 13:33:35 +01:00
import { Filesystem, Directory, Encoding, FilesystemDirectory } 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';
import { FilePicker } from '@capawesome/capacitor-file-picker';
import { CapacitorVideoPlayer } from 'capacitor-video-player';
2024-01-12 12:13:51 +01:00
import { CaptureError, CaptureImageOptions, CaptureVideoOptions, MediaCapture, MediaFile } from '@awesome-cordova-plugins/media-capture/ngx';
2023-11-06 09:07:04 +01:00
import { Capacitor } from '@capacitor/core';
2023-11-10 15:37:12 +01:00
import { File } from '@ionic-native/file/ngx';
import { Media } from '@ionic-native/media/ngx';
2023-11-20 14:12:32 +01:00
import { checkFileTypeService } from 'src/app/services/checkFileType.service';
import { FileValidatorService } from "src/app/services/file/file-validator.service"
2024-01-12 12:13:51 +01:00
import { CameraService } from "src/app/services/camera.service"
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';
/* const { VideoRecorder } = Plugin; */
2021-11-16 13:07:55 +01:00
interface LocalFile {
name: string;
path: string;
data: string;
}
2023-11-06 13:33:35 +01:00
/* const config_video: VideoRecorderPreviewFrame = {
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
}; */
@Component({
selector: 'app-new-publication',
templateUrl: './new-publication.page.html',
styleUrls: ['./new-publication.page.scss'],
})
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;
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;
publication: Publication;
pub: Publication = new Publication();
2020-12-10 11:22:06 +01:00
folderId: string;
image: Image = new Image();
publicationType: string;
publicationTitle: string;
imgUrl: any;
Defaultimage: any = '';
2020-12-10 11:22:06 +01:00
photo: SafeResourceUrl;
guestPicture: any;
capturedImage: any = '';
capturedVideo: any = '';
capturedImageTitle: any;
2021-11-09 10:13:48 +01:00
public photos: any[] = [];
2023-08-11 16:14:25 +01:00
pictureExiste = false
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;
video: any;
photoOrVideo: boolean = false;
fileType = "";
2023-11-06 09:07:04 +01:00
filecontent: boolean;
2023-11-20 14:12:32 +01:00
seletedContent: any[] = []
// 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
constructor(
private modalController: ModalController,
2020-12-11 15:09:53 +01:00
public photoService: PhotoService,
private navParams: NavParams,
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,
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-01-12 12:13:51 +01:00
private FileValidatorService: FileValidatorService,
private file: File,
private cameraService: CameraService
) {
2021-11-09 10:13:48 +01:00
this.publicationType = this.navParams.get('publicationType');
this.folderId = this.navParams.get('folderId');
2023-08-18 17:37:11 +01:00
this.publication = this.navParams.get('publication');
2023-11-29 12:17:52 +01:00
if (this.publication) {
this.seletedContent = this.publication.Files;
this.filecontent = true;
}
console.log('Edit', this.publication)
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));
}
ngOnInit() {
2023-11-29 12:17:52 +01:00
this.reciveSharedContent();
2023-10-25 09:08:49 +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-01-12 12:13:51 +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) {}
}
2021-07-06 16:18:00 +01:00
2023-08-23 17:19:22 +01:00
// in use
async takePicture() {
const capturedImage = await Camera.getPhoto({
quality: 50,
// allowEditing: true,
resultType: CameraResultType.Base64,
source: CameraSource.Camera
2021-02-09 13:16:41 +01:00
});
2022-01-03 18:45:37 +01:00
2023-11-29 12:17:52 +01:00
console.log(capturedImage)
2023-12-06 17:01:00 +01:00
this.capturedImage = 'data:image/jpeg;base64,' + capturedImage.base64String;
this.capturedImageTitle = 'foto';
2023-12-06 17:01:00 +01:00
if (this.fileSizeToMB(capturedImage.base64String.length) <= 20) {
const compressedImage = await this.compressImageBase64(
this.capturedImage,
800, // maxWidth
800, // maxHeight
0.9 // quality
).then((picture) => {
console.log('take picture', this.removeTextBeforeSlash(picture, ','),)
this.filecontent = true;
this.photoOrVideo = false;
let fileObject = {
FileBase64: this.removeTextBeforeSlash(picture, ','),
2024-01-12 12:13:51 +01:00
FileExtension: capturedImage.format,
OriginalFileName: 'foto'
2023-12-06 17:01:00 +01:00
}
this.seletedContent.push(fileObject)
2023-11-29 12:17:52 +01:00
2023-12-06 17:01:00 +01:00
});
} else {
if (this.seletedContent.length === 0)
this.filesSizeSum = 0
2023-10-31 15:13:19 +01:00
2023-12-06 17:01:00 +01:00
this.httpErrorHandle.validationMessagge('filessize');
}
}
2021-11-09 10:13:48 +01:00
async laodPicture() {
const capturedImage = await Camera.getPhoto({
quality: 90,
resultType: CameraResultType.Base64,
source: CameraSource.Photos
});
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
async startVideoRecording() {
2024-01-12 12:13:51 +01:00
try {
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];
2023-11-10 15:37:12 +01:00
console.log(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
if (this.fileSizeToMB(this.filesSizeSum) <= 20) {
const savedFile = await Filesystem.copy({
from: element.fullPath, // directory prop removed, Capacitor parses filename for us
to: "video.mp4",
toDirectory: FilesystemDirectory.Data
});
console.log(savedFile.uri)
Filesystem.readFile({ path: savedFile.uri })
.then(async (content) => {
this.filecontent = true;
let fileObject = {
FileBase64: content.data,
FileExtension: 'mp4'
}
this.seletedContent.push(fileObject)
})
.catch((err) => console.error(err));
} else {
if (this.seletedContent.length === 0)
this.filesSizeSum = 0
2023-11-29 12:17:52 +01:00
2023-12-06 17:01:00 +01:00
this.httpErrorHandle.validationMessagge('filessize')
}
2023-11-29 12:17:52 +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)
}
2024-01-12 12:13:51 +01:00
2023-11-10 15:37:12 +01:00
}
2023-11-06 13:33:35 +01:00
async loadVideo() {
2023-10-31 15:13:19 +01:00
const result = await FilePicker.pickMedia
2023-11-06 09:07:04 +01:00
({
multiple: true,
});
2023-11-20 14:12:32 +01:00
result.files.forEach(element => {
2023-12-06 17:01:00 +01:00
this.filesSizeSum = this.filesSizeSum + element.size
if (this.fileSizeToMB(this.filesSizeSum) <= 20) {
if (this.checkFileType.checkFileType(element.mimeType) == 'image' || this.checkFileType.checkFileType(element.mimeType) == 'video') {
let resultUrl = decodeURIComponent(element.path);
Filesystem.readFile({ path: resultUrl })
.then(async (content) => {
console.log(result)
console.log(content)
this.filecontent = true;
let fileObject = {
FileBase64: content.data,
2024-01-12 12:13:51 +01:00
FileExtension: this.removeTextBeforeSlash(element.mimeType, '/'),
OriginalFileName: 'foto'
2023-12-06 17:01:00 +01:00
}
this.seletedContent.push(fileObject)
})
.catch((err) => console.error(err));
}
} else {
if (this.seletedContent.length === 0)
this.filesSizeSum = 0
2023-11-29 12:17:52 +01:00
2023-12-06 17:01:00 +01:00
this.httpErrorHandle.validationMessagge('filessize')
2023-11-29 12:17:52 +01:00
}
2023-11-20 14:12:32 +01:00
});
};
chossePhotoOrVideo() {
2023-10-31 15:13:19 +01:00
this.photoOrVideo = !this.photoOrVideo
}
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
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 = () => {
resolve(reader.result);
2021-11-09 10:13:48 +01:00
};
reader.readAsDataURL(blob);
}).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
/* // in use
async laodPicture() {
2024-01-12 12:13:51 +01:00
const capturedImage = await Camera.getPhoto({
quality: 90,
// allowEditing: true,
resultType: CameraResultType.Uri,
source: CameraSource.Photos
});
2024-01-12 12:13:51 +01:00
const response = await fetch(capturedImage.webPath!);
const blob = await response.blob();
2024-01-12 12:13:51 +01:00
this.convertBlobToBase64Worker.postMessage(blob);
this.convertBlobToBase64Worker.onmessage = async (oEvent)=> {
this.capturedImage = oEvent.data
this.capturedImageTitle = 'foto'
2024-01-12 12:13:51 +01:00
}
2024-01-12 12:13:51 +01:00
} */
2021-08-23 16:06:05 +01:00
2021-07-06 16:18:00 +01:00
2021-07-06 16:18:00 +01:00
runValidation() {
this.validateFrom = true
2021-07-06 16:18:00 +01:00
}
injectValidation() {
this.Form = new FormGroup({
Subject: new FormControl(this.pub.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, [
]),
Message: new FormControl(this.pub.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()
if (this.Form.invalid) return false
2021-07-06 16:18:00 +01:00
2021-11-09 10:13:48 +01:00
2021-07-14 15:38:58 +01:00
if (this.publicationType == '3') {
2023-08-23 09:55:14 +01:00
const loader = this.toastService.loading()
2021-11-09 10:13:48 +01:00
2024-01-12 12:13:51 +01:00
this.publication = {
DateIndex: this.publication.DateIndex,
DocumentId: this.publication.DocumentId,
ProcessId: this.publication.ProcessId,
Title: this.pub.Title,
Message: this.pub.Message,
DatePublication: this.publication.DatePublication,
OriginalFileName: this.publication.OriginalFileName,
Files: this.seletedContent,
}
2021-07-12 11:13:29 +01:00
2021-06-29 14:16:49 +01:00
2024-01-12 12:13:51 +01:00
/* else {
2021-07-26 15:19:03 +01:00
this.publication = {
DateIndex: this.publication.DateIndex,
DocumentId: this.publication.DocumentId,
ProcessId: this.publication.ProcessId,
2021-07-26 15:19:03 +01:00
Title: this.pub.Title,
Message: this.pub.Message,
DatePublication: this.publication.DatePublication,
2023-08-22 15:43:20 +01:00
OriginalFileName: this.publication.OriginalFileName,
FileBase64: this.publication.FileBase64,
2023-08-24 22:15:56 +01:00
FileExtension: this.publication.FileExtension || 'jpeg',
2021-07-26 15:19:03 +01:00
}
} */
2023-08-23 09:55:14 +01:00
2023-08-24 22:15:56 +01:00
2023-08-23 09:55:14 +01:00
try {
const response = await this.publications.UpdatePublication(this.publication.ProcessId, this.publication).toPromise()
2023-08-23 09:55:14 +01:00
this.httpErrorHandle.httpsSucessMessagge('Editar publicação')
console.log({ response })
2023-08-23 09:55:14 +01:00
2021-07-26 15:19:03 +01:00
2023-08-23 09:55:14 +01:00
this.close();
} catch (error) {
if (error.status == 404) {
this.PublicationFolderService.deletePost(this.publication.ProcessId, this.publication.DocumentId)
2023-08-24 22:15:56 +01:00
this.close();
}
2023-08-23 09:55:14 +01:00
this.httpErrorHandle.httpStatusHandle(error)
} finally {
2023-08-23 09:55:14 +01:00
loader.remove()
}
2023-08-18 17:37:11 +01:00
}
2021-07-06 16:18:00 +01:00
else {
2021-07-14 16:57:06 +01:00
const date = formatDate(new Date(), 'yyyy-MM-dd HH:mm:ss')
2023-11-29 12:17:52 +01:00
/* if (this.capturedImage != '') { */
this.publication = {
DateIndex: date,
DocumentId: null,
ProcessId: this.folderId,
Title: this.pub.Title,
Message: this.pub.Message,
DatePublication: date,
OriginalFileName: this.capturedImageTitle,
Files: this.seletedContent,
/* FileExtension: 'jpeg', */
2020-12-10 11:22:06 +01:00
}
2021-06-29 14:16:49 +01:00
2023-11-29 12:17:52 +01:00
/* } else if (this.capturedVideo != '') {
this.publication = {
DateIndex: date,
DocumentId: null,
ProcessId: this.folderId,
Title: this.pub.Title,
Message: this.pub.Message,
DatePublication: date,
OriginalFileName: this.capturedImageTitle || 'video',
Files: this.seletedContent,
FileExtension: 'mp4',
}
} */
2021-07-12 11:13:29 +01:00
const loader = this.toastService.loading()
2021-06-29 14:16:49 +01:00
try {
2021-06-30 16:11:07 +01:00
await this.publications.CreatePublication(this.folderId, this.publication).toPromise();
this.close();
2023-02-27 09:34:36 +01:00
this.httpErrorHandle.httpsSucessMessagge('Criar publicação')
2023-11-29 12:17:52 +01:00
window["sharedContent"] = null;
2021-06-29 14:16:49 +01:00
this.close();
} catch (error) {
2023-02-27 09:34:36 +01:00
this.httpErrorHandle.httpStatusHandle(error)
} finally {
2021-07-12 11:13:29 +01:00
loader.remove()
2021-06-29 14:16:49 +01:00
}
}
2023-08-23 09:55:14 +01:00
this.PublicationFolderService.getPublicationsIds(this.folderId)
}
2021-07-06 16:18:00 +01:00
close() {
2023-08-23 09:55:14 +01:00
this.modalController.dismiss(this.publication).then(() => {
this.showLoader = true;
2020-12-15 19:37:42 +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;
2023-11-29 12:17:52 +01:00
this.seletedContent = [];
2020-12-11 15:09:53 +01:00
}
2021-07-06 16:18:00 +01:00
setTitle() {
if (this.publicationType == '1') {
2020-12-10 11:22:06 +01:00
this.publicationTitle = 'Nova Publicação Rápida';
}
else if (this.publicationType == '2') {
2020-12-10 11:22:06 +01:00
this.publicationTitle = 'Nova Publicação';
}
else if (this.publicationType == '3') {
this.publicationTitle = 'Editar Publicação';
this.pub = this.navParams.get('publication');
2021-07-14 15:38:58 +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() {
//this.imgResultBeforeCompress = image;s
2021-11-26 14:46:08 +01:00
this.imageCompress.getOrientation(this.capturedImage).then((orientation) => {
this.imageCompress.compressFile(this.capturedImage, orientation, 90, 90).then(
2021-11-26 14:46:08 +01:00
result => {
this.capturedImage = result;
2021-11-26 14:46:08 +01:00
}
);
});
}
2023-08-15 10:15:08 +01:00
deletePublicationImage() {
2023-11-29 12:17:52 +01:00
this.seletedContent = []
2023-08-15 10:15:08 +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;
image.onload = async () => {
const canvas = document.createElement('canvas');
let newWidth = image.width;
let newHeight = image.height;
if (newWidth > maxWidth) {
newHeight *= maxWidth / newWidth;
newWidth = maxWidth;
}
if (newHeight > maxHeight) {
newWidth *= maxHeight / newHeight;
newHeight = maxHeight;
}
canvas.width = newWidth;
canvas.height = newHeight;
const context = canvas.getContext('2d');
context?.drawImage(image, 0, 0, newWidth, newHeight);
const compressedBase64 = canvas.toDataURL('image/jpeg', quality);
resolve(compressedBase64);
};
image.onerror = (error) => {
reject(error);
};
});
}
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
}
2023-12-06 17:01:00 +01:00
if(this.intent?.additionalItems) {
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);
Filesystem.readFile({ path: resultUrl }).then(async (content) => {
2023-12-06 17:01:00 +01:00
console.log('shared base', content.data)
2023-11-29 12:17:52 +01:00
let fileObject = {
FileBase64: this.removeTextBeforeSlash(content.data, ','),
FileExtension: FileExtension
}
this.seletedContent.push(fileObject)
})
} 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)
}
deleteFromSeletedContent(index){
this.seletedContent.splice(index,1)
}
2023-12-06 17:01:00 +01:00
2021-11-09 10:13:48 +01:00
}