src/SSCMS.Web/Controllers/Admin/Cms/Settings/SettingsStyleContentController.Import.cs
(完整代码) 2KBusing System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SSCMS.Configuration;
using SSCMS.Core.Utils.Serialization;
using SSCMS.Dto;
using SSCMS.Utils;
using SSCMS.Core.Utils;
namespace SSCMS.Web.Controllers.Admin.Cms.Settings
{
public partial class SettingsStyleContentController
{
[RequestSizeLimit(long.MaxValue)]
[HttpPost, Route(RouteImport)]
public async Task<ActionResult<BoolResult>> Import([FromQuery] ImportRequest request, [FromForm] IFormFile file)
{
if (!await _authManager.HasSitePermissionsAsync(request.SiteId,
MenuUtils.SitePermissions.SettingsStyleContent))
{
return Unauthorized();
}
var site = await _siteRepository.GetAsync(request.SiteId);
if (site == null) return NotFound();
var channel = await _channelRepository.GetAsync(request.ChannelId);
if (file == null)
{
return this.Error(Constants.ErrorUpload);
}
var fileName = PathUtils.GetFileName(file.FileName);
var sExt = PathUtils.GetExtension(fileName);
if (!StringUtils.EqualsIgnoreCase(sExt, ".zip"))
{
return this.Error("导入文件为 Zip 格式,请选择有效的文件上传");
}
var filePath = _pathManager.GetTemporaryFilesPath(fileName);
await _pathManager.UploadAsync(file, filePath);
var tableName = _channelRepository.GetTableName(site, channel);
var directoryPath = await ImportObject.ImportTableStyleByZipFileAsync(_pathManager, _databaseManager, tableName, _tableStyleRepository.GetRelatedIdentities(channel), filePath);
FileUtils.DeleteFileIfExists(filePath);
DirectoryUtils.DeleteDirectoryIfExists(directoryPath);
await _authManager.AddSiteLogAsync(request.SiteId, "导入站点字段");
return new BoolResult
{
Value = true
};
}
}
}
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
