Skip to content

Commit d49a9e8

Browse files
authored
doc(IP2Region): support IPv6 format (#7661)
* refactor: 移除 BaiduV2 定位器 * doc: 更新文档 * test: 调整单元测试 * doc(IP2Region): 更新文档 * feat(IP2Region): support IPv6 format bump version 10.0.1
1 parent bec6064 commit d49a9e8

File tree

8 files changed

+14
-225
lines changed

8 files changed

+14
-225
lines changed

src/BootstrapBlazor.Server/BootstrapBlazor.Server.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
<PackageReference Include="BootstrapBlazor.Html2Pdf" Version="10.0.2" />
5050
<PackageReference Include="BootstrapBlazor.IconPark" Version="10.0.0" />
5151
<PackageReference Include="BootstrapBlazor.ImageCropper" Version="10.0.0" />
52-
<PackageReference Include="BootstrapBlazor.IP2Region" Version="10.0.0" />
52+
<PackageReference Include="BootstrapBlazor.IP2Region" Version="10.0.1" />
5353
<PackageReference Include="BootstrapBlazor.JitsiMeet" Version="10.0.0" />
5454
<PackageReference Include="BootstrapBlazor.JuHeIpLocatorProvider" Version="10.0.0" />
5555
<PackageReference Include="BootstrapBlazor.Live2DDisplay" Version="10.0.0" />

src/BootstrapBlazor.Server/Components/Samples/Locators.razor

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@page "/locator"
1+
@page "/locator"
22

33
<h3>@Localizer["LocatorsTitle"]</h3>
44

@@ -38,14 +38,16 @@ Location = await provider.Locate(Ip);</Pre>
3838
<p>@Localizer["LocatorsNormalIpTitle"]</p>
3939
<p><code>112.224.74.239</code> @Localizer["LocatorsNormalTips3"]</p>
4040
<p><code>183.160.236.53</code> @Localizer["LocatorsNormalTips4"]</p>
41+
<p><code>240e:3b7:3272:d8d0:db09:c067:8d59:539e</code> @Localizer["LocatorsNormalTips5"]</p>
4142

4243
<DemoBlock Title="@Localizer["LocatorsNormalTitle"]" Introduction="@Localizer["LocatorsNormalIntro"]" Name="Normal">
4344
<section ignore>
4445
@((MarkupString)Localizer["LocatorsProviderDesc"].Value)
4546
</section>
4647
<div class="row g-3 form-inline">
4748
<div class="col-12 col-sm-6">
48-
<Select Items="_providers" Value="@ProviderName" OnValueChanged="OnProviderNameChanged" ShowLabel="true" DisplayText="LocatorProvider">
49+
<Select Items="_providers" Value="@ProviderName" OnValueChanged="OnProviderNameChanged"
50+
ShowLabel="true" DisplayText="LocatorProvider">
4951
</Select>
5052
</div>
5153
<div class="col-12 col-sm-6">

src/BootstrapBlazor.Server/Components/Samples/Locators.razor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the Apache 2.0 License
33
// See the LICENSE file in the project root for more information.
44
// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone
@@ -30,7 +30,7 @@ public partial class Locators
3030

3131
private string? Location { get; set; }
3232

33-
private string ProviderName { get; set; } = nameof(BaiduIpLocatorProviderV2);
33+
private string ProviderName { get; set; } = nameof(BaiduIpLocatorProvider);
3434

3535
[NotNull]
3636
private List<SelectedItem>? _providers = null;

src/BootstrapBlazor.Server/Locales/en-US.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2982,9 +2982,10 @@
29822982
"LocatorsNormalTips2": "The <code>Startup</code> file add the following phrase to the <code>ConfigureServices</code> method",
29832983
"LocatorsNormalTips3": "Shandong, China Unicom",
29842984
"LocatorsNormalTips4": "Shushan District Hefei, Anhui China Telecom",
2985+
"LocatorsNormalTips5": "Bao'an District, Shenzhen, Guangdong China Telecom",
29852986
"LocatorsNormalTipsTitle": "Some geographic location query interfaces may return character sets from other character sets such as<code>gbk</code>, and the program may report an error",
29862987
"LocatorsNormalTitle": "Basic usage",
2987-
"LocatorsProviderDesc": "<p>The component library has two built-in free online geolocation locators, <code>BaiduIpLocatorProvider</code> <code>BaiduIpLocatorProviderV2</code><p><p>The component library has a built-in paid online geolocation locator <code>BootstrapBlazor.JuHeIpLocatorProvider</code> <a href=\"https://www.nuget.org/packages/BootstrapBlazor.JuHeIpLocatorProvider\" target=\"_blank\">Nuget package</a> <a href=\"https://juhe.cn\" target=\"_blank\">Official website address</a></p><p>The component library has a built-in free offline geolocation locator <code>BootstrapBlazor.IP2Region</code> <a href=\"https://www.nuget.org/packages/BootstrapBlazor.IP2Region\" target=\"_blank\">Nuget package</a></p>",
2988+
"LocatorsProviderDesc": "<p>The component library built-in free online geolocation locators, <code>BaiduIpLocatorProvider</code><p><p>The component library has a built-in paid online geolocation locator <code>BootstrapBlazor.JuHeIpLocatorProvider</code> <a href=\"https://www.nuget.org/packages/BootstrapBlazor.JuHeIpLocatorProvider\" target=\"_blank\">Nuget package</a> <a href=\"https://juhe.cn\" target=\"_blank\">Official website address</a></p><p>The component library has a built-in free offline geolocation locator <code>BootstrapBlazor.IP2Region</code> <a href=\"https://www.nuget.org/packages/BootstrapBlazor.IP2Region\" target=\"_blank\">Nuget package</a>. Supports IPv6 format.</p>",
29882989
"LocatorsSubTitle": "More for system log tracking and analysis",
29892990
"LocatorsTitle": "Get the IP geographic location"
29902991
},

src/BootstrapBlazor.Server/Locales/zh-CN.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2982,9 +2982,10 @@
29822982
"LocatorsNormalTips2": "<code>Startup</code> 文件中 <code>ConfigureServices</code> 方法内增加下面这句话即可解决",
29832983
"LocatorsNormalTips3": "山东省 中国联通",
29842984
"LocatorsNormalTips4": "安徽省合肥市蜀山区 中国电信",
2985+
"LocatorsNormalTips5": "广东省深圳市宝安区 中国电信",
29852986
"LocatorsNormalTipsTitle": "某些地理位置查询接口返回字符集可能是其他字符集如 <code>gbk</code>,程序会报错;",
29862987
"LocatorsNormalTitle": "普通用法",
2987-
"LocatorsProviderDesc": "<p>组件库内置两个免费在线地理位置定位器分别为 <code>BaiduIpLocatorProvider</code> <code>BaiduIpLocatorProviderV2</code><p><p>组件库内置一个收费在线地理位置定位器 <code>BootstrapBlazor.JuHeIpLocatorProvider</code> <a href=\"https://www.nuget.org/packages/BootstrapBlazor.JuHeIpLocatorProvider\" target=\"_blank\">Nuget 包</a> <a href=\"https://juhe.cn\" target=\"_blank\">官网地址</a></p><p>组件库内置一个免费离线地理位置定位器 <code>BootstrapBlazor.IP2Region</code> <a href=\"https://www.nuget.org/packages/BootstrapBlazor.IP2Region\" target=\"_blank\">Nuget 包</a></p>",
2988+
"LocatorsProviderDesc": "<p>组件库内置免费一个在线地理位置定位器 <code>BaiduIpLocatorProvider</code><p><p>组件库内置一个收费在线地理位置定位器 <code>BootstrapBlazor.JuHeIpLocatorProvider</code> <a href=\"https://www.nuget.org/packages/BootstrapBlazor.JuHeIpLocatorProvider\" target=\"_blank\">Nuget 包</a> <a href=\"https://juhe.cn\" target=\"_blank\">官网地址</a></p><p>组件库内置一个免费离线地理位置定位器 <code>BootstrapBlazor.IP2Region</code> <a href=\"https://www.nuget.org/packages/BootstrapBlazor.IP2Region\" target=\"_blank\">Nuget 包</a> 支持 <code>IPv6<code> 格式</p>",
29882989
"LocatorsSubTitle": "多用于系统日志跟踪与分析",
29892990
"LocatorsTitle": "获取 IP 地理位置"
29902991
},

src/BootstrapBlazor/Extensions/BootstrapBlazorServiceCollectionExtensions.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,9 @@ public static IServiceCollection AddBootstrapBlazor(this IServiceCollection serv
6969
// <para lang="en">IP Locator Service</para>
7070
services.TryAddSingleton<IIpLocatorFactory, DefaultIpLocatorFactory>();
7171
services.AddSingleton<IIpLocatorProvider, BaiduIpLocatorProvider>();
72-
services.AddSingleton<IIpLocatorProvider, BaiduIpLocatorProviderV2>();
7372

7473
#if NET8_0_OR_GREATER
7574
services.AddKeyedSingleton<IIpLocatorProvider, BaiduIpLocatorProvider>(nameof(BaiduIpLocatorProvider));
76-
services.AddKeyedSingleton<IIpLocatorProvider, BaiduIpLocatorProviderV2>(nameof(BaiduIpLocatorProviderV2));
7775
#endif
7876

7977
// <para lang="zh">节日服务</para>

src/BootstrapBlazor/Services/IPLocator/BaiduIpLocatorProviderV2.cs

Lines changed: 0 additions & 169 deletions
This file was deleted.

test/UnitTest/Services/IpLocatorTest.cs

Lines changed: 3 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -36,40 +36,19 @@ public async Task BaiduIpLocatorProvider_Ok()
3636
// 关闭缓存
3737
option.Value.IpLocatorOptions.EnableCache = false;
3838
option.Value.IpLocatorOptions.SlidingExpiration = TimeSpan.FromMinutes(5);
39-
option.Value.IpLocatorOptions.ProviderName = nameof(BaiduIpLocatorProviderV2);
39+
option.Value.IpLocatorOptions.ProviderName = nameof(BaiduIpLocatorProvider);
4040
await provider.Locate("223.91.188.112");
4141
Assert.Equal("美国", result);
4242
}
4343

44-
[Fact]
45-
public async Task BaiduIpLocatorProviderV2_Ok()
46-
{
47-
var factory = Context.Services.GetRequiredService<IHttpClientFactory>();
48-
var option = Context.Services.GetRequiredService<IOptions<BootstrapBlazorOptions>>();
49-
var logger = Context.Services.GetRequiredService<ILogger<MockProviderV2>>();
50-
var provider = new MockProviderV2(factory, option, logger);
51-
52-
var result = await provider.Locate("127.0.0.1");
53-
Assert.Equal("localhost", result);
54-
55-
result = await provider.Locate("");
56-
Assert.Equal("localhost", result);
57-
58-
// 河南省漯河市 移动
59-
result = await provider.Locate("223.91.188.112");
60-
Assert.Equal("省份城市区县 测试", result);
61-
}
62-
6344
[Fact]
6445
public void Factory_Ok()
6546
{
6647
var factory = Context.Services.GetRequiredService<IIpLocatorFactory>();
67-
Assert.NotNull(factory.Create("BaiduIpLocatorProviderV2"));
6848
Assert.NotNull(factory.Create("BaiduIpLocatorProvider"));
6949
Assert.NotNull(factory.Create());
7050

7151
Assert.NotNull(Context.Services.GetKeyedService<IIpLocatorProvider>("BaiduIpLocatorProvider"));
72-
Assert.NotNull(Context.Services.GetKeyedService<IIpLocatorProvider>("BaiduIpLocatorProviderV2"));
7352
}
7453

7554
[Fact]
@@ -89,8 +68,8 @@ public async Task Fetch_Error()
8968
var result = await provider.Locate("223.91.188.112");
9069
Assert.Null(result);
9170

92-
var cancelPprovider = new MockProviderFetchCancelError(factory, option, logger);
93-
result = await cancelPprovider.Locate("223.91.188.112");
71+
var cancelProvider = new MockProviderFetchCancelError(factory, option, logger);
72+
result = await cancelProvider.Locate("223.91.188.112");
9473
Assert.Null(result);
9574
}
9675

@@ -104,11 +83,6 @@ public async Task Fetch_Result_Fail()
10483
var provider = new MockBaiduProvider(factory, option, logger);
10584
var result = await provider.Locate("223.91.188.112");
10685
Assert.Null(result);
107-
108-
var loggerV2 = Context.Services.GetRequiredService<ILogger<MockBaiduProviderV2>>();
109-
var providerV2 = new MockBaiduProviderV2(factory, option, loggerV2);
110-
result = await providerV2.Locate("223.91.188.112");
111-
Assert.Null(result);
11286
}
11387

11488
class MockProviderFetchError(IHttpClientFactory httpClientFactory, IOptions<BootstrapBlazorOptions> option, ILogger<MockProviderFetchError> logger) : BaiduIpLocatorProvider(httpClientFactory, option, logger)
@@ -130,15 +104,6 @@ class MockBaiduProvider(IHttpClientFactory httpClientFactory, IOptions<Bootstrap
130104
}
131105
}
132106

133-
class MockBaiduProviderV2(IHttpClientFactory httpClientFactory, IOptions<BootstrapBlazorOptions> option, ILogger<MockBaiduProviderV2> logger) : BaiduIpLocatorProviderV2(httpClientFactory, option, logger)
134-
{
135-
protected override Task<string?> Fetch(string url, HttpClient client, CancellationToken token)
136-
{
137-
client = new HttpClient(new MockHttpNullMessageHandler(), true);
138-
return base.Fetch(url, client, token);
139-
}
140-
}
141-
142107
class MockProvider(IHttpClientFactory httpClientFactory, IOptions<BootstrapBlazorOptions> option, ILogger<MockProvider> logger) : BaiduIpLocatorProvider(httpClientFactory, option, logger)
143108
{
144109
protected override Task<string?> Fetch(string url, HttpClient client, CancellationToken token)
@@ -148,15 +113,6 @@ class MockProvider(IHttpClientFactory httpClientFactory, IOptions<BootstrapBlazo
148113
}
149114
}
150115

151-
class MockProviderV2(IHttpClientFactory httpClientFactory, IOptions<BootstrapBlazorOptions> option, ILogger<MockProviderV2> logger) : BaiduIpLocatorProviderV2(httpClientFactory, option, logger)
152-
{
153-
protected override Task<string?> Fetch(string url, HttpClient client, CancellationToken token)
154-
{
155-
client = new HttpClient(new MockHttpSuccessMessageHandlerV2(), true);
156-
return base.Fetch(url, client, token);
157-
}
158-
}
159-
160116
class MockHttpNullMessageHandler : HttpMessageHandler
161117
{
162118
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)

0 commit comments

Comments
 (0)