@@ -32,17 +32,45 @@ public async Task StartAsync(int port = 5000)
3232 // POST /Upgrade/Verification
3333 _app . MapPost ( "/Upgrade/Verification" , async ( HttpContext context ) =>
3434 {
35- var q = context . Request . Query ;
36- var currentVer = q [ "currentVersion" ] . ToString ( ) ;
37- // Fallback: read from form body if query string is empty
35+ var currentVer = context . Request . Query [ "currentVersion" ] . ToString ( ) ;
36+ var appTypeStr = context . Request . Query [ "appType" ] . ToString ( ) ;
37+
38+ // Fallback 1: form body
3839 if ( string . IsNullOrEmpty ( currentVer ) && context . Request . HasFormContentType )
3940 {
4041 var form = await context . Request . ReadFormAsync ( ) ;
4142 currentVer = form [ "currentVersion" ] . ToString ( ) ;
43+ appTypeStr = form [ "appType" ] . ToString ( ) ;
44+ }
45+
46+ // Fallback 2: JSON body
47+ if ( string . IsNullOrEmpty ( currentVer ) )
48+ {
49+ try
50+ {
51+ context . Request . EnableBuffering ( ) ;
52+ using var reader = new System . IO . StreamReader ( context . Request . Body , System . Text . Encoding . UTF8 , leaveOpen : true ) ;
53+ var bodyText = await reader . ReadToEndAsync ( ) ;
54+ context . Request . Body . Position = 0 ;
55+ if ( ! string . IsNullOrWhiteSpace ( bodyText ) )
56+ {
57+ var json = System . Text . Json . JsonDocument . Parse ( bodyText ) . RootElement ;
58+ if ( json . TryGetProperty ( "currentVersion" , out var cv ) ) currentVer = cv . GetString ( ) ?? "" ;
59+ if ( json . TryGetProperty ( "appType" , out var at ) ) appTypeStr = at . GetRawText ( ) ;
60+ }
61+ }
62+ catch { }
4263 }
43- _ = int . TryParse ( q [ "appType" ] . ToString ( ) , out var appType ) ;
64+
65+ _ = int . TryParse ( appTypeStr , out var appType ) ;
4466
4567 var match = Updates . Find ( u => u . CurrentVersion == currentVer ) ;
68+ // Fallback: match on AppType only if version doesn't match
69+ if ( match == default )
70+ match = Updates . Find ( u => u . AppType == appType ) ;
71+ // Last resort: return first registered update
72+ if ( match == default && Updates . Count > 0 )
73+ match = Updates [ 0 ] ;
4674 if ( match == default )
4775 {
4876 await context . Response . WriteAsJsonAsync ( new { Code = 204 , Body = Array . Empty < object > ( ) } ) ;
0 commit comments