Skip to content

Commit b74ebff

Browse files
committed
fix(Server): AppType filtering, WebRootPath, and new patch package
- Use IWebHostEnvironment.WebRootPath instead of AppDomain.BaseDirectory to correctly locate wwwroot in both dev and publish scenarios - Filter patches by request.AppType to avoid returning mismatched updates - Remove hardcoded call counter to allow repeated test runs - Add patch_20260529221936.zip with matching SHA256 hash - Update csproj to copy patch_*.zip to output directory
1 parent 5ffa4e1 commit b74ebff

5 files changed

Lines changed: 24 additions & 17 deletions

File tree

src/Server/Program.cs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,45 @@
33
var builder = WebApplication.CreateBuilder(args);
44
var app = builder.Build();
55

6-
int count = 0;
7-
string packageName = "packet_20250102230201638_1.0.0.1";
6+
string packageName = "patch_20260529221936";
87

98
app.MapPost("/Upgrade/Report", (ReportDTO request) =>
109
{
1110
return HttpResponseDTO<bool>.Success(true,"has update.");
1211
});
1312

14-
app.MapPost("/Upgrade/Verification", (VerifyDTO request) =>
13+
app.MapPost("/Upgrade/Verification", (VerifyDTO request, IWebHostEnvironment env) =>
1514
{
16-
count++;
17-
if (count > 2)
15+
// Use WebRootPath to correctly locate wwwroot in both dev (project dir) and publish scenarios.
16+
var filePath = Path.Combine(env.WebRootPath, "packages", $"{packageName}.zip");
17+
var packet = new FileInfo(filePath);
18+
if (!packet.Exists)
1819
{
19-
return HttpResponseDTO<IEnumerable<VerificationResultDTO>>.Success(Enumerable.Empty<VerificationResultDTO>(), "Upgrade completed.");
20+
return HttpResponseDTO<IEnumerable<VerificationResultDTO>>.InnerException(
21+
$"Package file not found: {filePath}");
22+
}
23+
24+
// Only return patches whose AppType matches the request.
25+
// Client convention: Client=1, Upgrade=2 (matches GeneralUpdate.Core.AppType enum).
26+
// This patch is a main application update (AppType=Client).
27+
const int patchAppType = 2; // Client
28+
if (request.AppType != null && request.AppType != patchAppType)
29+
{
30+
return HttpResponseDTO<IEnumerable<VerificationResultDTO>>.Success(
31+
Enumerable.Empty<VerificationResultDTO>(), "No matching update for this app type.");
2032
}
2133

22-
var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "wwwroot", "packages", $"{packageName}.zip");
23-
var packet = new FileInfo(filePath);
2434
var result = new List<VerificationResultDTO>
2535
{
2636
new VerificationResultDTO
2737
{
2838
RecordId = 1,
2939
Name = packageName,
30-
Hash = "ad1a85a9169ca0083ab54ba390e085c56b9059efc3ca8aa1ec9ed857683cc4b1",
40+
Hash = "0ad66de07179921e7ab5d2f38d39e92ca73969136d42536e0381b9f86082b4e5",
3141
ReleaseDate = DateTime.Now,
3242
Url = $"http://localhost:5000/packages/{packageName}.zip",
3343
Version = "1.0.0.1",
34-
AppType = 1,
44+
AppType = patchAppType,
3545
Platform = 1,
3646
ProductId = "2d974e2a-31e6-4887-9bb1-b4689e98c77a",
3747
IsForcibly = false,

src/Server/ServerSample.csproj

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<Content Update="wwwroot\packages\versions.json">
1212
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
1313
</Content>
14-
<Content Update="wwwroot\packages\packet_20250102230201638_1.0.0.1.zip">
14+
<Content Update="wwwroot\packages\patch_*.zip">
1515
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
1616
</Content>
1717
</ItemGroup>
@@ -22,9 +22,6 @@
2222
<None Update="packages\packet_20250102230201638_1.0.0.1.zip">
2323
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
2424
</None>
25-
<None Include="wwwroot\packages\packet_20250102230201638_1.0.0.1.zip">
26-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
27-
</None>
2825
</ItemGroup>
2926

3027
<ItemGroup>
-338 Bytes
Binary file not shown.
722 Bytes
Binary file not shown.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
[
22
{
3-
"PacketName": "packet_20250102230201638_1.0.0.1",
4-
"Hash": "ad1a85a9169ca0083ab54ba390e085c56b9059efc3ca8aa1ec9ed857683cc4b1",
3+
"PacketName": "patch_20260529221936",
4+
"Hash": "0ad66de07179921e7ab5d2f38d39e92ca73969136d42536e0381b9f86082b4e5",
55
"Version": "1.0.0.1",
6-
"Url": "http://localhost:5000/packages/packet_20250102230201638_1.0.0.1.zip",
6+
"Url": "http://localhost:5000/packages/patch_20260529221936.zip",
77
"PubTime": "2025-01-02T23:48:21"
88
}
99
]

0 commit comments

Comments
 (0)