Skip to content

Commit 2fca2a6

Browse files
authored
Merge pull request #198 from cnblogs/support-oss-signed-url
feat: support aliyun oss download link generation
2 parents 0774d33 + 46bf57c commit 2fca2a6

File tree

13 files changed

+79
-12
lines changed

13 files changed

+79
-12
lines changed

src/Cnblogs.Architecture.Ddd.Cqrs.Dapper.SqlServer/Cnblogs.Architecture.Ddd.Cqrs.Dapper.SqlServer.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</ItemGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.1.2"/>
14+
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.1.4" />
1515
</ItemGroup>
1616

1717
</Project>

src/Cnblogs.Architecture.Ddd.Cqrs.DependencyInjection/CqrsInjector.cs

+12
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,18 @@ public CqrsInjector AddFileProvider<TProvider>()
128128
return this;
129129
}
130130

131+
/// <summary>
132+
/// Use given implementation of <see cref="IFileDeliveryProvider"/>.
133+
/// </summary>
134+
/// <typeparam name="TProvider">The type of implementation.</typeparam>
135+
/// <returns></returns>
136+
public CqrsInjector AddFileDeliveryProvider<TProvider>()
137+
where TProvider : class, IFileDeliveryProvider
138+
{
139+
Services.AddScoped<IFileDeliveryProvider, TProvider>();
140+
return this;
141+
}
142+
131143
/// <summary>
132144
/// 添加自定义随机数提供器。
133145
/// </summary>

src/Cnblogs.Architecture.Ddd.Cqrs.ServiceAgent/Cnblogs.Architecture.Ddd.Cqrs.ServiceAgent.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</ItemGroup>
1010
<ItemGroup>
1111
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
12-
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="8.0.0" />
12+
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="8.0.1" />
1313
</ItemGroup>
1414
<ItemGroup>
1515
<Compile Include="..\Cnblogs.Architecture.Ddd.Cqrs.AspNetCore\CqrsHeaderNames.cs">

src/Cnblogs.Architecture.Ddd.EventBus.Dapr/DaprEventBusProvider.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public async Task PublishAsync(string eventName, IntegrationEvent @event)
4040
eventName,
4141
@event,
4242
@event.TraceId ?? @event.Id);
43-
object data = @event; // do not provide type information to serializer since it's base class.
43+
object data = @event; // do not provide type information to serializer since it's base class.
4444
await _daprClient.PublishEventAsync(
4545
DaprOptions.PubSubName,
4646
DaprUtils.GetDaprTopicName(_daprOptions.AppName, eventName),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace Cnblogs.Architecture.Ddd.Infrastructure.Abstractions;
2+
3+
/// <summary>
4+
/// File provider that can create public url for user to download
5+
/// </summary>
6+
public interface IFileDeliveryProvider
7+
{
8+
/// <summary>
9+
/// Get public url to download with validate time.
10+
/// </summary>
11+
/// <param name="filename">The file filename.</param>
12+
/// <param name="duration">Duration of url availability.</param>
13+
/// <returns></returns>
14+
public Task<string> GetDownloadUrlAsync(string filename, TimeSpan duration);
15+
}

src/Cnblogs.Architecture.Ddd.Infrastructure.Dapper.Clickhouse/Cnblogs.Architecture.Ddd.Infrastructure.Dapper.Clickhouse.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
</ItemGroup>
1414

1515
<ItemGroup>
16-
<PackageReference Include="ClickHouse.Client" Version="6.8.1" />
16+
<PackageReference Include="ClickHouse.Client" Version="7.0.0" />
1717
</ItemGroup>
1818

1919
</Project>

src/Cnblogs.Architecture.Ddd.Infrastructure.Dapper/Cnblogs.Architecture.Ddd.Infrastructure.Dapper.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
<ItemGroup>
1212
<PackageReference Include="Dapper" Version="2.1.28" />
13-
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.0" />
13+
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.1" />
1414
</ItemGroup>
1515

1616
</Project>

src/Cnblogs.Architecture.Ddd.Infrastructure.EntityFramework/Cnblogs.Architecture.Ddd.Infrastructure.EntityFramework.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.0" />
12+
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.1" />
1313
</ItemGroup>
1414

1515
<ItemGroup>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using Cnblogs.Architecture.Ddd.Infrastructure.Abstractions;
2+
using Cuiliang.AliyunOssSdk;
3+
using Microsoft.Extensions.Options;
4+
5+
namespace Cnblogs.Architecture.Ddd.Infrastructure.FileProviders.AliyunOss;
6+
7+
/// <summary>
8+
/// Aliyun OSS implementation of <see cref="IFileDeliveryProvider"/>.
9+
/// </summary>
10+
public class AliyunOssFileDeliveryProvider : IFileDeliveryProvider
11+
{
12+
private readonly OssClient _client;
13+
private readonly AliyunOssOptions _options;
14+
15+
/// <summary>
16+
/// Create a <see cref="AliyunOssFileDeliveryProvider"/>.
17+
/// </summary>
18+
/// <param name="client">The oss client.</param>
19+
/// <param name="options">The options for oss client.</param>
20+
public AliyunOssFileDeliveryProvider(OssClient client, IOptions<AliyunOssOptions> options)
21+
{
22+
_client = client;
23+
_options = options.Value;
24+
}
25+
26+
/// <inheritdoc />
27+
public async Task<string> GetDownloadUrlAsync(string filename, TimeSpan duration)
28+
{
29+
var meta = await _client.GetObjectMetaAsync(_options.BucketInfo, filename);
30+
if (meta.IsSuccess == false)
31+
{
32+
throw new FileNotFoundException(meta.ErrorMessage, filename, meta.InnerException);
33+
}
34+
35+
return _client.GetFileDownloadLink(
36+
_options.BucketInfo,
37+
filename,
38+
(int)Math.Ceiling(duration.TotalSeconds));
39+
}
40+
}

src/Cnblogs.Architecture.Ddd.Infrastructure.FileProviders.AliyunOss/CqrsInjectorExtensions.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace Cnblogs.Architecture.Ddd.Infrastructure.FileProviders.AliyunOss;
1111
public static class CqrsInjectorExtensions
1212
{
1313
/// <summary>
14-
/// Use aliyun oss as default implementation of <see cref="IFileProvider"/>.
14+
/// Use aliyun oss as default implementation of <see cref="IFileProvider"/> and <see cref="IFileDeliveryProvider"/>.
1515
/// </summary>
1616
/// <param name="injector"></param>
1717
/// <param name="configuration"></param>
@@ -24,6 +24,7 @@ public static CqrsInjector UseAliyunOssFileProvider(
2424
{
2525
injector.Services.AddOssClient(configuration, configurationSectionName);
2626
injector.Services.Configure<AliyunOssOptions>(configuration.GetSection(configurationSectionName));
27-
return injector.AddFileProvider<AliyunOssFileProvider>();
27+
return injector.AddFileProvider<AliyunOssFileProvider>()
28+
.AddFileDeliveryProvider<AliyunOssFileDeliveryProvider>();
2829
}
2930
}

test/Cnblogs.Architecture.IntegrationTests/Cnblogs.Architecture.IntegrationTests.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<ItemGroup>
33
<PackageReference Include="Cnblogs.Serilog.Extensions" Version="1.1.0" />
4-
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.0" />
4+
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.1" />
55
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
66
<PackageReference Include="xunit" Version="2.6.5" />
77
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">

test/Cnblogs.Architecture.IntegrationTests/CqrsRouteMapperTests.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,7 @@ public async Task GetItem_MapHeadAndGet_SuccessAsync()
121121
// Act
122122
var uris = new[]
123123
{
124-
"/api/v1/apps/-/strings/-/value", "/api/v1/apps/-/strings/1/value",
125-
"/api/v1/apps/someApp/strings/-/value", "/api/v1/apps/someApp/strings/1/value"
124+
"/api/v1/apps/-/strings/-/value", "/api/v1/apps/-/strings/1/value", "/api/v1/apps/someApp/strings/-/value", "/api/v1/apps/someApp/strings/1/value"
126125
}.Select(x => new HttpRequestMessage(HttpMethod.Head, x));
127126
var responses = new List<HttpResponseMessage>();
128127
foreach (var uri in uris)

test/Cnblogs.Architecture.UnitTests/Cnblogs.Architecture.UnitTests.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<ItemGroup>
4-
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.0" />
4+
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.1" />
55
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
66
<PackageReference Include="xunit" Version="2.6.5" />
77
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">

0 commit comments

Comments
 (0)