Added validation to check if user add image ou video and prevent to create publication withou it

This commit is contained in:
Eudes Inácio
2024-02-02 12:05:42 +01:00
parent 01f15f97ac
commit a5b29e330a
2 changed files with 172 additions and 182 deletions
@@ -278,7 +278,7 @@ export class NewPublicationPage implements OnInit {
({
multiple: true,
});
console.log(result.files)
console.log(result.files)
result.files.forEach(element => {
this.filesSizeSum = this.filesSizeSum + element.size
@@ -293,9 +293,9 @@ export class NewPublicationPage implements OnInit {
console.log(content)
this.filecontent = true;
let fileObject;
if(this.removeTextBeforeSlash(element.mimeType, '/') == "mp4") {
fileObject = {
FileBase64: 'data:video/mp4;base64,'+ content.data,
if (this.removeTextBeforeSlash(element.mimeType, '/') == "mp4") {
fileObject = {
FileBase64: 'data:video/mp4;base64,' + content.data,
FileExtension: this.removeTextBeforeSlash(element.mimeType, '/'),
OriginalFileName: 'video'
}
@@ -306,7 +306,7 @@ export class NewPublicationPage implements OnInit {
OriginalFileName: 'image'
}
}
this.seletedContent.push(fileObject)
})
.catch((err) => console.error(err));
@@ -405,51 +405,52 @@ export class NewPublicationPage implements OnInit {
if (this.Form.invalid) return false
if (this.seletedContent.length != 0) {
if (this.publicationType == '3') {
const loader = this.toastService.loading()
if (this.publicationType == '3') {
const loader = this.toastService.loading()
// has file
if (this.PublicationFolderService.PublicationHasImage(this.publication)) {
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,
}
// has file
if (this.PublicationFolderService.PublicationHasImage(this.publication)) {
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,
}
/* } else if (this.capturedVideo != '' && this.capturedImage == '') {
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 || 'video',
Files: this.seletedContent,
FileExtension: 'mp4',
}
} */
// no names
} else if (!this.PublicationFolderService.PublicationHasImage(this.publication)) {
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,
}
/* } else if (this.capturedVideo != '' && this.capturedImage == '') {
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 || 'video',
Files: this.seletedContent,
FileExtension: 'mp4',
}
} */
// no names
} else if (!this.PublicationFolderService.PublicationHasImage(this.publication)) {
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,
}
} /* else {
} /* else {
this.publication = {
DateIndex: this.publication.DateIndex,
DocumentId: this.publication.DocumentId,
@@ -465,92 +466,95 @@ export class NewPublicationPage implements OnInit {
} */
try {
try {
const response = await this.publications.UpdatePublication(this.publication.ProcessId, this.publication).toPromise()
const response = await this.publications.UpdatePublication(this.publication.ProcessId, this.publication).toPromise()
this.httpErrorHandle.httpsSucessMessagge('Editar publicação')
console.log({ response })
this.httpErrorHandle.httpsSucessMessagge('Editar publicação')
console.log({ response })
this.close();
} catch (error) {
if (error.status == 404) {
this.PublicationFolderService.deletePost(this.publication.ProcessId, this.publication.DocumentId)
this.close();
}
this.httpErrorHandle.httpStatusHandle(error)
} finally {
loader.remove()
}
}
else {
const date = formatDate(new Date(), 'yyyy-MM-dd HH:mm:ss')
/* this.seletedContent = this.seletedContent.map((e) => {
if(e.FileExtension == "mp4") {
return {
FileBase64: e.FileBase64,
FileExtension: 'data:video/mp4;base64,'+e.FileExtension,
OriginalFileName: "video",
} catch (error) {
if (error.status == 404) {
this.PublicationFolderService.deletePost(this.publication.ProcessId, this.publication.DocumentId)
this.close();
}
this.httpErrorHandle.httpStatusHandle(error)
} finally {
loader.remove()
}
}
else {
const date = formatDate(new Date(), 'yyyy-MM-dd HH:mm:ss')
/* this.seletedContent = this.seletedContent.map((e) => {
if(e.FileExtension == "mp4") {
return {
FileBase64: e.FileBase64,
FileExtension: 'data:video/mp4;base64,'+e.FileExtension,
OriginalFileName: "video",
}
}
return e
}) */
/* 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 || 'foto',
Files: this.seletedContent,
/* FileExtension: 'jpeg', */
}
/* } 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',
}
} */
const loader = this.toastService.loading()
try {
await this.publications.CreatePublication(this.folderId, this.publication).toPromise();
this.close();
this.httpErrorHandle.httpsSucessMessagge('Criar publicação')
window["sharedContent"] = null;
window["endSharedContent"] = null;
this.close();
} catch (error) {
this.httpErrorHandle.httpStatusHandle(error)
} finally {
loader.remove()
}
return e
}) */
/* 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 || 'foto',
Files: this.seletedContent,
/* FileExtension: 'jpeg', */
}
/* } 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',
}
} */
const loader = this.toastService.loading()
try {
await this.publications.CreatePublication(this.folderId, this.publication).toPromise();
this.close();
this.httpErrorHandle.httpsSucessMessagge('Criar publicação')
window["sharedContent"] = null;
window["endSharedContent"] = null;
this.close();
} catch (error) {
this.httpErrorHandle.httpStatusHandle(error)
} finally {
loader.remove()
}
this.PublicationFolderService.getPublicationsIds(this.folderId)
} else {
this.httpErrorHandle.validationMessagge("noFileSelected")
}
this.PublicationFolderService.getPublicationsIds(this.folderId)
}
@@ -741,7 +745,7 @@ export class NewPublicationPage implements OnInit {
let resultUrl = decodeURIComponent(element.url);
Filesystem.readFile({ path: resultUrl }).then(async (content) => {
let fileObject;
if(this.checkFileType.checkFileType(FileExtension) == 'image') {
if (this.checkFileType.checkFileType(FileExtension) == 'image') {
fileObject = {
FileBase64: this.removeTextBeforeSlash(content.data, ','),
FileExtension: FileExtension,
@@ -750,14 +754,14 @@ export class NewPublicationPage implements OnInit {
} else if (this.checkFileType.checkFileType(FileExtension) == 'video') {
fileObject = {
FileBase64: 'data:video/mp4;base64,'+ this.removeTextBeforeSlash(content.data, ','),
FileBase64: 'data:video/mp4;base64,' + this.removeTextBeforeSlash(content.data, ','),
FileExtension: FileExtension,
OriginalFileName: 'shared',
}
}
console.log('shared base', content.data)
this.seletedContent.push(fileObject)
})
} else {
File diff suppressed because one or more lines are too long