Merge branch 'feature/shared-content' of bitbucket.org:equilibriumito/gabinete-digital-fo into feature/shared-content

This commit is contained in:
Peter Maquiran
2023-12-07 16:00:17 +01:00
9 changed files with 573 additions and 72 deletions
@@ -115,6 +115,7 @@ export class NewPublicationPage implements OnInit {
seletedContent: any[] = []
// Set a limit for the number of images to display
displayLimit = 4;
filesSizeSum = 0;
constructor(
private modalController: ModalController,
@@ -179,26 +180,33 @@ export class NewPublicationPage implements OnInit {
console.log(capturedImage)
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('take picture', this.removeTextBeforeSlash(picture, ','),)
this.filecontent = true;
this.photoOrVideo = false;
let fileObject = {
FileBase64: this.removeTextBeforeSlash(picture, ','),
FileExtension: capturedImage.format
}
this.seletedContent.push(fileObject)
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, ','),
FileExtension: capturedImage.format
}
this.seletedContent.push(fileObject)
});
});
} else {
if (this.seletedContent.length === 0)
this.filesSizeSum = 0
this.httpErrorHandle.validationMessagge('filessize');
}
}
async laodPicture() {
@@ -230,24 +238,32 @@ export class NewPublicationPage implements OnInit {
this.video = data[0];
console.log(data)
data.forEach(async element => {
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 })
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
this.httpErrorHandle.validationMessagge('filessize')
}
.then(async (content) => {
this.filecontent = true;
let fileObject = {
FileBase64: content.data,
FileExtension: 'mp4'
}
this.seletedContent.push(fileObject)
})
.catch((err) => console.error(err));
});
} catch (error) {
console.log('record video error: ', error)
@@ -262,23 +278,30 @@ export class NewPublicationPage implements OnInit {
});
result.files.forEach(element => {
if (this.checkFileType.checkFileType(element.mimeType) == 'image' || this.checkFileType.checkFileType(element.mimeType) == 'video') {
let resultUrl = decodeURIComponent(element.path);
Filesystem.readFile({ path: resultUrl })
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,
FileExtension: this.removeTextBeforeSlash(element.mimeType, '/')
}
this.seletedContent.push(fileObject)
})
.catch((err) => console.error(err));
.then(async (content) => {
console.log(result)
console.log(content)
this.filecontent = true;
let fileObject = {
FileBase64: content.data,
FileExtension: this.removeTextBeforeSlash(element.mimeType, '/')
}
this.seletedContent.push(fileObject)
})
.catch((err) => console.error(err));
}
} else {
if (this.seletedContent.length === 0)
this.filesSizeSum = 0
this.httpErrorHandle.validationMessagge('filessize')
}
});
};
@@ -674,14 +697,16 @@ export class NewPublicationPage implements OnInit {
type: this.intent.type,
url: this.intent.url
}
filesArray = this.intent?.additionalItems;
if(this.intent?.additionalItems) {
filesArray = this.intent?.additionalItems;
}
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) => {
console.log('shared base',content.data)
console.log('shared base', content.data)
let fileObject = {
FileBase64: this.removeTextBeforeSlash(content.data, ','),
FileExtension: FileExtension
@@ -696,5 +721,12 @@ export class NewPublicationPage implements OnInit {
}
fileSizeToMB(sizeInBytes) {
var sizeInMB = (sizeInBytes / (1024 * 1024)).toFixed(2);
console.log(sizeInMB + 'MB');
return parseInt(sizeInMB)
}
}