mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 13:02:56 +00:00
47 lines
1.5 KiB
TypeScript
47 lines
1.5 KiB
TypeScript
import { Injectable } from '@angular/core';
|
|
import { MessageAttachmentByMessageIdInput } from './message-attachment-by-message-id.service';
|
|
import { AttachmentRemoteDataSourceService } from 'src/app/module/chat/data/repository/attachment/attachment-remote-repository.service'
|
|
import { AttachmentLocalDataSource } from 'src/app/module/chat/data/repository/attachment/attachment-local-repository.service'
|
|
import { err, Result } from 'neverthrow';
|
|
import { AttachmentTableSchema } from 'src/app/infra/database/dexie/instance/chat/schema/attachment';
|
|
import { z } from 'zod';
|
|
import { createBlobUrl } from 'src/app/utils/ToBase64';
|
|
|
|
const GetMessageAttachmentLocallyByMessageIdSchema = AttachmentTableSchema.pick({
|
|
$messageId: true
|
|
})
|
|
|
|
export type GetMessageAttachmentLocallyByMessageId = z.infer<typeof GetMessageAttachmentLocallyByMessageIdSchema>
|
|
|
|
|
|
|
|
@Injectable({
|
|
providedIn: 'root'
|
|
})
|
|
export class GetMessageAttachmentLocallyUseCaseService {
|
|
|
|
constructor(
|
|
private AttachmentRemoteDataSourceService: AttachmentRemoteDataSourceService,
|
|
private AttachmentLocalDataSource: AttachmentLocalDataSource
|
|
) { }
|
|
|
|
|
|
async execute(input: GetMessageAttachmentLocallyByMessageId): Promise<Result<string, any>> {
|
|
|
|
const getLocalAttachment = await this.AttachmentLocalDataSource.findOne({
|
|
$messageId: input.$messageId
|
|
})
|
|
|
|
if(getLocalAttachment.isOk()) {
|
|
if(getLocalAttachment.value) {
|
|
const dataUrl = await createBlobUrl(getLocalAttachment.value.file)
|
|
|
|
return dataUrl
|
|
}
|
|
} else {
|
|
return err(getLocalAttachment.error)
|
|
}
|
|
}
|
|
|
|
}
|