fix 本地上传调整
This commit is contained in:
@@ -1,82 +0,0 @@
|
||||
using Dlhis.Common.Request;
|
||||
using Dlhis.Common.Response;
|
||||
using Dlhis.Common.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Dlhis.Common.Controllers;
|
||||
|
||||
/// <summary>
|
||||
/// 文件上传/下载
|
||||
/// </summary>
|
||||
[Authorize]
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class ApkFileController : ControllerBase
|
||||
{
|
||||
private IApkFIileService _apkFIileService;
|
||||
|
||||
public ApkFileController(IApkFIileService apkFIileService)
|
||||
{
|
||||
_apkFIileService = apkFIileService;
|
||||
}
|
||||
/// <summary>
|
||||
/// minlo文件上传
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("minio")]
|
||||
public async Task<ApkFileResponse> FormSingleFileUpload([FromForm] ApkRequest request)
|
||||
{
|
||||
return await _apkFIileService.FormSingleFileUpload(request);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// minlo文件下载
|
||||
/// </summary>
|
||||
/// <param name="fileName"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("miniourl")]
|
||||
public async Task<string> RequestDownloadFile(string fileName)
|
||||
{
|
||||
return await _apkFIileService.RequestDownloadFile(fileName);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 本地文件上传
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("uploadlocal")]
|
||||
[RequestSizeLimit(100_000_0000)]
|
||||
|
||||
public async Task<ApkFileFormLocalResponse> FormLocalFileUpload([FromForm] ApkRequest request)
|
||||
{
|
||||
return await _apkFIileService.FormLocalFileUpload(request);
|
||||
}
|
||||
/// <summary>
|
||||
/// 查看最新版本
|
||||
/// </summary>
|
||||
/// <param name="fileName"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("lateFile")]
|
||||
public async Task<ApkFileFormLocalResponse> LatestFile(string fileName)
|
||||
{
|
||||
return await _apkFIileService.LatestFile(fileName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 本地文件下载
|
||||
/// </summary>
|
||||
/// <param name="fileName"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("downlocal")]
|
||||
public IActionResult FormLocalDownloadFile(string fileName)
|
||||
{
|
||||
return _apkFIileService.FormLocalDownloadFile(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
using Dlhis.Common.FileOperation.Response;
|
||||
using Dlhis.Common.FileOperation.Services;
|
||||
using Dlhis.Common.Request;
|
||||
using Dlhis.Common.Response;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Org.BouncyCastle.Asn1.Ocsp;
|
||||
|
||||
namespace Dlhis.Common.FileOperation.Controllers;
|
||||
|
||||
@@ -57,15 +59,26 @@ public class ApkFileController : ControllerBase
|
||||
return await _apkFIileService.FormLocalFileUpload(request);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查看最新版本
|
||||
/// </summary>
|
||||
/// <param name="fileName"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("lastfile")]
|
||||
public async Task<ApkFileFormLocalResponse> LatestFile(string fileName)
|
||||
{
|
||||
return await _apkFIileService.LatestFile(fileName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 本地文件下载
|
||||
/// </summary>
|
||||
/// <param name="filePath"></param>
|
||||
/// <param name="fileName"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("local")]
|
||||
public IActionResult FormLocalDownloadFile(string filePath)
|
||||
public IActionResult FormLocalDownloadFile(string fileName)
|
||||
{
|
||||
return _apkFIileService.FormLocalDownloadFile(filePath);
|
||||
return _apkFIileService.FormLocalDownloadFile(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Dlhis.Common.FileOperation.Request;
|
||||
using Dlhis.Common.FileOperation.Response;
|
||||
using Dlhis.Common.Request;
|
||||
using Dlhis.Common.Response;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Dlhis.Common.FileOperation.Services;
|
||||
@@ -26,12 +27,15 @@ public interface IApkFIileService : IScopeDependency
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
Task<ApkFileResponse> FormLocalFileUpload(ApkRequest request);
|
||||
|
||||
Task<ApkFileFormLocalResponse> LatestFile(string fileName);
|
||||
|
||||
/// <summary>
|
||||
/// 本地下载
|
||||
/// </summary>
|
||||
/// <param name="filePath"></param>
|
||||
/// <param name="fileName"></param>
|
||||
/// <returns></returns>
|
||||
IActionResult FormLocalDownloadFile(string filePath);
|
||||
IActionResult FormLocalDownloadFile(string fileName);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using Dlhis.Common.FileOperation.Response;
|
||||
using Dlhis.Common.FileOperation.Services;
|
||||
using Dlhis.Common.Request;
|
||||
using Dlhis.Common.Response;
|
||||
using Dlhis.Entity.Common;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
using Kurisu.SqlSugar.Services;
|
||||
@@ -90,6 +91,7 @@ public class ApkFIileService : IApkFIileService
|
||||
Name = fileName,
|
||||
Url = completeFilePath,
|
||||
VersionCode = request.VersionCode,
|
||||
VersionName = request.VersionName,
|
||||
UpdateMessage = request.UpdateMessage,
|
||||
};
|
||||
await _dbContext.InsertAsync(info);
|
||||
@@ -99,6 +101,7 @@ public class ApkFIileService : IApkFIileService
|
||||
entity.Url = completeFilePath;
|
||||
entity.VersionCode = request.VersionCode;
|
||||
entity.UpdateMessage = request.UpdateMessage;
|
||||
entity.VersionName = request.VersionName;
|
||||
await _dbContext.UpdateAsync(entity);
|
||||
}
|
||||
var newEntity = await _dbContext.Queryable<ApkFileEntity>().Where(x => x.Name == fileName).FirstAsync();
|
||||
@@ -110,7 +113,7 @@ public class ApkFIileService : IApkFIileService
|
||||
{
|
||||
try
|
||||
{
|
||||
var filePath = "D:\\apk\\";
|
||||
var filePath = "C:\\apk\\";
|
||||
|
||||
// 创建存储文件夹
|
||||
if (!Directory.Exists(filePath))
|
||||
@@ -146,15 +149,33 @@ public class ApkFIileService : IApkFIileService
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 返回最新版本信息
|
||||
/// </summary>
|
||||
/// <param name="fileName"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<ApkFileFormLocalResponse> LatestFile(string fileName)
|
||||
{
|
||||
var info = await _dbContext.Queryable<ApkFileEntity>()
|
||||
.Where(x => x.Name == fileName)
|
||||
.OrderByDescending(x => x.VersionCode)
|
||||
.FirstAsync();
|
||||
info.ThrowIfNull($"没有{fileName}信息");
|
||||
var res = info.Adapt<ApkFileFormLocalResponse>();
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 本地下载
|
||||
/// </summary>
|
||||
/// <param name="filePath"></param>
|
||||
/// <param name="fileName"></param>
|
||||
/// <returns></returns>
|
||||
public IActionResult FormLocalDownloadFile(string filePath)
|
||||
public IActionResult FormLocalDownloadFile(string fileName)
|
||||
{
|
||||
string fileName = Path.GetFileName(filePath);
|
||||
|
||||
var Path = "C:\\apk\\";
|
||||
var filePath = Path + fileName;
|
||||
return new FileStreamResult(new FileStream(filePath, FileMode.Open), "application/octet-stream") { FileDownloadName = fileName };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Dlhis.Common.Response
|
||||
{
|
||||
public class ApkFileResponse
|
||||
public class ApkFile1Response
|
||||
{
|
||||
/// <summary>
|
||||
/// 文件名称
|
||||
@@ -11,7 +11,7 @@ namespace Dlhis.Common.Services;
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
Task<ApkFileResponse> FormSingleFileUpload(ApkRequest request);
|
||||
Task<ApkFile1Response> FormSingleFileUpload(ApkRequest request);
|
||||
|
||||
/// <summary>
|
||||
/// 文件下载
|
||||
|
||||
@@ -25,7 +25,7 @@ public class ApkFIileService : IApkFIileService
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<ApkFileResponse> FormSingleFileUpload(ApkRequest request)
|
||||
public async Task<ApkFile1Response> FormSingleFileUpload(ApkRequest request)
|
||||
{
|
||||
//上传
|
||||
var fileUrl = await _minioService.MinloUploadFileAsync(request);
|
||||
@@ -53,7 +53,7 @@ public class ApkFIileService : IApkFIileService
|
||||
await _dbContext.UpdateAsync(entity);
|
||||
}
|
||||
var newEntity = await _dbContext.Queryable<ApkFileEntity>().Where(x => x.Name == fileName).FirstAsync();
|
||||
var res = newEntity.Adapt<ApkFileResponse>();
|
||||
var res = newEntity.Adapt<ApkFile1Response>();
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user