From f3b17dc6b82409dbe9b14ed0f156a41e2a02ed6e Mon Sep 17 00:00:00 2001 From: cheche <717840555@qq.com> Date: Thu, 22 Feb 2024 18:25:19 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E5=88=A0=E9=99=A4url=E5=88=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/ApkFileController.cs | 31 ----- .../Services/IApkFIileService.cs | 14 --- .../Services/Implements/ApkFIileService.cs | 110 ------------------ Src/Dlhis.Entity/Common/ApkFileEntity.cs | 6 - 4 files changed, 161 deletions(-) diff --git a/Src/Dlhis.Common/FileOperation/Controllers/ApkFileController.cs b/Src/Dlhis.Common/FileOperation/Controllers/ApkFileController.cs index 7646dd3e..b2c442aa 100644 --- a/Src/Dlhis.Common/FileOperation/Controllers/ApkFileController.cs +++ b/Src/Dlhis.Common/FileOperation/Controllers/ApkFileController.cs @@ -46,40 +46,9 @@ public class ApkFileController : ControllerBase } - /// - /// 本地文件上传 - /// - /// - /// - [HttpPost("local")] - [RequestSizeLimit(100_000_0000)] - public async Task FormLocalFileUpload([FromForm] ApkRequest request) - { - return await _apkFIileService.FormLocalFileUpload(request); - } - /// - /// 查看最新版本 - /// - /// - /// - [HttpGet("lastfile")] - public async Task LatestFile(string fileName) - { - return await _apkFIileService.LatestFile(fileName); - } - /// - /// 本地文件下载 - /// - /// - /// - [HttpGet("local")] - public IActionResult FormLocalDownloadFile(string fileName) - { - return _apkFIileService.FormLocalDownloadFile(fileName); - } } diff --git a/Src/Dlhis.Common/FileOperation/Services/IApkFIileService.cs b/Src/Dlhis.Common/FileOperation/Services/IApkFIileService.cs index f9f29d73..ff5a079b 100644 --- a/Src/Dlhis.Common/FileOperation/Services/IApkFIileService.cs +++ b/Src/Dlhis.Common/FileOperation/Services/IApkFIileService.cs @@ -21,21 +21,7 @@ public interface IApkFIileService : IScopeDependency /// Task RequestDownloadFile(string fileName); - /// - /// 本地上传 - /// - /// - /// - Task FormLocalFileUpload(ApkRequest request); - Task LatestFile(string fileName); - - /// - /// 本地下载 - /// - /// - /// - IActionResult FormLocalDownloadFile(string fileName); } diff --git a/Src/Dlhis.Common/FileOperation/Services/Implements/ApkFIileService.cs b/Src/Dlhis.Common/FileOperation/Services/Implements/ApkFIileService.cs index 8978cfb6..ffe86e6b 100644 --- a/Src/Dlhis.Common/FileOperation/Services/Implements/ApkFIileService.cs +++ b/Src/Dlhis.Common/FileOperation/Services/Implements/ApkFIileService.cs @@ -41,7 +41,6 @@ public class ApkFIileService : IApkFIileService var info = new ApkFileEntity { Name = fileName, - Url = fileUrl, VersionCode = request.VersionCode, UpdateMessage = request.UpdateMessage, VersionName = request.VersionName, @@ -50,7 +49,6 @@ public class ApkFIileService : IApkFIileService } else { - entity.Url = fileUrl; entity.VersionCode = request.VersionCode; entity.UpdateMessage = request.UpdateMessage; await _dbContext.UpdateAsync(entity); @@ -69,116 +67,8 @@ public class ApkFIileService : IApkFIileService return await _minioService.MinloDownloadLinkAsync(fileName); } - /// - /// 本地文件上传 - /// - /// - /// - public async Task FormLocalFileUpload(ApkRequest request) - { - //上传 - var completeFilePath = FormSingleFileUpload(request.formFile); - if (completeFilePath == "No file uploaded" || completeFilePath.IsEmpty()) - { - return null; - } - //更新数据库 - var fileName = request.formFile.FileName; - var entity = await _dbContext.Queryable().Where(x => x.Name == fileName).FirstAsync(); - if (entity == null) - { - var info = new ApkFileEntity - { - Name = fileName, - Url = completeFilePath, - VersionCode = request.VersionCode, - VersionName = request.VersionName, - UpdateMessage = request.UpdateMessage, - }; - await _dbContext.InsertAsync(info); - } - else - { - entity.Url = completeFilePath; - entity.VersionCode = request.VersionCode; - entity.UpdateMessage = request.UpdateMessage; - entity.VersionName = request.VersionName; - await _dbContext.UpdateAsync(entity); - } - var newEntity = await _dbContext.Queryable().Where(x => x.Name == fileName).FirstAsync(); - var res = newEntity.Adapt(); - return res; - - } - public string FormSingleFileUpload(IFormFile formFile) - { - try - { - var filePath = "C:\\apk\\"; - - // 创建存储文件夹 - if (!Directory.Exists(filePath)) - { - Directory.CreateDirectory(filePath); - } - - if (formFile != null && formFile.Length > 0) - { - // 保存的文件名称 - var saveName = Path.GetFileName(formFile.FileName); - - // 文件保存 - using (var fs = File.Create(Path.Combine(filePath, saveName))) - { - formFile.CopyTo(fs); - fs.Flush(); - } - - // 完整的文件路径 - var completeFilePath = Path.Combine(filePath, saveName); - return completeFilePath; - } - else - { - return "No file uploaded"; - } - } - catch (Exception) - { - return null; - throw; - } - } - - /// - /// 返回最新版本信息 - /// - /// - /// - public async Task LatestFile(string fileName) - { - var info = await _dbContext.Queryable() - .Where(x => x.Name == fileName) - .OrderByDescending(x => x.VersionCode) - .FirstAsync(); - info.ThrowIfNull($"没有{fileName}信息"); - var res = info.Adapt(); - return res; - } - /// - /// 本地下载 - /// - /// - /// - public IActionResult FormLocalDownloadFile(string fileName) - { - - var Path = "C:\\apk\\"; - var filePath = Path + fileName; - return new FileStreamResult(new FileStream(filePath, FileMode.Open), "application/octet-stream") { FileDownloadName = fileName }; - } } diff --git a/Src/Dlhis.Entity/Common/ApkFileEntity.cs b/Src/Dlhis.Entity/Common/ApkFileEntity.cs index da72752e..cf1735ec 100644 --- a/Src/Dlhis.Entity/Common/ApkFileEntity.cs +++ b/Src/Dlhis.Entity/Common/ApkFileEntity.cs @@ -20,12 +20,6 @@ public class ApkFileEntity : SugarBaseEntity [SugarColumn(ColumnDescription = "文件名称")] public string Name { get; set; } - /// - /// 地址 - /// - [SugarColumn(ColumnDescription = "地址")] - public string Url { get; set; } - /// /// 版本号 ///