Skip to content

Commit f6ca986

Browse files
committed
mission complete
1 parent a5235d1 commit f6ca986

File tree

57 files changed

+268
-177
lines changed

Some content is hidden

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

57 files changed

+268
-177
lines changed

最后大项目代码/Nginx配置/nginx.conf

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,18 @@ http {
4040

4141
#access_log logs/host.access.log main;
4242

43-
43+
location /FileService/ {
44+
proxy_pass http://localhost:50401/;
45+
proxy_set_header Host $host;
46+
proxy_set_header X-Real-IP $remote_addr;
47+
proxy_set_header X-Real-PORT $remote_port;
48+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
49+
proxy_set_header X-Forwarded-Proto $scheme;
50+
client_max_body_size 100m;
51+
}
4452

4553
location /IdentityService/ {
46-
proxy_pass https://localhost:44392/;
54+
proxy_pass http://localhost:50402/;
4755
proxy_set_header Host $host;
4856
proxy_set_header X-Real-IP $remote_addr;
4957
proxy_set_header X-Real-PORT $remote_port;
@@ -52,7 +60,7 @@ http {
5260
}
5361

5462
location /Listening.Admin/ {
55-
proxy_pass https://localhost:44352/;
63+
proxy_pass http://localhost:50403/;
5664
proxy_set_header Host $host;
5765
proxy_set_header X-Real-IP $remote_addr;
5866
proxy_set_header X-Real-PORT $remote_port;
@@ -62,43 +70,33 @@ http {
6270
proxy_set_header Upgrade $http_upgrade;
6371
proxy_set_header Connection "upgrade";
6472
}
65-
66-
location /MediaEncoder/ {
67-
proxy_pass https://localhost:44353/;
68-
proxy_set_header Host $host;
69-
proxy_set_header X-Real-IP $remote_addr;
70-
proxy_set_header X-Real-PORT $remote_port;
71-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
72-
proxy_set_header X-Forwarded-Proto $scheme;
73-
}
7473

7574
location /Listening.Main/ {
76-
proxy_pass https://localhost:44375/;
75+
proxy_pass http://localhost:50404/;
7776
proxy_set_header Host $host;
7877
proxy_set_header X-Real-IP $remote_addr;
7978
proxy_set_header X-Real-PORT $remote_port;
8079
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
8180
proxy_set_header X-Forwarded-Proto $scheme;
82-
}
83-
84-
location /SearchService/ {
85-
proxy_pass https://localhost:44310/;
81+
}
82+
83+
location /MediaEncoder/ {
84+
proxy_pass http://localhost:50405/;
8685
proxy_set_header Host $host;
8786
proxy_set_header X-Real-IP $remote_addr;
8887
proxy_set_header X-Real-PORT $remote_port;
89-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
90-
proxy_set_header X-Forwarded-Proto $scheme;
91-
}
88+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
89+
proxy_set_header X-Forwarded-Proto $scheme;
90+
}
9291

93-
location /FileService/ {
94-
proxy_pass https://localhost:44339/;
92+
location /SearchService/ {
93+
proxy_pass http://localhost:50406/;
9594
proxy_set_header Host $host;
9695
proxy_set_header X-Real-IP $remote_addr;
9796
proxy_set_header X-Real-PORT $remote_port;
9897
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
9998
proxy_set_header X-Forwarded-Proto $scheme;
100-
client_max_body_size 100m;
101-
}
99+
}
102100

103101
#error_page 404 /404.html;
104102

最后大项目代码/YouZack-VNext/FileService.Domain/FSDomainService.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public FSDomainService(IFSRepository repository,
2323
this.remoteStorage = storageClients.First(c => c.StorageType == StorageType.Public);
2424
}
2525

26+
//领域服务只有抽象的业务逻辑
2627
public async Task<UploadedItem> UploadAsync(Stream stream, string fileName,
2728
CancellationToken cancellationToken)
2829
{
@@ -47,6 +48,8 @@ public async Task<UploadedItem> UploadAsync(Stream stream, string fileName,
4748
Uri remoteUrl = await remoteStorage.SaveAsync(key, stream, cancellationToken);//保存到生产的存储系统
4849
stream.Position = 0;
4950
Guid id = Guid.NewGuid();
51+
//领域服务并不会真正的执行数据库插入,只是把实体对象生成,然后由应用服务和基础设施配合来真正的插入数据库!
52+
//DDD中尽量避免直接在领域服务中执行数据库的修改(包含删除、新增)操作。
5053
return UploadedItem.Create(id, fileSize, fileName, hash, backupUrl, remoteUrl);
5154
}
5255
}

最后大项目代码/YouZack-VNext/FileService.Domain/IFSRepository.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ namespace FileService.Domain
55
{
66
public interface IFSRepository
77
{
8+
/// <summary>
9+
/// 查找已经上传的相同大小以及散列值的文件记录
10+
/// </summary>
11+
/// <param name="fileSize"></param>
12+
/// <param name="sha256Hash"></param>
13+
/// <returns></returns>
814
Task<UploadedItem?> FindFileAsync(long fileSize, string sha256Hash);
915
}
1016
}

最后大项目代码/YouZack-VNext/FileService.Infrastructure/Configs/UploadedItemConfig.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ class UploadedItemConfig : IEntityTypeConfiguration<UploadedItem>
88
public void Configure(EntityTypeBuilder<UploadedItem> builder)
99
{
1010
builder.ToTable("T_FS_UploadedItems");
11+
//因为SQLServer对于Guid主键默认创建聚集索引,因此会造成每次插入新数据,都会数据库重排。
12+
//因此我们取消主键的默认的聚集索引
1113
builder.HasKey(e => e.Id).IsClustered(false);
1214
builder.Property(e => e.FileName).IsUnicode().HasMaxLength(1024);
1315
builder.Property(e => e.FileSHA256Hash).IsUnicode(false).HasMaxLength(64);
14-
builder.HasIndex(e => new { e.FileSHA256Hash, e.FileSizeInBytes });//经常要按照
16+
builder.HasIndex(e => new { e.FileSHA256Hash, e.FileSizeInBytes });//经常要按照这两个列进行查询,因此把它们两个组成复合索引,提高查询效率。
1517
}
1618
}
1719
}

最后大项目代码/YouZack-VNext/FileService.Infrastructure/Services/MockCloudStorageClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace FileService.Infrastructure.Services
66
{
77
/// <summary>
8-
/// 把文件服务器当成一个云存储服务器。文件保存在wwwroot文件夹下。
8+
/// 把FileService.WebAPI当成一个云存储服务器,是一个Mock。文件保存在wwwroot文件夹下。
99
/// 这仅供开发、演示阶段使用,在生产环境中,一定要用专门的云存储服务器来代替。
1010
/// </summary>
1111
class MockCloudStorageClient : IStorageClient

最后大项目代码/YouZack-VNext/FileService.Infrastructure/Services/SMBStorageClient.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
namespace FileService.Infrastructure.Services
55
{
6+
/// <summary>
7+
/// 用局域网内共享文件夹或者本机磁盘当备份服务器的实现类
8+
/// </summary>
69
class SMBStorageClient : IStorageClient
710
{
811
private IOptionsSnapshot<SMBStorageOptions> options;

最后大项目代码/YouZack-VNext/FileService.Infrastructure/Services/UpYunStorageClient.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
namespace FileService.Infrastructure.Services
88
{
9+
/// <summary>
10+
/// 又拍云存储服务
11+
/// </summary>
912
class UpYunStorageClient : IStorageClient
1013
{
1114
private IOptionsSnapshot<UpYunStorageOptions> options;

最后大项目代码/YouZack-VNext/FileService.WebAPI/Properties/launchSettings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"windowsAuthentication": false,
55
"anonymousAuthentication": true,
66
"iisExpress": {
7-
"applicationUrl": "http://localhost:3590/",
8-
"sslPort": 44339
7+
"applicationUrl": "http://localhost:50401/",
8+
"sslPort": 44331
99
}
1010
},
1111
"profiles": {

最后大项目代码/YouZack-VNext/FileService.WebAPI/Uploader/UploaderController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public async Task<FileExistsResponse> FileExists(long fileSize, string sha256Has
4545
//页面直传只能使用上传码上传一个文件,防止接口被恶意利用。应用服务器要控制发放上传码的频率。
4646
//todo:再提供一个非页面直传的接口,供服务器用
4747
[HttpPost]
48-
[RequestSizeLimit(100_000_000)]
48+
[RequestSizeLimit(60_000_000)]
4949
public async Task<ActionResult<Uri>> Upload([FromForm] UploadRequest request, CancellationToken cancellationToken = default)
5050
{
5151
var file = request.File;

最后大项目代码/YouZack-VNext/IdentityService.Domain/IIdRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public interface IIdRepository
77
Task<User?> FindByIdAsync(Guid userId);//根据Id获取用户
88
Task<User?> FindByNameAsync(string userName);//根据用户名获取用户
99
Task<User?> FindByPhoneNumberAsync(string phoneNum);//根据手机号获取用户
10-
Task<IdentityResult> CreateAsync(User user, string password);//创建管理员
10+
Task<IdentityResult> CreateAsync(User user, string password);//创建用户
1111
Task<IdentityResult> AccessFailedAsync(User user);//记录一次登陆失败
1212

1313
/// <summary>

最后大项目代码/YouZack-VNext/IdentityService.Domain/IdDomainService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ private async Task<SignInResult> CheckPhoneNumAndPwdAsync(string phoneNum, strin
4242
return result;
4343
}
4444

45+
//<(SignInResult Result, string? Token)> 元组的语法
4546
public async Task<(SignInResult Result, string? Token)> LoginByPhoneAndPwdAsync(string phoneNum, string password)
4647
{
4748
var checkResult = await CheckPhoneNumAndPwdAsync(phoneNum, password);

最后大项目代码/YouZack-VNext/IdentityService.Domain/新文件夹

Whitespace-only changes.

最后大项目代码/YouZack-VNext/IdentityService.WebAPI/Controllers/Login/LoginController.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public async Task<ActionResult<UserResponse>> GetUserInfo()
5454
return NotFound();
5555
}
5656
//出于安全考虑,不要机密信息传递到客户端
57+
//除非确认没问题,否则尽量不要直接把实体类对象返回给前端
5758
return new UserResponse(user.Id, user.PhoneNumber, user.CreationTime);
5859
}
5960

最后大项目代码/YouZack-VNext/IdentityService.WebAPI/Controllers/UserAdmin/UserAdminController.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ public async Task<ActionResult> AddAdminUser(AddAdminUserRequest req)
5252
return BadRequest(result.Errors.SumErrors());
5353
}
5454
//生成的密码短信发给对方
55+
//可以同时或者选择性的把新增用户的密码短信/邮件/打印给用户
56+
//体现了领域事件对于代码“高内聚、低耦合”的追求
5557
var userCreatedEvent = new UserCreatedEvent(user.Id, req.UserName, password, req.PhoneNum);
5658
eventBus.Publish("IdentityService.User.Created", userCreatedEvent);
5759
return Ok();

最后大项目代码/YouZack-VNext/IdentityService.WebAPI/Events/ResetPasswordEventHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public ResetPasswordEventHandler(ILogger<ResetPasswordEventHandler> logger, ISms
1818

1919
public override Task HandleJson(string eventName, ResetPasswordEvent? eventData)
2020
{
21-
//发送初始密码给被创建用户的手机
21+
//发送密码给被用户的手机
2222
return smsSender.SendAsync(eventData.PhoneNum, eventData.Password);
2323
}
2424
}

最后大项目代码/YouZack-VNext/IdentityService.WebAPI/Properties/launchSettings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"windowsAuthentication": false,
55
"anonymousAuthentication": true,
66
"iisExpress": {
7-
"applicationUrl": "http://localhost:2832/",
8-
"sslPort": 44392
7+
"applicationUrl": "http://localhost:50402/",
8+
"sslPort": 44332
99
}
1010
},
1111
"profiles": {

最后大项目代码/YouZack-VNext/Listening.Admin.WebAPI/EventHandlers/EpisodeCreatedEventHandler.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ public EpisodeCreatedEventHandler(IEventBus eventBus)
1414

1515
public Task Handle(EpisodeCreatedEvent notification, CancellationToken cancellationToken)
1616
{
17+
//把领域事件转发为集成事件,让其他微服务听到
18+
1719
//在领域事件处理中集中进行更新缓存等处理,而不是写到Controller中。因为项目中有可能不止一个地方操作领域对象,这样就就统一了操作。
1820
var episode = notification.Value;
1921
var sentences = episode.ParseSubtitle();

最后大项目代码/YouZack-VNext/Listening.Admin.WebAPI/EventHandlers/MediaEncodingStatusChangeIntegrationHandler.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace Listening.Admin.WebAPI.EventHandlers;
66

7+
//收听转码服务发出的集成事件
8+
//把状态通过SignalR推送给客户端,从而显示“转码进度”
79
[EventName("MediaEncoding.Started")]
810
[EventName("MediaEncoding.Failed")]
911
[EventName("MediaEncoding.Duplicated")]
@@ -50,6 +52,7 @@ public override async Task HandleDynamic(string eventName, dynamic eventData)
5052
await hubContext.Clients.All.SendAsync("OnMediaEncodingCompleted", id);//通知前端刷新
5153
break;
5254
case "MediaEncoding.Completed":
55+
//转码完成,则从Redis中把暂存的Episode信息取出来,然后正式地插入Episode表中
5356
await encHelper.UpdateEpisodeStatusAsync(id, "Completed");
5457
Uri outputUrl = new Uri(eventData.OutputUrl);
5558
var encItem = await encHelper.GetEncodingEpisodeAsync(id);
@@ -64,7 +67,8 @@ public override async Task HandleDynamic(string eventName, dynamic eventData)
6467
.AlbumId(albumId).AudioUrl(outputUrl)
6568
.DurationInSecond(encItem.DurationInSecond)
6669
.SubtitleType(encItem.SubtitleType).Subtitle(encItem.Subtitle);
67-
dbContext.Add(builder.Build());
70+
var episdoe = builder.Build();
71+
dbContext.Add(episdoe);
6872
await dbContext.SaveChangesAsync();
6973
await hubContext.Clients.All.SendAsync("OnMediaEncodingCompleted", id);//通知前端刷新
7074
break;

最后大项目代码/YouZack-VNext/Listening.Admin.WebAPI/EventHandlers/ReIndexAllEventHandler.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Listening.Admin.WebAPI.EventHandlers
44
{
55
[EventName("SearchService.ReIndexAll")]
6+
//让搜索引擎服务器,重新收录所有的Episode
67
public class ReIndexAllEventHandler : IIntegrationEventHandler
78
{
89
private readonly ListeningDbContext dbContext;

最后大项目代码/YouZack-VNext/Listening.Admin.WebAPI/Properties/launchSettings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"windowsAuthentication": false,
55
"anonymousAuthentication": true,
66
"iisExpress": {
7-
"applicationUrl": "http://localhost:63145",
8-
"sslPort": 44352
7+
"applicationUrl": "http://localhost:50403",
8+
"sslPort": 44333
99
}
1010
},
1111
"profiles": {

最后大项目代码/YouZack-VNext/Listening.Domain/Entities/Category.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,16 @@ namespace Listening.Domain.Entities
55
public record Category : AggregateRootEntity, IAggregateRoot
66
{
77
private Category() { }
8+
9+
/// <summary>
10+
/// 在所有Category中的显示序号,越小越靠前
11+
/// </summary>
812
public int SequenceNumber { get; private set; }
913
public MultilingualString Name { get; private set; }
14+
15+
/// <summary>
16+
/// 封面图片。现在一般都不会直接把图片保存到数据库中(Blob),而是只是保存图片的路径。
17+
/// </summary>
1018
public Uri CoverUrl { get; private set; }
1119

1220
public static Category Create(Guid id, int sequenceNumber, MultilingualString name, Uri coverUrl)
@@ -34,6 +42,7 @@ public Category ChangeName(MultilingualString value)
3442

3543
public Category ChangeCoverUrl(Uri value)
3644
{
45+
//todo: 做项目的时候,不管这个事件是否有被用到,都尽量publish。
3746
this.CoverUrl = value;
3847
return this;
3948
}

最后大项目代码/YouZack-VNext/Listening.Domain/Subtitles/ISubtitleParser.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,18 @@ namespace Listening.Domain.Subtitles
44
{
55
interface ISubtitleParser
66
{
7+
/// <summary>
8+
/// 本解析器是否能够解析typeName这个类型的字幕
9+
/// </summary>
10+
/// <param name="typeName"></param>
11+
/// <returns></returns>
712
bool Accept(string typeName);
13+
14+
/// <summary>
15+
/// 解析这个字幕subtitle
16+
/// </summary>
17+
/// <param name="subtitle"></param>
18+
/// <returns></returns>
819
IEnumerable<Sentence> Parse(string subtitle);
920
}
1021
}

最后大项目代码/YouZack-VNext/Listening.Domain/Subtitles/SubtitleParserFactory.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ static class SubtitleParserFactory
66

77
static SubtitleParserFactory()
88
{
9+
//扫描本程序集中的所有实现了ISubtitleParser接口的类
910
var parserTypes = typeof(SubtitleParserFactory).Assembly.GetTypes().Where(t => typeof(ISubtitleParser).IsAssignableFrom(t) && !t.IsAbstract);
11+
12+
//创建这些对象,添加到parsers
1013
foreach (var parserType in parserTypes)
1114
{
1215
ISubtitleParser parser = (ISubtitleParser)Activator.CreateInstance(parserType);
@@ -16,6 +19,7 @@ static SubtitleParserFactory()
1619

1720
public static ISubtitleParser? GetParser(string typeName)
1821
{
22+
//遍历所有解析器,挨个问他们“能解析这个格式吗”,碰到一个能解析的,就会把解析器返回
1923
foreach (var parser in parsers)
2024
{
2125
if (parser.Accept(typeName))

最后大项目代码/YouZack-VNext/Listening.Main.WebAPI/Properties/launchSettings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"windowsAuthentication": false,
55
"anonymousAuthentication": true,
66
"iisExpress": {
7-
"applicationUrl": "http://localhost:50403",
8-
"sslPort": 44375
7+
"applicationUrl": "http://localhost:50404",
8+
"sslPort": 44334
99
}
1010
},
1111
"profiles": {

最后大项目代码/YouZack-VNext/MediaEncoder.Infrastructure/Configs/EncodingItemConfig.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ class EncodingItemConfig : IEntityTypeConfiguration<EncodingItem>
99
public void Configure(EntityTypeBuilder<EncodingItem> builder)
1010
{
1111
builder.ToTable("T_ME_EncodingItems");
12+
//todo:id需要非聚集索引。
13+
//todo:符合索引。
1214
builder.Property(e => e.Name).HasMaxLength(256);
1315
builder.Property(e => e.FileSHA256Hash).HasMaxLength(64).IsUnicode(false);
1416
builder.Property(e => e.OutputFormat).HasMaxLength(10).IsUnicode(false);

最后大项目代码/YouZack-VNext/MediaEncoder.Infrastructure/ToM4AEncoder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ public async Task EncodeAsync(FileInfo sourceFile, FileInfo destFile, string des
1717
//可以用“FFmpeg.AutoGen”,因为他是bingding库,不用启动独立的进程,更靠谱。但是编程难度大,这里重点不是FFMPEG,所以先用命令行实现
1818
var inputFile = new InputFile(sourceFile);
1919
var outputFile = new OutputFile(destFile);
20-
string baseDir = AppContext.BaseDirectory;
20+
string baseDir = AppContext.BaseDirectory;//程序的运行根目录
2121
string ffmpegPath = Path.Combine(baseDir, "ffmpeg.exe");
2222
var ffmpeg = new Engine(ffmpegPath);
2323
string? errorMsg = null;
2424
ffmpeg.Error += (s, e) =>
2525
{
2626
errorMsg = e.Exception.Message;
2727
};
28-
await ffmpeg.ConvertAsync(inputFile, outputFile, ct);
28+
await ffmpeg.ConvertAsync(inputFile, outputFile, ct);//进行转码
2929
if (errorMsg != null)
3030
{
3131
throw new Exception(errorMsg);

0 commit comments

Comments
 (0)