Skip to content

Commit 67f1098

Browse files
authored
Merge pull request #84 from sdcb/dev
Dev
2 parents 56ac858 + abcc800 commit 67f1098

File tree

100 files changed

+4125
-1694
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+4125
-1694
lines changed

.github/workflows/build-container.yml

Lines changed: 86 additions & 70 deletions
Large diffs are not rendered by default.

src/BE/Chats.BE.csproj

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,32 @@
55
<Nullable>enable</Nullable>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<UserSecretsId>d4aa34e2-6c5f-41b9-b61b-c1a48b1d1b44</UserSecretsId>
8+
<Version>1.0.0</Version>
89
</PropertyGroup>
910

1011
<ItemGroup>
1112
<PackageReference Include="Aliyun.OSS.SDK.NetCore" Version="2.14.1" />
12-
<PackageReference Include="AWSSDK.S3" Version="3.7.415.24" />
13+
<PackageReference Include="AWSSDK.S3" Version="3.7.416.13" />
1314
<PackageReference Include="Azure.AI.OpenAI" Version="2.1.0" />
1415
<PackageReference Include="Azure.Storage.Blobs" Version="12.24.0" />
1516
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
16-
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.3">
17+
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.4">
1718
<PrivateAssets>all</PrivateAssets>
1819
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1920
</PackageReference>
20-
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.3" />
21-
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.3" />
21+
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.4" />
22+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.4" />
2223
<PackageReference Include="Microsoft.ML.Tokenizers.Data.Cl100kBase" Version="1.0.2" />
2324
<PackageReference Include="Microsoft.ML.Tokenizers.Data.O200kBase" Version="1.0.2" />
24-
<PackageReference Include="Mscc.GenerativeAI" Version="2.4.1" />
25+
<PackageReference Include="MiniExcel" Version="1.41.0" />
26+
<PackageReference Include="Mscc.GenerativeAI" Version="2.5.2" />
2527
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
2628
<PackageReference Include="OpenAI" Version="2.1.0" />
27-
<PackageReference Include="Swashbuckle.AspNetCore" Version="8.0.0" />
28-
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.7.0" />
29+
<PackageReference Include="Swashbuckle.AspNetCore" Version="8.1.1" />
30+
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.8.0" />
2931
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
30-
<PackageReference Include="System.Runtime.Caching" Version="9.0.3" />
31-
<PackageReference Include="TencentCloudSDK.Sms" Version="3.0.1207" />
32+
<PackageReference Include="System.Runtime.Caching" Version="9.0.4" />
33+
<PackageReference Include="TencentCloudSDK.Sms" Version="3.0.1223" />
3234
</ItemGroup>
3335

3436
</Project>

src/BE/Controllers/Admin/GlobalConfigs/Dtos/CheckUpdateResponse.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ public record CheckUpdateResponse
88
public required bool HasNewVersion { get; init; }
99

1010
[JsonPropertyName("tagName")]
11-
public required string TagName { get; init; }
11+
public required string? LatestVersion { get; init; }
1212

1313
[JsonPropertyName("currentVersion")]
14-
public required int CurrentVersion { get; init; }
15-
}
14+
public required string? CurrentVersion { get; init; }
15+
}

src/BE/Controllers/Admin/GlobalConfigs/GitHubReleaseChecker.cs

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,40 +27,8 @@ public async Task<string> GetLatestReleaseTagNameAsync(CancellationToken cancell
2727
response.EnsureSuccessStatusCode(); // 如果请求失败,抛出异常
2828

2929
using Stream responseStream = await response.Content.ReadAsStreamAsync(cancellationToken);
30-
var jsonDocument = await JsonDocument.ParseAsync(responseStream, cancellationToken: cancellationToken);
30+
using JsonDocument jsonDocument = await JsonDocument.ParseAsync(responseStream, cancellationToken: cancellationToken);
3131

3232
return jsonDocument.RootElement.GetProperty("tag_name").GetString()!;
3333
}
34-
35-
public static bool IsNewVersionAvailableAsync(string latestTagName, int currentVersion)
36-
{
37-
try
38-
{
39-
if (latestTagName.StartsWith("r-"))
40-
{
41-
int latestVersion = int.Parse(latestTagName.Substring(2));
42-
return latestVersion > currentVersion;
43-
}
44-
else
45-
{
46-
Console.WriteLine($"Warning: Latest tag name '{latestTagName}' does not follow the expected format 'r-XXX'.");
47-
return false;
48-
}
49-
}
50-
catch (HttpRequestException ex)
51-
{
52-
Console.WriteLine($"Error checking for updates: {ex.Message}");
53-
return false;
54-
}
55-
catch (JsonException ex)
56-
{
57-
Console.WriteLine($"Error parsing JSON response: {ex.Message}");
58-
return false;
59-
}
60-
catch (Exception ex)
61-
{
62-
Console.WriteLine($"An unexpected error occurred: {ex.Message}");
63-
return false;
64-
}
65-
}
6634
}
Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
11
using Chats.BE.Controllers.Admin.Common;
22
using Chats.BE.Controllers.Admin.GlobalConfigs.Dtos;
33
using Microsoft.AspNetCore.Mvc;
4+
using System.Reflection;
45

56
namespace Chats.BE.Controllers.Admin.GlobalConfigs;
67

78
[AuthorizeAdmin, Route("api/version")]
8-
public class VersionController : ControllerBase
9+
public class VersionController(ILogger<VersionController> logger) : ControllerBase
910
{
10-
// it will be replaced by CI/CD pipeline
11-
const int buildVersion = 0;
11+
static string? CurrentVersion => typeof(VersionController).Assembly
12+
.GetCustomAttribute<AssemblyFileVersionAttribute>()?
13+
.Version;
1214

1315
[HttpGet]
14-
public ActionResult<int> GetCurrentVersion()
16+
public ActionResult<string> GetCurrentVersion()
1517
{
16-
return Ok(buildVersion);
18+
return Ok(CurrentVersion);
1719
}
1820

1921
[HttpPost("check-update")]
2022
public async Task<ActionResult<CheckUpdateResponse>> CheckUpdate(
2123
[FromServices] ILogger<VersionController> logger,
2224
CancellationToken cancellationToken)
2325
{
24-
string tagName = "r-" + buildVersion;
26+
string? tagName = null;
2527
try
2628
{
2729
tagName = await GitHubReleaseChecker.SdcbChats.GetLatestReleaseTagNameAsync(cancellationToken);
@@ -31,12 +33,39 @@ public async Task<ActionResult<CheckUpdateResponse>> CheckUpdate(
3133
logger.LogWarning(e, "Failed to get latest release tag name from GitHub.");
3234
}
3335

34-
bool hasNewVersion = GitHubReleaseChecker.IsNewVersionAvailableAsync(tagName, buildVersion);
36+
bool hasNewVersion = IsNewVersionAvailableAsync(tagName, CurrentVersion);
3537
return Ok(new CheckUpdateResponse
3638
{
37-
CurrentVersion = buildVersion,
39+
CurrentVersion = CurrentVersion,
40+
LatestVersion = tagName,
3841
HasNewVersion = hasNewVersion,
39-
TagName = tagName,
4042
});
4143
}
44+
45+
bool IsNewVersionAvailableAsync(string? latestTagName, string? currentVersion)
46+
{
47+
// latestTagName format: 1.0.0.587
48+
// currentVersion format: 1.0.0.586
49+
if (string.IsNullOrEmpty(latestTagName) || string.IsNullOrEmpty(currentVersion))
50+
{
51+
return false;
52+
}
53+
54+
if (latestTagName.StartsWith("r-"))
55+
{
56+
return false;
57+
}
58+
59+
try
60+
{
61+
Version latestVersion = Version.Parse(latestTagName);
62+
Version currentVersionParsed = Version.Parse(currentVersion);
63+
return latestVersion > currentVersionParsed;
64+
}
65+
catch (Exception)
66+
{
67+
logger.LogWarning("Failed to parse version strings: {LatestTagName}, {CurrentVersion}", latestTagName, currentVersion);
68+
return false;
69+
}
70+
}
4271
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Chats.BE.Controllers.Admin.Statistics.Dtos;
2+
3+
public record CostStatisticsEntry
4+
{
5+
public decimal InputCost { get; init; }
6+
public decimal OutputCost { get; init; }
7+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
3+
namespace Chats.BE.Controllers.Admin.Statistics.Dtos;
4+
5+
public record DateStatisticsEntry<T>
6+
{
7+
public required DateOnly Date { get; init; }
8+
public required T Value { get; init; }
9+
10+
[SetsRequiredMembers]
11+
public DateStatisticsEntry(DateOnly date, T value)
12+
{
13+
Date = date;
14+
Value = value;
15+
}
16+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
3+
namespace Chats.BE.Controllers.Admin.Statistics.Dtos;
4+
5+
public record SingleValueStatisticsEntry
6+
{
7+
public required string Key { get; init; }
8+
9+
public required int Count { get; init; }
10+
11+
[SetsRequiredMembers]
12+
public SingleValueStatisticsEntry(string key, int count)
13+
{
14+
Key = key;
15+
Count = count;
16+
}
17+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
3+
4+
namespace Chats.BE.Controllers.Admin.Statistics.Dtos;
5+
6+
public record StartEndDate
7+
{
8+
[FromQuery(Name = "start")]
9+
public DateOnly? Start { get; init; }
10+
11+
[FromQuery(Name = "end")]
12+
public DateOnly? End { get; init; }
13+
14+
[FromQuery(Name = "tz")]
15+
public short TimezoneOffset { get; init; }
16+
17+
internal DateTime? StartDate => Start?.ToDateTime(new TimeOnly(), DateTimeKind.Utc)
18+
.AddMinutes(TimezoneOffset);
19+
20+
internal DateTime? EndDate => End?.ToDateTime(new TimeOnly(), DateTimeKind.Utc)
21+
.AddMinutes(TimezoneOffset);
22+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace Chats.BE.Controllers.Admin.Statistics.Dtos;
2+
3+
public record TokenStatisticsEntry
4+
{
5+
public int InputTokens { get; init; }
6+
7+
public int OutputTokens { get; init; }
8+
9+
public int ReasoningTokens { get; init; }
10+
11+
public int TotalTokens => InputTokens + OutputTokens;
12+
}

0 commit comments

Comments
 (0)