@@ -11,14 +11,16 @@ namespace Lagrange.Core.Internal.Context.Uploader;
1111/// </summary>
1212internal static class FileUploader
1313{
14- public static async Task < bool > UploadPrivate ( ContextCollection context , MessageChain chain , IMessageEntity entity )
14+ public static async Task < ( int Retcode , string Message ) > UploadPrivate ( ContextCollection context , MessageChain chain , IMessageEntity entity )
1515 {
16- if ( entity is not FileEntity { FileStream : not null } file ) return false ;
17-
16+ if ( entity is not FileEntity { FileStream : not null } file ) return ( - 91000 , "Not FileEntity" ) ;
17+
1818 var uploadEvent = FileUploadEvent . Create ( chain . Uid ?? "" , file ) ;
1919 var result = await context . Business . SendEvent ( uploadEvent ) ;
20+ if ( result . Count == 0 ) return ( - 90000 , "(FileUploadEvent) No Event" ) ;
2021 var uploadResp = ( FileUploadEvent ) result [ 0 ] ;
21-
22+ if ( ! uploadResp . IsSuccess ) return ( uploadResp . ResultCode , $ "(FileUploadEvent) { uploadResp . Message } ") ;
23+
2224 if ( ! uploadResp . IsExist )
2325 {
2426 var ext = new FileUploadExt
@@ -75,23 +77,27 @@ public static async Task<bool> UploadPrivate(ContextCollection context, MessageC
7577 file . FileUuid = uploadResp . FileId ;
7678
7779 bool hwSuccess = await context . Highway . UploadSrcByStreamAsync ( 95 , file . FileStream , await Common . GetTicket ( context ) , file . FileMd5 , ext . Serialize ( ) . ToArray ( ) ) ;
78- if ( ! hwSuccess ) return false ;
80+ if ( ! hwSuccess ) return ( - 91001 , "Highway Failed" ) ;
7981 }
8082
8183 await file . FileStream . DisposeAsync ( ) ;
8284 var sendEvent = SendMessageEvent . Create ( chain ) ;
8385 var sendResult = await context . Business . SendEvent ( sendEvent ) ;
84- return sendResult . Count != 0 && ( ( SendMessageEvent ) sendResult [ 0 ] ) . MsgResult . Result == 0 ;
86+ if ( sendResult . Count == 0 ) return ( - 90000 , "(SendMessageEvent) No Event" ) ;
87+ var sendResp = ( SendMessageEvent ) sendResult [ 0 ] ;
88+ if ( sendResp . ResultCode != 0 ) return ( sendResp . ResultCode , $ "(SendMessageEvent) Failed!") ;
89+ return ( 0 , "ok" ) ;
8590 }
8691
87- public static async Task < bool > UploadGroup ( ContextCollection context , MessageChain chain , IMessageEntity entity , string targetDirectory )
92+ public static async Task < ( int Retcode , string Message ) > UploadGroup ( ContextCollection context , MessageChain chain , IMessageEntity entity , string targetDirectory )
8893 {
89- if ( entity is not FileEntity { FileStream : not null } file ) return false ;
90-
94+ if ( entity is not FileEntity { FileStream : not null } file ) return ( - 91000 , "Not FileEntity" ) ;
95+
9196 var uploadEvent = GroupFSUploadEvent . Create ( chain . GroupUin ?? 0 , targetDirectory , file ) ;
9297 var result = await context . Business . SendEvent ( uploadEvent ) ;
98+ if ( result . Count == 0 ) return ( - 90000 , "(GroupFSUploadEvent) No Event" ) ;
9399 var uploadResp = ( GroupFSUploadEvent ) result [ 0 ] ;
94-
100+ if ( ! uploadResp . IsSuccess ) return ( uploadResp . ResultCode , $ "(GroupFSUploadEvent) { uploadResp . Message } " ) ;
95101
96102 if ( ! uploadResp . IsExist )
97103 {
@@ -147,12 +153,16 @@ public static async Task<bool> UploadGroup(ContextCollection context, MessageCha
147153 } ;
148154
149155 bool hwSuccess = await context . Highway . UploadSrcByStreamAsync ( 71 , file . FileStream , await Common . GetTicket ( context ) , file . FileMd5 , ext . Serialize ( ) . ToArray ( ) ) ;
150- if ( ! hwSuccess ) return false ;
156+ if ( ! hwSuccess ) return ( - 91001 , "Highway Failed" ) ;
151157 }
152-
158+
153159 await file . FileStream . DisposeAsync ( ) ;
154160 var sendEvent = GroupSendFileEvent . Create ( chain . GroupUin ?? 0 , uploadResp . FileId ) ;
155161 var sendResult = await context . Business . SendEvent ( sendEvent ) ;
156- return sendResult . Count != 0 && ( ( GroupSendFileEvent ) sendResult [ 0 ] ) . ResultCode == 0 ;
162+ if ( sendResult . Count == 0 ) return ( - 90000 , "(GroupSendFileEvent) No Event" ) ;
163+ var sendResp = ( GroupSendFileEvent ) sendResult [ 0 ] ;
164+ if ( ! sendResp . IsSuccess ) return ( sendResp . ResultCode , $ "(GroupSendFileEvent) { sendResp . Message } ") ;
165+
166+ return ( 0 , "ok" ) ;
157167 }
158168}
0 commit comments