Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project>
<ItemGroup>
<!-- AutoMapper 12/14 在当前仓库依赖链中暂无可无痛升级的免费修复线,
先保留审计可见性,仅对该已评估告警做仓库级抑制,避免污染整个解空间的构建结果。 -->
<NuGetAuditSuppress Include="https://github.com/advisories/GHSA-rvv3-g6hj-g44x" />
</ItemGroup>
</Project>
3 changes: 2 additions & 1 deletion src/StarBlog.Api/Apis/Admin/ConfigController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using StarBlog.Data.Models;
using StarBlog.Api.Extensions;
using StarBlog.Application.Services;
using StarBlog.Application.ViewModels.Config;

namespace StarBlog.Api.Apis.Admin;

Expand Down Expand Up @@ -61,4 +62,4 @@ public ApiResponse Delete(string key) {
var item = _service.GetByKey(key);
return item == null ? ApiResponse.NotFound() : ApiResponse.Ok($"已删除 {_service.DeleteByKey(key)} 条数据");
}
}
}
2 changes: 2 additions & 0 deletions src/StarBlog.Api/Apis/Admin/VisitRecordController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public async Task<ApiResponse<VisitOverview>> Overview([FromQuery] VisitRecordPa
/// <summary>
/// 趋势数据
/// </summary>
/// <param name="p">访问记录筛选条件</param>
/// <param name="days">查看最近几天的数据,默认7天</param>
/// <returns></returns>
[HttpGet("[action]")]
Expand All @@ -74,6 +75,7 @@ public async Task<ApiResponse<List<HourlyTrend>>> HourlyTrend([FromQuery] VisitR
/// <summary>
/// 获取地理信息筛选参数
/// </summary>
/// <param name="p">访问记录筛选条件</param>
/// <param name="param">可选 country, province, city</param>
[HttpGet("[action]")]
public async Task<ApiResponse<List<string?>>> GeoFilterParams([FromQuery] VisitRecordParameters p, string param = "country") {
Expand Down
2 changes: 1 addition & 1 deletion src/StarBlog.Api/StarBlog.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<PackageReference Include="CodeLab.Share" Version="1.4.2" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="10.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.DynamicLinq" Version="10.7.1" />
<PackageReference Include="Microsoft.OpenApi" Version="2.4.1" />
<PackageReference Include="Microsoft.OpenApi" Version="2.9.0" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.12" />
<PackageReference Include="SixLabors.ImageSharp.Web" Version="3.2.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.1.2" />
Expand Down
4 changes: 2 additions & 2 deletions src/StarBlog.Application/Contrib/SiteMessage/Message.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace StarBlog.Application.Contrib.SiteMessage;

public class Message {
public string Tag { get; set; }
public string Tag { get; set; } = string.Empty;
public string? Title { get; set; }
public string? Content { get; set; }
}
Expand All @@ -12,4 +12,4 @@ public static class MessageTags {
public const string Success = "success";
public const string Warning = "warning";
public const string Error = "danger";
}
}
10 changes: 5 additions & 5 deletions src/StarBlog.Application/Models/Config/Auth.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
namespace StarBlog.Application.Models.Config;

public class Auth {
public Jwt Jwt { get; set; }
public Jwt Jwt { get; set; } = new();
}

public class Jwt {
public string Issuer { get; set; }
public string Audience { get; set; }
public string Key { get; set; }
}
public string Issuer { get; set; } = string.Empty;
public string Audience { get; set; } = string.Empty;
public string Key { get; set; } = string.Empty;
}
4 changes: 3 additions & 1 deletion src/StarBlog.Application/Services/CommentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public CommentService(ILogger<CommentService> logger, IBaseRepository<Comment> c

var data = await querySet.Page(param.Page, param.PageSize)
.Include(a => a.AnonymousUser)
.Include(a => a.Parent.AnonymousUser)
.Include(a => a.Parent!.AnonymousUser)
.ToListAsync();

IPagedList<Comment> pagedList = new StaticPagedList<Comment>(data, param.Page, param.PageSize, Convert.ToInt32(await querySet.CountAsync()));
Expand Down Expand Up @@ -171,6 +171,8 @@ public static bool IsValidEmail(string email) {
/// <summary>
/// 验证一次性密码
/// </summary>
/// <param name="email">邮箱地址</param>
/// <param name="otp">一次性验证码</param>
/// <param name="clear">验证通过后是否清除</param>
public bool VerifyOtp(string email, string otp, bool clear = true) {
var cacheKey = $"comment-otp-{email}";
Expand Down
4 changes: 2 additions & 2 deletions src/StarBlog.Application/Services/ConfigService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public List<ConfigItem> GetAll() {
// 尝试读取初始化配置
var section = _conf.GetSection($"StarBlog:Initial:{key}");
if (!section.Exists()) return null;
item = new ConfigItem { Key = key, Value = section.Value, Description = "Initial" };
item = new ConfigItem { Key = key, Value = section.Value ?? string.Empty, Description = "Initial" };
item = AddOrUpdate(item);
}

Expand Down Expand Up @@ -65,4 +65,4 @@ public string this[string key] {
AddOrUpdate(item);
}
}
}
}
5 changes: 3 additions & 2 deletions src/StarBlog.Application/Services/EmailService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ public async Task<MessageSentEventArgs> SendEmailAsync(string subject, string bo

/// <summary>
/// 发送邮箱验证码
/// <returns>生成随机验证码</returns>
/// <param name="mock">只生成验证码,不发邮件</param>
/// </summary>
/// <param name="email">收件邮箱</param>
/// <param name="mock">只生成验证码,不发邮件</param>
/// <returns>生成随机验证码</returns>
public async Task<string> SendOtpMail(string email, bool mock = false) {
var otp = Random.Shared.NextInt64(1000, 9999).ToString();

Expand Down
4 changes: 4 additions & 0 deletions src/StarBlog.Application/Services/PhotoService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public async Task<List<Photo>> GetFeaturedPhotos() {
/// <param name="quality">质量,默认85</param>
public async Task<byte[]> GetThumb(string id, int width = 0, int quality = 85) {
var photo = await _photoRepo.Where(a => a.Id == id).FirstAsync();
if (photo == null) throw new InvalidOperationException($"图片 {id} 不存在。");
using var image = await Image.LoadAsync(GetPhotoFilePath(photo));

if (width != 0) {
Expand All @@ -91,7 +92,9 @@ public async Task<byte[]> GetThumb(string id, int width = 0, int quality = 85) {
}

public async Task<Photo> Update(PhotoUpdateDto dto) {
if (string.IsNullOrWhiteSpace(dto.Id)) throw new ArgumentException("图片 ID 不能为空。", nameof(dto));
var photo = await GetById(dto.Id);
if (photo == null) throw new InvalidOperationException($"图片 {dto.Id} 不存在。");
photo = _mapper.Map(dto, photo);
await _photoRepo.UpdateAsync(photo);
return photo;
Expand Down Expand Up @@ -241,6 +244,7 @@ private string GetPhotoFilePath(Photo photo) {
private async Task<Photo> BuildPhotoData(Photo photo) {
var savePath = GetPhotoFilePath(photo);
var imgInfo = await Image.IdentifyAsync(savePath);
if (imgInfo == null) throw new InvalidOperationException($"无法识别图片文件:{savePath}");
photo.Width = imgInfo.Width;
photo.Height = imgInfo.Height;

Expand Down
6 changes: 3 additions & 3 deletions src/StarBlog.Application/Services/ThemeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public ThemeService(IAppPathProvider paths) {
}

public class Theme {
public string Name { get; set; }
public string Path { get; set; }
public string CssUrl { get; set; }
public string Name { get; set; } = string.Empty;
public string Path { get; set; } = string.Empty;
public string CssUrl { get; set; } = string.Empty;
}
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,8 @@ public async Task<List<ReferrerDomain>> GetReferrerDomains(VisitRecordParameters
// 在内存中进行 Uri 解析和分组
return records
.Select(r => {
try {
return new Uri(r!).Host;
}
catch {
return r;
} // 处理无效的 URL
if (string.IsNullOrWhiteSpace(r)) return string.Empty;
return Uri.TryCreate(r, UriKind.Absolute, out var uri) ? uri.Host : r;
})
.GroupBy(host => host)
.Select(g => new ReferrerDomain { Domain = g.Key, Count = g.Count() })
Expand Down Expand Up @@ -403,9 +399,9 @@ public async Task<TechDistribution> GetTechDistribution(VisitRecordParameters p)
.ToListAsync();

return new TechDistribution {
Browsers = browserStats.Select(b => new NameCountPair { Name = b.Browser, Count = b.Count }).ToList(),
OperatingSystems = osStats.Select(o => new NameCountPair { Name = o.OS, Count = o.Count }).ToList(),
Devices = deviceStats.Select(d => new NameCountPair { Name = d.Device, Count = d.Count }).ToList()
Browsers = browserStats.Select(b => new NameCountPair { Name = b.Browser ?? string.Empty, Count = b.Count }).ToList(),
OperatingSystems = osStats.Select(o => new NameCountPair { Name = o.OS ?? string.Empty, Count = o.Count }).ToList(),
Devices = deviceStats.Select(d => new NameCountPair { Name = d.Device ?? string.Empty, Count = d.Count }).ToList()
};
}

Expand Down
4 changes: 2 additions & 2 deletions src/StarBlog.Application/ViewModels/Auth/LoginToken.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace StarBlog.Application.ViewModels.Auth;

public class LoginToken {
public string Token { get; set; }
public string Token { get; set; } = string.Empty;
public DateTime Expiration { get; set; }
}
}
6 changes: 3 additions & 3 deletions src/StarBlog.Application/ViewModels/Auth/LoginUser.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace StarBlog.Application.ViewModels.Auth;

public class LoginUser {
public string Username { get; set; }
public string Password { get; set; }
}
public string Username { get; set; } = string.Empty;
public string Password { get; set; } = string.Empty;
}
10 changes: 5 additions & 5 deletions src/StarBlog.Application/ViewModels/Blog/PostUpdateDto.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
namespace StarBlog.Application.ViewModels.Blog;

public class PostUpdateDto {
public string Id { get; set; }
public string Id { get; set; } = string.Empty;

/// <summary>
/// 标题
/// </summary>
public string Title { get; set; }
public string Title { get; set; } = string.Empty;

/// <summary>
/// 文章链接,设置后可以通过以下形式访问文章
Expand All @@ -27,15 +27,15 @@ public class PostUpdateDto {
/// <summary>
/// 梗概
/// </summary>
public string Summary { get; set; }
public string Summary { get; set; } = string.Empty;

/// <summary>
/// 内容(markdown格式)
/// </summary>
public string Content { get; set; }
public string Content { get; set; } = string.Empty;

/// <summary>
/// 分类ID
/// </summary>
public int CategoryId { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace StarBlog.Application.ViewModels.Categories;

public record CategoryCreationDto {
public string Name { get; set; }
public string Name { get; set; } = string.Empty;
public int ParentId { get; set; }
public bool Visible { get; set; } = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ public class CategoryNode {
public int Id { get; set; }
public string? text { get; set; }
public string? href { get; set; }
public List<string> tags { get; set; }
public List<string> tags { get; set; } = [];
public List<CategoryNode>? nodes { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ public class FeaturedCategoryCreationDto {
/// <summary>
/// 重新定义的推荐名称
/// </summary>
public string Name { get; set; }
public string Name { get; set; } = string.Empty;

/// <summary>
/// 推荐分类解释
/// </summary>
public string Description { get; set; }
public string Description { get; set; } = string.Empty;

/// <summary>
/// 图标
Expand All @@ -20,5 +20,5 @@ public class FeaturedCategoryCreationDto {
/// <item>fa-brands fa-android</item>
/// </list>
/// </summary>
public string IconCssClass { get; set; }
}
public string IconCssClass { get; set; } = string.Empty;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ public class FeaturedCategoryCreationDto2 {
/// <summary>
/// 重新定义的推荐名称
/// </summary>
public string Name { get; set; }
public string Name { get; set; } = string.Empty;

/// <summary>
/// 推荐分类解释
/// </summary>
public string Description { get; set; }
public string Description { get; set; } = string.Empty;

/// <summary>
/// 图标
Expand All @@ -20,10 +20,10 @@ public class FeaturedCategoryCreationDto2 {
/// <item>fa-brands fa-android</item>
/// </list>
/// </summary>
public string IconCssClass { get; set; }
public string IconCssClass { get; set; } = string.Empty;

/// <summary>
/// 分类ID
/// </summary>
public int CategoryId { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@ public class CommentCreationDto {
public string? ParentId { get; set; }

[Required]
public string PostId { get; set; }
public string PostId { get; set; } = string.Empty;

[MinLength(2, ErrorMessage = "长度在 2 到 20 个字符")]
[MaxLength(20, ErrorMessage = "长度在 2 到 20 个字符")]
public string UserName { get; set; }
public string UserName { get; set; } = string.Empty;

[Required(ErrorMessage = "邮箱地址不能为空")]
[EmailAddress(ErrorMessage = "邮箱格式不正确")]
public string Email { get; set; }
public string Email { get; set; } = string.Empty;

[Url(ErrorMessage = "请输入正确的url")]
public string? Url { get; set; }

[Required(ErrorMessage = "邮箱验证码不能为空")]
[StringLength(4, ErrorMessage = "长度为 4 个字符")]
public string EmailOtp { get; set; }
public string EmailOtp { get; set; } = string.Empty;

[Required(ErrorMessage = "评论内容不能为空")]
[MaxLength(300, ErrorMessage = "评论最大长度为300个字符")]
public string Content { get; set; }
}
public string Content { get; set; } = string.Empty;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
namespace StarBlog.Application.ViewModels.Comments;

public class CommentRejectDto {
public string Reason { get; set; }
}
public string Reason { get; set; } = string.Empty;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
public class ConfigItemCreationDto {
public string Key { get; set; }
public string Value { get; set; }
namespace StarBlog.Application.ViewModels.Config;

public class ConfigItemCreationDto {
public string Key { get; set; } = string.Empty;
public string Value { get; set; } = string.Empty;
public string? Description { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
public class ConfigItemUpdateDto {
public string Value { get; set; }
namespace StarBlog.Application.ViewModels.Config;

public class ConfigItemUpdateDto {
public string Value { get; set; } = string.Empty;
public string? Description { get; set; }
}
}
Loading