1- using Chats . BE . Services . FileServices ;
1+ using Chats . BE . Controllers . Chats . Messages . Dtos ;
2+ using Chats . BE . Services . FileServices ;
23using Chats . BE . Services . Models . Dtos ;
34using System . Text . Json . Serialization ;
45
@@ -11,9 +12,9 @@ public abstract record ImageChatSegment : ChatSegmentItem
1112{
1213 public abstract Task < DBFileDef > Download ( CancellationToken cancellationToken = default ) ;
1314
14- public abstract string ToTempUrl ( ) ;
15+ protected abstract string ToTempUrl ( ) ;
1516
16- public abstract string ToContentType ( ) ;
17+ protected abstract string ToContentType ( ) ;
1718}
1819
1920public record Base64Image : ImageChatSegment
@@ -32,9 +33,22 @@ public override Task<DBFileDef> Download(CancellationToken cancellationToken = d
3233 return Task . FromResult ( new DBFileDef ( bytes , ContentType , null ) ) ;
3334 }
3435
35- public override string ToTempUrl ( ) => $ "data:{ ContentType } ;base64,{ Base64 } ";
36+ protected override string ToTempUrl ( ) => $ "data:{ ContentType } ;base64,{ Base64 } ";
3637
37- public override string ToContentType ( ) => ContentType ;
38+ protected override string ToContentType ( ) => ContentType ;
39+ }
40+
41+ public record Base64PreviewImage : Base64Image
42+ {
43+ public FileDto ToTempFileDto ( )
44+ {
45+ return new FileDto ( )
46+ {
47+ Id = Guid . NewGuid ( ) . ToString ( ) ,
48+ ContentType = ContentType ,
49+ Url = ToTempUrl ( ) ,
50+ } ;
51+ }
3852}
3953
4054public record UrlImage : ImageChatSegment
@@ -54,9 +68,9 @@ public override async Task<DBFileDef> Download(CancellationToken cancellationTok
5468 return new DBFileDef ( bytes , contentType , fileName ) ;
5569 }
5670
57- public override string ToTempUrl ( ) => Url ;
71+ protected override string ToTempUrl ( ) => Url ;
5872
59- public override string ToContentType ( ) => Url switch
73+ protected override string ToContentType ( ) => Url switch
6074 {
6175 var x when x . Contains ( ".png" , StringComparison . OrdinalIgnoreCase ) => "image/png" ,
6276 var x when x . Contains ( ".jpg" , StringComparison . OrdinalIgnoreCase ) => "image/jpeg" ,
0 commit comments