1+ using System . Text . Json . Serialization ;
2+ using Lagrange . Core ;
3+ using Lagrange . Core . Common . Interface ;
4+ using Lagrange . Milky . Utility ;
5+
6+ namespace Lagrange . Milky . Api . Handler . File ;
7+
8+ [ Api ( "upload_private_file" ) ]
9+ public class UploadPrivateFileHandler ( BotContext bot , ResourceResolver resolver ) : IApiHandler < UploadPrivateFileParameter , UploadPrivateFileResult >
10+ {
11+ private readonly BotContext _bot = bot ;
12+ private readonly ResourceResolver _resolver = resolver ;
13+
14+ public async Task < UploadPrivateFileResult > HandleAsync ( UploadPrivateFileParameter parameter , CancellationToken token )
15+ {
16+ var stream = await _resolver . ToMemoryStreamAsync ( parameter . FileUri , token ) ;
17+ ( int _ , _ ) = await _bot . SendFriendFile ( parameter . UserId , stream , parameter . FileName ) ;
18+
19+ // TODO: The URL cannot be located at this time
20+ return new UploadPrivateFileResult ( string . Empty ) ;
21+ }
22+ }
23+
24+ public class UploadPrivateFileParameter ( long userId , string fileUri , string fileName )
25+ {
26+ [ JsonRequired ]
27+ [ JsonPropertyName ( "user_id" ) ]
28+ public long UserId { get ; init ; } = userId ;
29+
30+ [ JsonRequired ]
31+ [ JsonPropertyName ( "file_uri" ) ]
32+ public string FileUri { get ; init ; } = fileUri ;
33+
34+ [ JsonRequired ]
35+ [ JsonPropertyName ( "file_name" ) ]
36+ public string FileName { get ; init ; } = fileName ;
37+ }
38+
39+ public class UploadPrivateFileResult ( string fileId )
40+ {
41+ [ JsonPropertyName ( "file_id" ) ]
42+ public string FileId { get ; } = fileId ;
43+ }
0 commit comments