This commit is contained in:
2025-05-09 15:03:54 +08:00
parent 331b06e733
commit 7416a2dd12
336 changed files with 339 additions and 246095 deletions

View File

@@ -0,0 +1,32 @@
namespace Yes.Application.Admins.Themes
{
public record GetThemeFileQuery(string ThemeName, string FileName) : IRequest<GetThemeFileQueryResponse>;
public record GetThemeFileQueryResponse(
string Content
);
public class GetThemeFileQueryHandler(IOptionsMonitor<BlogSettings> options, IMapper mapper, IWebHostEnvironment env) : IRequestHandler<GetThemeFileQuery, GetThemeFileQueryResponse>
{
private readonly BlogSettings _settings = options.CurrentValue;
private readonly IMapper _mapper = mapper;
private readonly IWebHostEnvironment _env = env;
public async Task<GetThemeFileQueryResponse> Handle(GetThemeFileQuery request, CancellationToken cancellationToken)
{
var themeName = request.ThemeName;
var fileName = request.FileName;
var themes = new List<GetThemeFileQueryResponse>();
var filePath = Path.Combine(_env.ContentRootPath, "files", "themes", themeName, fileName);
var content = "";
if (File.Exists(filePath))
{
content = File.ReadAllText(filePath);
}
return new GetThemeFileQueryResponse(content);
}
}
}

View File

@@ -0,0 +1,30 @@
namespace Yes.Application.Admins.Themes
{
public record GetThemeFilesQuery(string Name) : IRequest<List<GetThemeFilesQueryResponse>>;
public record GetThemeFilesQueryResponse(
string FileName
);
public class GetThemeFilesQueryHandler(IOptionsMonitor<BlogSettings> options, IMapper mapper, IWebHostEnvironment env) : IRequestHandler<GetThemeFilesQuery, List<GetThemeFilesQueryResponse>>
{
private readonly BlogSettings _settings = options.CurrentValue;
private readonly IMapper _mapper = mapper;
private readonly IWebHostEnvironment _env = env;
public async Task<List<GetThemeFilesQueryResponse>> Handle(GetThemeFilesQuery request, CancellationToken cancellationToken)
{
var themeName = request.Name;
var themes = new List<GetThemeFilesQueryResponse>();
var themePath = Path.Combine(_env.ContentRootPath, "files", "themes", themeName);
var files = Directory.GetFiles(themePath).Where(x=>x.EndsWith(".liquid") || x.EndsWith(".css") || x.EndsWith(".js"));
themes = files.Select(x=>new GetThemeFilesQueryResponse(Path.GetFileName(x))).ToList();
return themes;
}
}
}

View File

@@ -0,0 +1,31 @@
namespace Yes.Application.Admins.Themes
{
public record UpdateThemeFileCommand(
string ThemeName,
string FileName,
string Content
) : IRequest<Unit>;
public class UpdateThemeFileCommandHandler(
IThemeService themeService,
IWebHostEnvironment env
) : IRequestHandler<UpdateThemeFileCommand, Unit>
{
private readonly IThemeService _themeService = themeService;
private readonly IWebHostEnvironment _env = env;
public async Task<Unit> Handle(UpdateThemeFileCommand request, CancellationToken cancellationToken)
{
var themeName = request.ThemeName;
var fileName = request.FileName;
var content = request.Content;
_themeService.CheckThemeExists(themeName);
var filePath = Path.Combine(_env.ContentRootPath, "files", "themes", themeName, fileName);
if (File.Exists(filePath))
{
File.WriteAllText(filePath, content);
}
return new Unit();
}
}
}