fix 修改下载链接域名

This commit is contained in:
cheche
2024-02-23 15:19:16 +08:00
parent 7c52b7fb1e
commit 36188926d4
6 changed files with 49 additions and 10 deletions

View File

@@ -49,12 +49,12 @@ public class ApkFileController : ControllerBase
/// <summary>
/// 获取最新版本
/// </summary>
/// <param name="fileName"></param>
/// <param name="productCode"></param>
/// <returns></returns>
[HttpGet("lastverison")]
public async Task<ApkFileResponse> GetLastVersionAsync(string fileName)
public async Task<ApkFileResponse> GetLastVersionAsync(string productCode)
{
return await _apkFIileService.GetLastVersionAsync(fileName);
return await _apkFIileService.GetLastVersionAsync(productCode);
}

View File

@@ -23,5 +23,15 @@ namespace Dlhis.Common.FileOperation.Response
/// 修改信息
/// </summary>
public string UpdateMessage { get; set; }
/// <summary>
/// 产品代码
/// </summary>
public string ProductCode { get; set; }
/// <summary>
/// url
/// </summary>
public string? Url { get; set; }
}
}

View File

@@ -22,7 +22,7 @@ public interface IApkFIileService : IScopeDependency
Task<string> RequestDownloadFile(string fileName);
Task<ApkFileResponse> GetLastVersionAsync(string fileName);
Task<ApkFileResponse> GetLastVersionAsync(string productCode);
}

View File

@@ -15,11 +15,13 @@ public class ApkFIileService : IApkFIileService
{
private readonly IMinioService _minioService;
private readonly IDbContext _dbContext;
private readonly IConfiguration Configuration;
public ApkFIileService(IMinioService minioService, IDbContext dbContext)
public ApkFIileService(IMinioService minioService, IDbContext dbContext, IConfiguration configuration)
{
_minioService = minioService;
_dbContext = dbContext;
Configuration = configuration;
}
/// <summary>
@@ -34,13 +36,21 @@ public class ApkFIileService : IApkFIileService
string fileName = request.formFile.FileName;
var lenFive = request.formFile.FileName.Length >= 5;
lenFive.ThrowIfFalse("文件名长度不能小于5");
var houzhui = request.formFile.FileName.Substring(request.formFile.FileName.Length - 4, 4).ToLower();
var isApk = request.formFile.FileName.Substring(request.formFile.FileName.Length - 4, 4) == ".apk";
isApk.ThrowIfFalse("文件不是apk类型");
//更新数据库
var entity = await _dbContext.Queryable<ApkFileEntity>().Where(x => x.Name == fileName).FirstAsync();
var entity = await _dbContext.Queryable<ApkFileEntity>().Where(x => x.ProductCode == request.ProductCode).FirstAsync();
if (entity == null)
{
var info = new ApkFileEntity
{
Name = fileName,
ProductCode = request.ProductCode,
VersionCode = request.VersionCode,
UpdateMessage = request.UpdateMessage,
VersionName = request.VersionName,
@@ -54,17 +64,25 @@ public class ApkFIileService : IApkFIileService
entity.VersionName = request.VersionName;
await _dbContext.UpdateAsync(entity);
}
var newEntity = await _dbContext.Queryable<ApkFileEntity>().Where(x => x.Name == fileName).FirstAsync();
var newEntity = await _dbContext.Queryable<ApkFileEntity>().Where(x => x.ProductCode == request.ProductCode).FirstAsync();
var res = newEntity.Adapt<ApkFileResponse>();
return res;
}
public async Task<ApkFileResponse> GetLastVersionAsync(string fileName)
public async Task<ApkFileResponse> GetLastVersionAsync(string productCode)
{
var info = await _dbContext.Queryable<ApkFileEntity>()
.Where(x => x.Name == fileName)
.Where(x => x.ProductCode == productCode)
.Select<ApkFileResponse>()
.FirstAsync();
var url =await RequestDownloadFile(info.Name);
var host = Configuration["MinIO:Endpoint"];
var modified_url = url.Replace(host, "https://yikatong.isawesome.cn/m");
info.Url = modified_url;
return info;
}

View File

@@ -21,5 +21,10 @@
/// 修改信息
/// </summary>
public string UpdateMessage { get; set; }
/// <summary>
/// 产品代码
/// </summary>
public string? ProductCode { get; set; }
}
}

View File

@@ -37,6 +37,12 @@ public class ApkFileEntity : SugarBaseEntity
/// </summary>
[SugarColumn(ColumnDescription = "修改信息")]
public string UpdateMessage { get; set; }
}
/// <summary>
/// 产品代码
/// </summary>
[SugarColumn(ColumnDescription = "产品代码")]
public string? ProductCode { get; set; }
}