|
@@ -44,12 +44,16 @@ public class SysFileService : IDynamicApiController, ITransient
|
|
|
[DisplayName("获取文件分页列表")]
|
|
[DisplayName("获取文件分页列表")]
|
|
|
public async Task<SqlSugarPagedList<SysFile>> Page(PageFileInput input)
|
|
public async Task<SqlSugarPagedList<SysFile>> Page(PageFileInput input)
|
|
|
{
|
|
{
|
|
|
- return await _sysFileRep.AsQueryable()
|
|
|
|
|
- .WhereIF(!string.IsNullOrWhiteSpace(input.FileName), u => u.FileName.Contains(input.FileName.Trim()))
|
|
|
|
|
- .WhereIF(!string.IsNullOrWhiteSpace(input.StartTime.ToString()) && !string.IsNullOrWhiteSpace(input.EndTime.ToString()),
|
|
|
|
|
- u => u.CreateTime >= input.StartTime && u.CreateTime <= input.EndTime)
|
|
|
|
|
- .OrderBy(u => u.CreateTime, OrderByType.Desc)
|
|
|
|
|
- .ToPagedListAsync(input.Page, input.PageSize);
|
|
|
|
|
|
|
+ //获取所有公开附件
|
|
|
|
|
+ var publicList = _sysFileRep.AsQueryable().ClearFilter().Where(u => u.IsPublic == true);
|
|
|
|
|
+ //获取私有附件
|
|
|
|
|
+ var privateList = _sysFileRep.AsQueryable().Where(u => u.IsPublic == false);
|
|
|
|
|
+ //合并公开和私有附件并分页
|
|
|
|
|
+ return await _sysFileRep.Context.UnionAll(publicList, privateList).WhereIF(!string.IsNullOrWhiteSpace(input.FileName), u => u.FileName.Contains(input.FileName.Trim()))
|
|
|
|
|
+ .WhereIF(!string.IsNullOrWhiteSpace(input.StartTime.ToString()) && !string.IsNullOrWhiteSpace(input.EndTime.ToString()),
|
|
|
|
|
+ u => u.CreateTime >= input.StartTime && u.CreateTime <= input.EndTime)
|
|
|
|
|
+ .OrderBy(u => u.CreateTime, OrderByType.Desc)
|
|
|
|
|
+ .ToPagedListAsync(input.Page, input.PageSize);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
@@ -60,7 +64,7 @@ public class SysFileService : IDynamicApiController, ITransient
|
|
|
[DisplayName("上传文件")]
|
|
[DisplayName("上传文件")]
|
|
|
public async Task<SysFile> UploadFile([FromForm] FileUploadInput input)
|
|
public async Task<SysFile> UploadFile([FromForm] FileUploadInput input)
|
|
|
{
|
|
{
|
|
|
- return await HandleUploadFile(input.File, input.Path, fileType: input.FileType);
|
|
|
|
|
|
|
+ return await HandleUploadFile(input.File, input.Path, fileType: input.FileType, isPublic: input.IsPublic);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
@@ -84,7 +88,7 @@ public class SysFileService : IDynamicApiController, ITransient
|
|
|
Headers = new HeaderDictionary(),
|
|
Headers = new HeaderDictionary(),
|
|
|
ContentType = input.ContentType
|
|
ContentType = input.ContentType
|
|
|
};
|
|
};
|
|
|
- return await UploadFile(new FileUploadInput { File = formFile, Path = input.Path, FileType = input.FileType });
|
|
|
|
|
|
|
+ return await UploadFile(new FileUploadInput { File = formFile, Path = input.Path, FileType = input.FileType, IsPublic = input.IsPublic });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
@@ -113,59 +117,55 @@ public class SysFileService : IDynamicApiController, ITransient
|
|
|
{
|
|
{
|
|
|
var file = input.Id > 0 ? await GetFile(input) : await _sysFileRep.CopyNew().GetFirstAsync(u => u.Url == input.Url);
|
|
var file = input.Id > 0 ? await GetFile(input) : await _sysFileRep.CopyNew().GetFirstAsync(u => u.Url == input.Url);
|
|
|
var fileName = HttpUtility.UrlEncode(file.FileName, Encoding.GetEncoding("UTF-8"));
|
|
var fileName = HttpUtility.UrlEncode(file.FileName, Encoding.GetEncoding("UTF-8"));
|
|
|
|
|
+ var filePath = Path.Combine(file.FilePath, file.Id.ToString() + file.Suffix);
|
|
|
|
|
|
|
|
if (_OSSProviderOptions.IsEnable)
|
|
if (_OSSProviderOptions.IsEnable)
|
|
|
{
|
|
{
|
|
|
- var filePath = string.Concat(file.FilePath, "/", file.Id.ToString() + file.Suffix);
|
|
|
|
|
var stream = await (await _OSSService.PresignedGetObjectAsync(file.BucketName.ToString(), filePath, 5)).GetAsStreamAsync();
|
|
var stream = await (await _OSSService.PresignedGetObjectAsync(file.BucketName.ToString(), filePath, 5)).GetAsStreamAsync();
|
|
|
return new FileStreamResult(stream.Stream, "application/octet-stream") { FileDownloadName = fileName + file.Suffix };
|
|
return new FileStreamResult(stream.Stream, "application/octet-stream") { FileDownloadName = fileName + file.Suffix };
|
|
|
}
|
|
}
|
|
|
else if (App.Configuration["SSHProvider:IsEnable"].ToBoolean())
|
|
else if (App.Configuration["SSHProvider:IsEnable"].ToBoolean())
|
|
|
{
|
|
{
|
|
|
- var fullPath = string.Concat(file.FilePath, "/", file.Id + file.Suffix);
|
|
|
|
|
using (SSHHelper helper = new SSHHelper(App.Configuration["SSHProvider:Host"],
|
|
using (SSHHelper helper = new SSHHelper(App.Configuration["SSHProvider:Host"],
|
|
|
App.Configuration["SSHProvider:Port"].ToInt(), App.Configuration["SSHProvider:Username"], App.Configuration["SSHProvider:Password"]))
|
|
App.Configuration["SSHProvider:Port"].ToInt(), App.Configuration["SSHProvider:Username"], App.Configuration["SSHProvider:Password"]))
|
|
|
{
|
|
{
|
|
|
- return new FileStreamResult(helper.OpenRead(fullPath), "application/octet-stream") { FileDownloadName = fileName + file.Suffix };
|
|
|
|
|
|
|
+ return new FileStreamResult(helper.OpenRead(filePath), "application/octet-stream") { FileDownloadName = fileName + file.Suffix };
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
- var filePath = Path.Combine(file.FilePath, file.Id.ToString() + file.Suffix);
|
|
|
|
|
var path = Path.Combine(App.WebHostEnvironment.WebRootPath, filePath);
|
|
var path = Path.Combine(App.WebHostEnvironment.WebRootPath, filePath);
|
|
|
return new FileStreamResult(new FileStream(path, FileMode.Open), "application/octet-stream") { FileDownloadName = fileName + file.Suffix };
|
|
return new FileStreamResult(new FileStream(path, FileMode.Open), "application/octet-stream") { FileDownloadName = fileName + file.Suffix };
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
|
- /// 文件预览
|
|
|
|
|
|
|
+ /// 文件预览 🔖
|
|
|
/// </summary>
|
|
/// </summary>
|
|
|
/// <param name="Id"></param>
|
|
/// <param name="Id"></param>
|
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
|
- [AllowAnonymous]
|
|
|
|
|
|
|
+ [DisplayName("文件预览")]
|
|
|
public async Task<IActionResult> GetPreview([FromRoute] long Id)
|
|
public async Task<IActionResult> GetPreview([FromRoute] long Id)
|
|
|
{
|
|
{
|
|
|
var file = await GetFile(new FileInput { Id = Id });
|
|
var file = await GetFile(new FileInput { Id = Id });
|
|
|
//var fileName = HttpUtility.UrlEncode(file.FileName, Encoding.GetEncoding("UTF-8"));
|
|
//var fileName = HttpUtility.UrlEncode(file.FileName, Encoding.GetEncoding("UTF-8"));
|
|
|
|
|
+ var filePath = Path.Combine(file.FilePath, file.Id.ToString() + file.Suffix);
|
|
|
|
|
|
|
|
if (_OSSProviderOptions.IsEnable)
|
|
if (_OSSProviderOptions.IsEnable)
|
|
|
{
|
|
{
|
|
|
- var filePath = string.Concat(file.FilePath, "/", file.Id.ToString() + file.Suffix);
|
|
|
|
|
var stream = await (await _OSSService.PresignedGetObjectAsync(file.BucketName.ToString(), filePath, 5)).GetAsStreamAsync();
|
|
var stream = await (await _OSSService.PresignedGetObjectAsync(file.BucketName.ToString(), filePath, 5)).GetAsStreamAsync();
|
|
|
return new FileStreamResult(stream.Stream, "application/octet-stream");
|
|
return new FileStreamResult(stream.Stream, "application/octet-stream");
|
|
|
}
|
|
}
|
|
|
else if (App.Configuration["SSHProvider:IsEnable"].ToBoolean())
|
|
else if (App.Configuration["SSHProvider:IsEnable"].ToBoolean())
|
|
|
{
|
|
{
|
|
|
- var fullPath = string.Concat(file.FilePath, "/", file.Id + file.Suffix);
|
|
|
|
|
using (SSHHelper helper = new SSHHelper(App.Configuration["SSHProvider:Host"],
|
|
using (SSHHelper helper = new SSHHelper(App.Configuration["SSHProvider:Host"],
|
|
|
App.Configuration["SSHProvider:Port"].ToInt(), App.Configuration["SSHProvider:Username"], App.Configuration["SSHProvider:Password"]))
|
|
App.Configuration["SSHProvider:Port"].ToInt(), App.Configuration["SSHProvider:Username"], App.Configuration["SSHProvider:Password"]))
|
|
|
{
|
|
{
|
|
|
- return new FileStreamResult(helper.OpenRead(fullPath), "application/octet-stream");
|
|
|
|
|
|
|
+ return new FileStreamResult(helper.OpenRead(filePath), "application/octet-stream");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
- var filePath = Path.Combine(file.FilePath, file.Id.ToString() + file.Suffix);
|
|
|
|
|
var path = Path.Combine(App.WebHostEnvironment.WebRootPath, filePath);
|
|
var path = Path.Combine(App.WebHostEnvironment.WebRootPath, filePath);
|
|
|
return new FileStreamResult(new FileStream(path, FileMode.Open), "application/octet-stream");
|
|
return new FileStreamResult(new FileStream(path, FileMode.Open), "application/octet-stream");
|
|
|
}
|
|
}
|
|
@@ -176,7 +176,6 @@ public class SysFileService : IDynamicApiController, ITransient
|
|
|
/// </summary>
|
|
/// </summary>
|
|
|
/// <param name="url"></param>
|
|
/// <param name="url"></param>
|
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
|
- [AllowAnonymous]
|
|
|
|
|
[DisplayName("下载指定文件Base64格式")]
|
|
[DisplayName("下载指定文件Base64格式")]
|
|
|
public async Task<string> DownloadFileBase64([FromBody] string url)
|
|
public async Task<string> DownloadFileBase64([FromBody] string url)
|
|
|
{
|
|
{
|
|
@@ -270,15 +269,16 @@ public class SysFileService : IDynamicApiController, ITransient
|
|
|
var isExist = await _sysFileRep.IsAnyAsync(u => u.Id == input.Id);
|
|
var isExist = await _sysFileRep.IsAnyAsync(u => u.Id == input.Id);
|
|
|
if (!isExist) throw Oops.Oh(ErrorCodeEnum.D8000);
|
|
if (!isExist) throw Oops.Oh(ErrorCodeEnum.D8000);
|
|
|
|
|
|
|
|
- await _sysFileRep.UpdateAsync(u => new SysFile() { FileName = input.FileName, FileType = input.FileType }, u => u.Id == input.Id);
|
|
|
|
|
|
|
+ await _sysFileRep.UpdateAsync(u => new SysFile() { FileName = input.FileName, FileType = input.FileType, IsPublic = input.IsPublic }, u => u.Id == input.Id);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
|
- /// 获取文件
|
|
|
|
|
|
|
+ /// 获取文件 🔖
|
|
|
/// </summary>
|
|
/// </summary>
|
|
|
/// <param name="input"></param>
|
|
/// <param name="input"></param>
|
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
|
- private async Task<SysFile> GetFile([FromQuery] FileInput input)
|
|
|
|
|
|
|
+ [DisplayName("获取文件")]
|
|
|
|
|
+ public async Task<SysFile> GetFile([FromQuery] FileInput input)
|
|
|
{
|
|
{
|
|
|
var file = await _sysFileRep.CopyNew().GetFirstAsync(u => u.Id == input.Id);
|
|
var file = await _sysFileRep.CopyNew().GetFirstAsync(u => u.Id == input.Id);
|
|
|
return file ?? throw Oops.Oh(ErrorCodeEnum.D8000);
|
|
return file ?? throw Oops.Oh(ErrorCodeEnum.D8000);
|
|
@@ -291,13 +291,14 @@ public class SysFileService : IDynamicApiController, ITransient
|
|
|
/// <param name="savePath">路径</param>
|
|
/// <param name="savePath">路径</param>
|
|
|
/// <param name="allowSuffix">允许格式:.jpg.png.gif.tif.bmp</param>
|
|
/// <param name="allowSuffix">允许格式:.jpg.png.gif.tif.bmp</param>
|
|
|
/// <param name="fileType">类型</param>
|
|
/// <param name="fileType">类型</param>
|
|
|
|
|
+ /// <param name="isPublic">是否公开</param>
|
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
|
- private async Task<SysFile> HandleUploadFile(IFormFile file, string savePath, string allowSuffix = "", string fileType = "")
|
|
|
|
|
|
|
+ private async Task<SysFile> HandleUploadFile(IFormFile file, string savePath, string allowSuffix = "", string fileType = "", bool isPublic = false)
|
|
|
{
|
|
{
|
|
|
if (file == null) throw Oops.Oh(ErrorCodeEnum.D8000);
|
|
if (file == null) throw Oops.Oh(ErrorCodeEnum.D8000);
|
|
|
|
|
|
|
|
// 判断是否重复上传的文件
|
|
// 判断是否重复上传的文件
|
|
|
- var sizeKb = (long)(file.Length / 1024.0); // 大小KB
|
|
|
|
|
|
|
+ var sizeKb = file.Length / 1024; // 大小KB
|
|
|
var fileMd5 = string.Empty;
|
|
var fileMd5 = string.Empty;
|
|
|
if (_uploadOptions.EnableMd5)
|
|
if (_uploadOptions.EnableMd5)
|
|
|
{
|
|
{
|
|
@@ -356,7 +357,8 @@ public class SysFileService : IDynamicApiController, ITransient
|
|
|
SizeKb = sizeKb,
|
|
SizeKb = sizeKb,
|
|
|
FilePath = path,
|
|
FilePath = path,
|
|
|
FileMd5 = fileMd5,
|
|
FileMd5 = fileMd5,
|
|
|
- FileType = fileType
|
|
|
|
|
|
|
+ FileType = fileType,
|
|
|
|
|
+ IsPublic = isPublic,
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
var finalName = newFile.Id + suffix; // 文件最终名称
|
|
var finalName = newFile.Id + suffix; // 文件最终名称
|
|
@@ -387,7 +389,7 @@ public class SysFileService : IDynamicApiController, ITransient
|
|
|
}
|
|
}
|
|
|
else if (App.Configuration["SSHProvider:IsEnable"].ToBoolean())
|
|
else if (App.Configuration["SSHProvider:IsEnable"].ToBoolean())
|
|
|
{
|
|
{
|
|
|
- var fullPath = string.Concat(path.StartsWith("/") ? path : "/" + path, "/", finalName);
|
|
|
|
|
|
|
+ var fullPath = string.Concat(path.StartsWith('/') ? path : "/" + path, "/", finalName);
|
|
|
using (SSHHelper helper = new SSHHelper(App.Configuration["SSHProvider:Host"],
|
|
using (SSHHelper helper = new SSHHelper(App.Configuration["SSHProvider:Host"],
|
|
|
App.Configuration["SSHProvider:Port"].ToInt(), App.Configuration["SSHProvider:Username"], App.Configuration["SSHProvider:Password"]))
|
|
App.Configuration["SSHProvider:Port"].ToInt(), App.Configuration["SSHProvider:Username"], App.Configuration["SSHProvider:Password"]))
|
|
|
{
|
|
{
|
|
@@ -417,17 +419,6 @@ public class SysFileService : IDynamicApiController, ITransient
|
|
|
return newFile;
|
|
return newFile;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- ///// <summary>
|
|
|
|
|
- ///// 获取Minio文件的下载或者预览地址
|
|
|
|
|
- ///// </summary>
|
|
|
|
|
- ///// <param name="bucketName">桶名</param>
|
|
|
|
|
- ///// <param name="fileName">文件名</param>
|
|
|
|
|
- ///// <returns></returns>
|
|
|
|
|
- //private async Task<string> GetMinioPreviewFileUrl(string bucketName, string fileName)
|
|
|
|
|
- //{
|
|
|
|
|
- // return await _OSSService.PresignedGetObjectAsync(bucketName, fileName, 7);
|
|
|
|
|
- //}
|
|
|
|
|
-
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
|
/// 上传头像 🔖
|
|
/// 上传头像 🔖
|
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -436,7 +427,7 @@ public class SysFileService : IDynamicApiController, ITransient
|
|
|
[DisplayName("上传头像")]
|
|
[DisplayName("上传头像")]
|
|
|
public async Task<SysFile> UploadAvatar([Required] IFormFile file)
|
|
public async Task<SysFile> UploadAvatar([Required] IFormFile file)
|
|
|
{
|
|
{
|
|
|
- var sysFile = await HandleUploadFile(file, "Upload/Avatar", _imageType);
|
|
|
|
|
|
|
+ var sysFile = await HandleUploadFile(file, "upload/avatar", _imageType);
|
|
|
|
|
|
|
|
var sysUserRep = _sysFileRep.ChangeRepository<SqlSugarRepository<SysUser>>();
|
|
var sysUserRep = _sysFileRep.ChangeRepository<SqlSugarRepository<SysUser>>();
|
|
|
var user = sysUserRep.GetFirst(u => u.Id == _userManager.UserId);
|
|
var user = sysUserRep.GetFirst(u => u.Id == _userManager.UserId);
|
|
@@ -458,7 +449,7 @@ public class SysFileService : IDynamicApiController, ITransient
|
|
|
[DisplayName("上传电子签名")]
|
|
[DisplayName("上传电子签名")]
|
|
|
public async Task<SysFile> UploadSignature([Required] IFormFile file)
|
|
public async Task<SysFile> UploadSignature([Required] IFormFile file)
|
|
|
{
|
|
{
|
|
|
- var sysFile = await HandleUploadFile(file, "Upload/Signature", _imageType);
|
|
|
|
|
|
|
+ var sysFile = await HandleUploadFile(file, "upload/signature", _imageType);
|
|
|
|
|
|
|
|
var sysUserRep = _sysFileRep.ChangeRepository<SqlSugarRepository<SysUser>>();
|
|
var sysUserRep = _sysFileRep.ChangeRepository<SqlSugarRepository<SysUser>>();
|
|
|
var user = sysUserRep.GetFirst(u => u.Id == _userManager.UserId);
|
|
var user = sysUserRep.GetFirst(u => u.Id == _userManager.UserId);
|
|
@@ -473,7 +464,7 @@ public class SysFileService : IDynamicApiController, ITransient
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
|
- /// 修改附件关联对象
|
|
|
|
|
|
|
+ /// 修改附件关联对象 🔖
|
|
|
/// </summary>
|
|
/// </summary>
|
|
|
/// <param name="ids"></param>
|
|
/// <param name="ids"></param>
|
|
|
/// <param name="relationName"></param>
|
|
/// <param name="relationName"></param>
|
|
@@ -499,6 +490,7 @@ public class SysFileService : IDynamicApiController, ITransient
|
|
|
/// <param name="input"></param>
|
|
/// <param name="input"></param>
|
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
|
/// <exception cref="ArgumentNullException"></exception>
|
|
/// <exception cref="ArgumentNullException"></exception>
|
|
|
|
|
+ [DisplayName("根据关联查询附件")]
|
|
|
public async Task<List<FileOutput>> GetRelationFiles([FromQuery] RelationQueryInput input)
|
|
public async Task<List<FileOutput>> GetRelationFiles([FromQuery] RelationQueryInput input)
|
|
|
{
|
|
{
|
|
|
return await _sysFileRep.AsQueryable()
|
|
return await _sysFileRep.AsQueryable()
|