v3.4.6
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Security.Cryptography;
|
||||
using System.IO.Compression;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using JNPF.Common.Captcha.General;
|
||||
@@ -80,7 +81,7 @@ public class FileService : IFileService, IDynamicApiController, ITransient
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("Uploader/Preview")]
|
||||
public async Task<dynamic> Preview(string fileName)
|
||||
public async Task<dynamic> Preview(string fileName, string fileDownloadUrl)
|
||||
{
|
||||
string[]? typeList = new string[] { "doc", "docx", "xls", "xlsx", "ppt", "pptx", "pdf", "jpg", "jpeg", "gif", "png", "bmp" };
|
||||
string? type = fileName.Split('.').LastOrDefault();
|
||||
@@ -92,7 +93,7 @@ public class FileService : IFileService, IDynamicApiController, ITransient
|
||||
switch (_appOptions.PreviewType)
|
||||
{
|
||||
case PreviewType.kkfile:
|
||||
previewUrl = KKFileUploaderPreview(fileName);
|
||||
previewUrl = KKFileUploaderPreview(fileName, fileDownloadUrl);
|
||||
break;
|
||||
case PreviewType.yozo:
|
||||
previewUrl = await YoZoUploaderPreview(fileName, 5, 1);
|
||||
@@ -154,10 +155,15 @@ public class FileService : IFileService, IDynamicApiController, ITransient
|
||||
/// 下载.
|
||||
/// </summary>
|
||||
/// <param name="fileName"></param>
|
||||
/// <param name="type"></param>
|
||||
[HttpGet("down/{fileName}")]
|
||||
public async Task FileDown(string fileName)
|
||||
public async Task FileDown(string fileName, [FromQuery] string type)
|
||||
{
|
||||
string? systemFilePath = Path.Combine(FileVariable.SystemFilePath, fileName);
|
||||
if (type.IsNotEmptyOrNull())
|
||||
{
|
||||
systemFilePath = Path.Combine(_fileManager.GetPathByType(type), fileName);
|
||||
}
|
||||
var fileStreamResult = await _fileManager.DownloadFileByType(systemFilePath, fileName);
|
||||
byte[] bytes = new byte[fileStreamResult.FileStream.Length];
|
||||
|
||||
@@ -190,6 +196,39 @@ public class FileService : IFileService, IDynamicApiController, ITransient
|
||||
return new { name = fileName, url = string.Format("/api/file/Download?encryption={0}", encryptStr) };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 全部下载.
|
||||
/// </summary>
|
||||
/// <param name="type">图片类型.</param>
|
||||
/// <param name="fileName">文件名称.</param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("PackDownload/{type}")]
|
||||
public async Task<dynamic> DownloadAll(string type, [FromBody] List<FileControlsModel> input)
|
||||
{
|
||||
var fileName = RandomExtensions.NextLetterAndNumberString(new Random(), 7);
|
||||
//临时目录
|
||||
string directoryPath = Path.Combine(App.GetConfig<AppOptions>("JNPF_App", true).SystemPath, "TemporaryFile", fileName);
|
||||
Directory.CreateDirectory(directoryPath);
|
||||
foreach (var item in input)
|
||||
{
|
||||
string filePath = Path.Combine(GetPathByType(type), item.fileId.Replace("@", "."));
|
||||
await _fileManager.CopyFile(filePath, Path.Combine(directoryPath, item.fileName));
|
||||
}
|
||||
// 压缩文件
|
||||
string downloadPath = directoryPath + ".zip";
|
||||
|
||||
// 判断是否存在同名称文件
|
||||
if (File.Exists(downloadPath))
|
||||
File.Delete(downloadPath);
|
||||
|
||||
ZipFile.CreateFromDirectory(directoryPath, downloadPath);
|
||||
if (!App.Configuration["OSS:Provider"].Equals("Invalid"))
|
||||
await UploadFileByType(downloadPath, "SystemPath", string.Format("文件{0}.zip", fileName));
|
||||
var downloadFileName = string.Format("{0}|{1}.zip|TemporaryFile", _userManager.UserId, fileName);
|
||||
_cacheManager.Set(fileName + ".zip", string.Empty);
|
||||
return new { downloadName = string.Format("文件{0}.zip", fileName), downloadVo = new { name = fileName, url = "/api/File/Download?encryption=" + DESCEncryption.Encrypt(downloadFileName, "JNPF") } };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 下载文件链接.
|
||||
/// </summary>
|
||||
@@ -268,16 +307,17 @@ public class FileService : IFileService, IDynamicApiController, ITransient
|
||||
[HttpPost("Uploader/{type}")]
|
||||
[AllowAnonymous]
|
||||
[IgnoreLog]
|
||||
public async Task<dynamic> Uploader(string type, IFormFile file)
|
||||
public async Task<dynamic> Uploader(string type, [FromForm] ChunkModel input)
|
||||
{
|
||||
string? fileType = Path.GetExtension(file.FileName).Replace(".", string.Empty);
|
||||
string? fileType = Path.GetExtension(input.file.FileName).Replace(".", string.Empty);
|
||||
if (!AllowFileType(fileType, type))
|
||||
throw Oops.Oh(ErrorCode.D1800);
|
||||
string filePath = GetPathByType(type);
|
||||
string fileName = string.Format("{0}{1}{2}", DateTime.Now.ToString("yyyyMMdd"), RandomExtensions.NextLetterAndNumberString(new Random(), 5), Path.GetExtension(file.FileName));
|
||||
var stream = file.OpenReadStream();
|
||||
await _fileManager.UploadFileByType(stream, filePath, fileName);
|
||||
return new { name = fileName, url = string.Format("/api/File/Image/{0}/{1}", type, fileName), fileSize = file.Length, fileExtension = fileType };
|
||||
string saveFileName = string.Format("{0}{1}{2}", DateTime.Now.ToString("yyyyMMdd"), RandomExtensions.NextLetterAndNumberString(new Random(), 5), Path.GetExtension(input.file.FileName));
|
||||
var stream = input.file.OpenReadStream();
|
||||
input.type = type;
|
||||
_fileManager.GetChunkModel(input, saveFileName);
|
||||
await _fileManager.UploadFileByType(stream, input.folder, saveFileName);
|
||||
return new FileControlsModel { name = input.fileName, url = string.Format("/api/File/Image/{0}/{1}", type, input.fileName), fileExtension = fileType, fileSize = input.file.Length, fileName = input.fileName };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -364,12 +404,18 @@ public class FileService : IFileService, IDynamicApiController, ITransient
|
||||
/// KKFile 文件预览.
|
||||
/// </summary>
|
||||
/// <param name="fileName">文件名称.</param>
|
||||
/// <param name="fileDownloadUrl">文件地址.</param>
|
||||
/// <returns></returns>
|
||||
public string KKFileUploaderPreview(string fileName)
|
||||
public string KKFileUploaderPreview(string fileName, string fileDownloadUrl)
|
||||
{
|
||||
var domain = App.Configuration["JNPF_APP:Domain"];
|
||||
var filePath = (domain + "/api/File/down/" + fileName).ToBase64String();
|
||||
|
||||
if (fileDownloadUrl.IsNotEmptyOrNull())
|
||||
{
|
||||
var list = fileDownloadUrl.Split('/');
|
||||
var type = list.Length > 4 ? list[4] : string.Empty;
|
||||
filePath = string.Format("{0}{1}{2}?type={3}", domain, "/api/File/down/", fileName, type).ToBase64String();
|
||||
}
|
||||
var kkFileDoMain = App.Configuration["JNPF_APP:KKFileDomain"];
|
||||
var kkurl = kkFileDoMain + "/onlinePreview?url=";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user