Ver Fonte

fix(app): 保留下载代理前缀(server 1.0.629)

Co-authored-by: Cursor <cursoragent@cursor.com>
YY968XX há 10 horas atrás
pai
commit
7737c3515b

+ 8 - 2
server/Admin.NET.Core/Service/AppVersion/SysAppReleaseService.cs

@@ -198,13 +198,19 @@ public sealed class SysAppReleaseService : IDynamicApiController, ITransient
             VersionName = consumed.Record.VersionName,
             VersionName = consumed.Record.VersionName,
             Sha256 = consumed.Record.Sha256,
             Sha256 = consumed.Record.Sha256,
         }, TimeSpan.FromMinutes(grantTtlMinutes));
         }, TimeSpan.FromMinutes(grantTtlMinutes));
-        var escapedGrant = Uri.EscapeDataString(grant.Token);
         return new RedirectResult(
         return new RedirectResult(
-            BuildAbsoluteUrl($"/api/sysAppRelease/file?grant={escapedGrant}"),
+            BuildDownloadGrantRedirectUrl(grant.Token),
             permanent: false,
             permanent: false,
             preserveMethod: false);
             preserveMethod: false);
     }
     }
 
 
+    /// <summary>
+    /// 返回相对 Location,让浏览器从当前下载端点继承 /prod-api 等反向代理前缀。
+    /// </summary>
+    [NonAction]
+    public static string BuildDownloadGrantRedirectUrl(string grant) =>
+        $"file?grant={Uri.EscapeDataString(grant)}";
+
     /// <summary>
     /// <summary>
     /// 使用短时下载凭证输出 APK;允许 Android 下载管理器在有效期内重试和断点续传。
     /// 使用短时下载凭证输出 APK;允许 Android 下载管理器在有效期内重试和断点续传。
     /// </summary>
     /// </summary>

+ 12 - 0
server/Admin.NET.Test/Security/AppReleaseSecurityTests.cs

@@ -261,6 +261,18 @@ public class AppReleaseSecurityTests
         Assert.Contains("EnableRangeProcessing = true", releaseService);
         Assert.Contains("EnableRangeProcessing = true", releaseService);
     }
     }
 
 
+    [Fact]
+    public void DownloadGrantRedirect_IsRelativeAndPreservesReverseProxyPrefix()
+    {
+        var location = SysAppReleaseService.BuildDownloadGrantRedirectUrl("a+b_c");
+
+        Assert.Equal("file?grant=a%2Bb_c", location);
+        Assert.False(Uri.TryCreate(location, UriKind.Absolute, out _));
+        Assert.Equal(
+            "https://mdiop.example.com/prod-api/api/sysAppRelease/file?grant=a%2Bb_c",
+            new Uri(new Uri("https://mdiop.example.com/prod-api/api/sysAppRelease/download?ticket=qr"), location).AbsoluteUri);
+    }
+
     private static AppReleaseSnapshot CurrentRelease() => new()
     private static AppReleaseSnapshot CurrentRelease() => new()
     {
     {
         FileId = 10,
         FileId = 10,

+ 3 - 3
server/Admin.NET.Web.Entry/Admin.NET.Web.Entry.csproj

@@ -11,9 +11,9 @@
     <GenerateSatelliteAssembliesForCore>true</GenerateSatelliteAssembliesForCore>
     <GenerateSatelliteAssembliesForCore>true</GenerateSatelliteAssembliesForCore>
     <Copyright>Admin.NET</Copyright>
     <Copyright>Admin.NET</Copyright>
     <Description>Admin.NET 通用权限开发平台</Description>
     <Description>Admin.NET 通用权限开发平台</Description>
-    <AssemblyVersion>1.0.628</AssemblyVersion>
-    <FileVersion>1.0.628</FileVersion>
-    <Version>1.0.628</Version>
+    <AssemblyVersion>1.0.629</AssemblyVersion>
+    <FileVersion>1.0.629</FileVersion>
+    <Version>1.0.629</Version>
   </PropertyGroup>
   </PropertyGroup>
 
 
   <ItemGroup>
   <ItemGroup>