This commit is contained in:
2025-05-16 23:14:52 +08:00
parent 5080850523
commit c6d62a68ca
25 changed files with 543 additions and 60 deletions

View File

@@ -1,6 +1,6 @@
namespace Yes.Application.Admins.Themes
{
public record UploadThemeCommand(IFormFile File) : IRequest<UploadThemeCommandResponse>;
public record UploadThemeCommand(IFormFile File, string Theme) : IRequest<UploadThemeCommandResponse>;
public record UploadThemeCommandResponse(string DirName);
public class UploadThemeCommandHandler(
@@ -31,6 +31,12 @@
try
{
var file = request.File;
var theme = request.Theme;
if(string.IsNullOrWhiteSpace(theme))
{
theme = Guid.NewGuid().ToString().ToLower();
}
var ext = Path.GetExtension(file.FileName).ToLowerInvariant();
var allowedExts = _settings.AllowedUploadExts;
@@ -81,14 +87,7 @@
var targetDirectory = Path.Combine(_env.ContentRootPath, "files", "themes");
ZipHelper.ExtractToDirectory(filePath, targetDirectory, newDirName);
string targetFilePath = Path.Combine(targetDirectory, newDirName, "config.json");
if (!File.Exists(targetFilePath))
{
throw new InvalidDataException("缺少config.json文件");
}
ZipHelper.ExtractAndProcessZip(filePath, targetDirectory, theme);
return new UploadThemeCommandResponse(newDirName);
}