1
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user