mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 13:02:56 +00:00
add audio
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { z } from "zod";
|
||||
import { MessageAttachmentFileType, MessageAttachmentSource } from "./messageOutputDTO";
|
||||
import { base64Schema } from "src/app/utils/zod";
|
||||
|
||||
export const MessageInputDTOSchema = z.object({
|
||||
roomId: z.string().uuid(),
|
||||
@@ -13,10 +14,10 @@ export const MessageInputDTOSchema = z.object({
|
||||
attachment: z.object({
|
||||
fileType: z.nativeEnum(MessageAttachmentFileType),
|
||||
source: z.nativeEnum(MessageAttachmentSource),
|
||||
file: z.string(),
|
||||
fileName: z.string(),
|
||||
applicationId: z.string(),
|
||||
docId: z.string(),
|
||||
file: base64Schema.optional(),
|
||||
fileName: z.string().optional(),
|
||||
applicationId: z.string().optional(),
|
||||
docId: z.string().optional(),
|
||||
mimeType: z.string().optional()
|
||||
}).optional()
|
||||
});
|
||||
|
||||
@@ -42,7 +42,7 @@ export const MessageOutPutDataDTOSchema = z.object({
|
||||
fileName: z.string().optional(),
|
||||
applicationId: z.string().optional(),
|
||||
docId: z.string().optional(),
|
||||
id: z.string()
|
||||
id: z.string().optional()
|
||||
}))
|
||||
});
|
||||
|
||||
|
||||
@@ -227,11 +227,11 @@ export class RoomRepositoryService {
|
||||
@captureAndReraiseAsync('RoomRepositoryService/addMemberToRoom')
|
||||
async addMemberToRoom(data: AddMemberToRoomInputDTO) {
|
||||
|
||||
//return this.roomLiveSignalRDataSourceService.addMemberToRoom(data)
|
||||
return this.roomLiveSignalRDataSourceService.addMemberToRoom(data)
|
||||
|
||||
const result = await this.roomRemoteDataSourceService.addMemberToRoom(data)
|
||||
// const result = await this.roomRemoteDataSourceService.addMemberToRoom(data)
|
||||
|
||||
return result
|
||||
// return result
|
||||
}
|
||||
|
||||
async updateMemberStatus(data: MemberListUPdateStatusInputDTO) {
|
||||
|
||||
@@ -26,8 +26,10 @@ export const MessageEntitySchema = z.object({
|
||||
file: base64Schema.optional(),
|
||||
fileName: z.string().optional(),
|
||||
applicationId: z.string().optional(),
|
||||
docId: z.string().optional()
|
||||
})),
|
||||
docId: z.string().optional(),
|
||||
id: z.string().optional(),
|
||||
mimeType: z.string().optional()
|
||||
})).optional()
|
||||
})
|
||||
|
||||
type Message = z.infer<typeof MessageEntitySchema>;
|
||||
|
||||
@@ -9,7 +9,7 @@ export class MessageMapper {
|
||||
}
|
||||
|
||||
static fromDomain(entity:MessageEntity, requestId): MessageInputDTO {
|
||||
return{
|
||||
return {
|
||||
canEdit: entity.canEdit,
|
||||
message: entity.message,
|
||||
messageType: entity.messageType,
|
||||
@@ -18,7 +18,16 @@ export class MessageMapper {
|
||||
roomId: entity.roomId,
|
||||
senderId: entity.sender.wxUserId,
|
||||
requestId: requestId,
|
||||
attachment: entity.attachments[0]
|
||||
attachment: entity.attachments.map((e)=>({
|
||||
fileType:e.fileType,
|
||||
source: e.source,
|
||||
file: e.file,
|
||||
fileName: e.fileName,
|
||||
applicationId: e.applicationId,
|
||||
docId: e.docId,
|
||||
mimeType: e.mimeType
|
||||
}))[0]
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,9 +47,13 @@ export class MessageCreateUseCaseService {
|
||||
|
||||
for (const attachment of message.attachments) {
|
||||
|
||||
const createAttachmentLocally = this.AttachmentRepositoryService.create({
|
||||
this.AttachmentRepositoryService.create({
|
||||
$messageId: createMessageLocally.value.$id,
|
||||
file: createDataURL(attachment.file, attachment.mimeType)
|
||||
}).then((e) => {
|
||||
if(e.isErr()) {
|
||||
console.log('e', e.error, createDataURL(attachment.file, attachment.mimeType))
|
||||
}
|
||||
})
|
||||
|
||||
attachment.safeFile = createDataURL(attachment.file, attachment.mimeType)
|
||||
|
||||
@@ -31,7 +31,9 @@ export const MessageTableSchema = z.object({
|
||||
source: z.nativeEnum(MessageAttachmentSource),
|
||||
fileName: z.string().optional(),
|
||||
applicationId: z.string().optional(),
|
||||
docId: z.string().optional()
|
||||
docId: z.string().optional(),
|
||||
id: z.string().optional(),
|
||||
mimeType: z.string().optional()
|
||||
})).optional()
|
||||
})
|
||||
|
||||
|
||||
@@ -71,10 +71,7 @@
|
||||
</div>
|
||||
|
||||
<div *ngIf="attachment.fileType == MessageAttachmentFileType.Audio">
|
||||
<audio controls>
|
||||
<source [src]="attachment.safeFile" >
|
||||
Your browser does not support the audio element.
|
||||
</audio>
|
||||
<audio [src]="attachment.safeFile|safehtml" preload="metadata" class="flex-grow-1" controls controlsList="nodownload noplaybackrate"></audio>
|
||||
</div>
|
||||
|
||||
<div *ngIf="attachment.fileType == MessageAttachmentFileType.Doc">
|
||||
|
||||
@@ -161,7 +161,8 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
private CameraService: CameraService,
|
||||
private FilePickerWebService: FilePickerWebService,
|
||||
private FilePickerService: FilePickerService,
|
||||
private SpeakerService: SpeakerService
|
||||
private SpeakerService: SpeakerService,
|
||||
private sanitizer: DomSanitizer
|
||||
) {
|
||||
// update
|
||||
this.checkAudioPermission()
|
||||
@@ -220,9 +221,12 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
id: message.attachments[0].id
|
||||
})
|
||||
|
||||
if(result.isOk()) {
|
||||
message.attachments[0].safeFile = result.value
|
||||
if(result.isOk() && message.attachments[0].fileType == MessageAttachmentFileType.Audio) {
|
||||
console.log('safe parse', result.value)
|
||||
message.attachments[0].safeFile = result.value;
|
||||
|
||||
} else if(result.isOk()){
|
||||
message.attachments[0].safeFile = result.value
|
||||
}
|
||||
}
|
||||
|
||||
@@ -257,10 +261,12 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
id: message.attachments[0].id
|
||||
})
|
||||
|
||||
if(result.isOk()) {
|
||||
if(result.isOk() && message.attachments[0].fileType == MessageAttachmentFileType.Audio) {
|
||||
console.log('safe parse', result.value)
|
||||
message.attachments[0].safeFile = result.value;
|
||||
|
||||
} else if(result.isOk()){
|
||||
message.attachments[0].safeFile = result.value
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -504,16 +510,6 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
}, 1000)
|
||||
}
|
||||
|
||||
async getFile(fileName?: any) {
|
||||
const audioFile = await Filesystem.readFile({
|
||||
path: fileName,
|
||||
directory: Directory.Data
|
||||
})
|
||||
const base64sound = audioFile.data;
|
||||
const base64Response = await fetch(`data:audio/ogg;base64,${base64sound}`);
|
||||
this.audioRecordedSafe = base64Response.url;
|
||||
}
|
||||
|
||||
async startRecording() {
|
||||
|
||||
const start = await this.SpeakerService.startRecording()
|
||||
@@ -584,8 +580,8 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
fileName: "audio",
|
||||
source: MessageAttachmentSource.Device,
|
||||
fileType: MessageAttachmentFileType.Audio,
|
||||
mimeType: this.audioMimeType
|
||||
|
||||
mimeType: this.audioMimeType, // 'audio/webm',
|
||||
safeFile: this.sanitiser.bypassSecurityTrustResourceUrl(this.audioRecordedDataUrl)
|
||||
}]
|
||||
|
||||
this.chatServiceService.sendMessage(message)
|
||||
@@ -929,7 +925,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
}
|
||||
|
||||
message.attachments = [{
|
||||
file: file.value.base64String.split(',')[1],
|
||||
file: file.value.base64String,
|
||||
fileName: "foto",
|
||||
source: MessageAttachmentSource.Device,
|
||||
fileType: MessageAttachmentFileType.Image,
|
||||
|
||||
@@ -1,11 +1,5 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
/**
|
||||
* Regular expression to validate a data URL.
|
||||
* The pattern matches data URLs that start with `data:`, optionally followed by a media type,
|
||||
* optionally followed by an encoding (e.g., `base64`), and ending with base64 encoded data.
|
||||
*/
|
||||
export const zodDataUrlRegex = /^data:(?:[\w+\/-]+)?(?:[\w+\/-]+)?;base64,[\s\S]*$/;
|
||||
|
||||
/**
|
||||
* Zod schema for validating data URLs.
|
||||
@@ -19,7 +13,7 @@ export const zodDataUrlRegex = /^data:(?:[\w+\/-]+)?(?:[\w+\/-]+)?;base64,[\s\S]
|
||||
* console.error('Validation error:', result.error.errors);
|
||||
* }
|
||||
*/
|
||||
export const zodDataUrlSchema = z.string().refine(value => zodDataUrlRegex.test(value), {
|
||||
export const zodDataUrlSchema = z.string().refine(value => value.startsWith('data:'), {
|
||||
message: 'Invalid data URL',
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user