Enhance APK upload functionality by adding version name and code parameters, and update UI for better user input validation
This commit is contained in:
@@ -8,8 +8,8 @@ public record AndroidApkVersionInfo(int LatestVersionCode, string LatestVersionN
|
||||
|
||||
public interface IAndroidApkVersionApplication
|
||||
{
|
||||
Task<OperationResult> CreateAndActive(IFormFile file, ApkType apkType, bool isForce = false);
|
||||
Task<OperationResult> CreateAndDeActive(IFormFile file, ApkType apkType, bool isForce = false);
|
||||
Task<OperationResult> CreateAndActive(IFormFile file, ApkType apkType, string versionName, string versionCode, bool isForce = false);
|
||||
Task<OperationResult> CreateAndDeActive(IFormFile file, ApkType apkType, string versionName, string versionCode, bool isForce = false);
|
||||
Task<string> GetLatestActiveVersionPath(ApkType apkType);
|
||||
Task<AndroidApkVersionInfo> GetLatestActiveInfo(ApkType apkType, int currentVersionCode);
|
||||
OperationResult Remove(long id);
|
||||
|
||||
@@ -22,7 +22,7 @@ public class AndroidApkVersionApplication : IAndroidApkVersionApplication
|
||||
_taskRepository = taskRepository;
|
||||
}
|
||||
|
||||
public async Task<OperationResult> CreateAndActive(IFormFile file, ApkType apkType, bool isForce = false)
|
||||
public async Task<OperationResult> CreateAndActive(IFormFile file, string versionName, string versionCode, ApkType apkType, bool isForce = false)
|
||||
{
|
||||
OperationResult op = new OperationResult();
|
||||
|
||||
@@ -34,6 +34,12 @@ public class AndroidApkVersionApplication : IAndroidApkVersionApplication
|
||||
if (Path.GetExtension(file.FileName).ToLower() != ".apk")
|
||||
return op.Failed("لطفا فایلی با پسوند .apk وارد کنید");
|
||||
|
||||
if (string.IsNullOrWhiteSpace(versionName))
|
||||
return op.Failed("لطفا نام ورژن را وارد کنید");
|
||||
|
||||
if (string.IsNullOrWhiteSpace(versionCode))
|
||||
return op.Failed("لطفا کد ورژن را وارد کنید");
|
||||
|
||||
#endregion
|
||||
|
||||
var activeApks = _androidApkVersionRepository.GetActives(apkType);
|
||||
@@ -47,30 +53,8 @@ public class AndroidApkVersionApplication : IAndroidApkVersionApplication
|
||||
|
||||
Directory.CreateDirectory(path);
|
||||
|
||||
// Read APK metadata with error handling
|
||||
ApkInfo apk;
|
||||
try
|
||||
{
|
||||
apk = ApkHelper.ReadApkInfo(file.OpenReadStream());
|
||||
|
||||
// Validate APK info
|
||||
if (string.IsNullOrEmpty(apk.VersionName) || string.IsNullOrEmpty(apk.VersionCode))
|
||||
{
|
||||
return op.Failed("فایل APK معتبر نیست - اطلاعات نسخه یافت نشد");
|
||||
}
|
||||
|
||||
// Validate version code is numeric
|
||||
if (!int.TryParse(apk.VersionCode, out _))
|
||||
{
|
||||
return op.Failed("فایل APK معتبر نیست - کد نسخه باید عددی باشد");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return op.Failed("خطا در خواندن فایل APK: " + ex.Message);
|
||||
}
|
||||
string uniqueFileName = $"{Path.GetFileNameWithoutExtension(file.FileName)}.v{versionName}{Path.GetExtension(file.FileName)}";
|
||||
|
||||
string uniqueFileName = $"{Path.GetFileNameWithoutExtension(file.FileName)}.v{apk.VersionName}{Path.GetExtension(file.FileName)}";
|
||||
string filepath = Path.Combine(path, uniqueFileName);
|
||||
|
||||
await using (var stream = new FileStream(filepath, FileMode.Create))
|
||||
@@ -78,13 +62,13 @@ public class AndroidApkVersionApplication : IAndroidApkVersionApplication
|
||||
await file.CopyToAsync(stream);
|
||||
}
|
||||
|
||||
var entity = new AndroidApkVersion(apk.VersionName, apk.VersionCode, IsActive.True, filepath, apkType, isForce);
|
||||
var entity = new AndroidApkVersion(versionName, versionCode, IsActive.True, filepath);
|
||||
_androidApkVersionRepository.Create(entity);
|
||||
_androidApkVersionRepository.SaveChanges();
|
||||
return op.Succcedded();
|
||||
}
|
||||
|
||||
public async Task<OperationResult> CreateAndDeActive(IFormFile file, ApkType apkType, bool isForce = false)
|
||||
public async Task<OperationResult> CreateAndDeActive(IFormFile file, string versionName, string versionCode, ApkType apkType, bool isForce = false)
|
||||
{
|
||||
OperationResult op = new OperationResult();
|
||||
|
||||
@@ -96,6 +80,12 @@ public class AndroidApkVersionApplication : IAndroidApkVersionApplication
|
||||
if (Path.GetExtension(file.FileName).ToLower() != ".apk")
|
||||
return op.Failed("لطفا فایلی با پسوند .apk وارد کنید");
|
||||
|
||||
if (string.IsNullOrWhiteSpace(versionName))
|
||||
return op.Failed("لطفا نام ورژن را وارد کنید");
|
||||
|
||||
if (string.IsNullOrWhiteSpace(versionCode))
|
||||
return op.Failed("لطفا کد ورژن را وارد کنید");
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -105,31 +95,7 @@ public class AndroidApkVersionApplication : IAndroidApkVersionApplication
|
||||
|
||||
Directory.CreateDirectory(path);
|
||||
|
||||
// Read APK metadata with error handling
|
||||
ApkInfo apk;
|
||||
try
|
||||
{
|
||||
apk = ApkHelper.ReadApkInfo(file.OpenReadStream());
|
||||
|
||||
// Validate APK info
|
||||
if (string.IsNullOrEmpty(apk.VersionName) || string.IsNullOrEmpty(apk.VersionCode))
|
||||
{
|
||||
return op.Failed("فایل APK معتبر نیست - اطلاعات نسخه یافت نشد");
|
||||
}
|
||||
|
||||
// Validate version code is numeric
|
||||
if (!int.TryParse(apk.VersionCode, out _))
|
||||
{
|
||||
return op.Failed("فایل APK معتبر نیست - کد نسخه باید عددی باشد");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return op.Failed("خطا در خواندن فایل APK: " + ex.Message);
|
||||
}
|
||||
|
||||
string uniqueFileName = $"{Path.GetFileNameWithoutExtension(file.FileName)}.v{apk.VersionName}{Path.GetExtension(file.FileName)}";
|
||||
|
||||
string uniqueFileName = $"{Path.GetFileNameWithoutExtension(file.FileName)}.v{versionName}{Path.GetExtension(file.FileName)}";
|
||||
|
||||
string filepath = Path.Combine(path, uniqueFileName);
|
||||
|
||||
@@ -138,7 +104,7 @@ public class AndroidApkVersionApplication : IAndroidApkVersionApplication
|
||||
await file.CopyToAsync(stream);
|
||||
}
|
||||
|
||||
var entity = new AndroidApkVersion(apk.VersionName, apk.VersionCode, IsActive.False, filepath, apkType, isForce);
|
||||
var entity = new AndroidApkVersion(versionName, versionCode, IsActive.False, filepath);
|
||||
_androidApkVersionRepository.Create(entity);
|
||||
_androidApkVersionRepository.SaveChanges();
|
||||
return op.Succcedded();
|
||||
|
||||
@@ -4,24 +4,46 @@
|
||||
ViewData["Title"] = "File Upload";
|
||||
}
|
||||
|
||||
<h1>Upload File</h1>
|
||||
<form asp-page-handler="Upload" id="1" method="post" enctype="multipart/form-data">
|
||||
<div>
|
||||
<label asp-for="File">Choose a file:</label>
|
||||
<input asp-for="File" type="file" required>
|
||||
<h1>Upload APK File</h1>
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<form asp-page-handler="Upload" id="1" method="post" enctype="multipart/form-data">
|
||||
<div class="form-group">
|
||||
<label asp-for="File" class="form-label">Choose APK file:</label>
|
||||
<input asp-for="File" type="file" class="form-control" required accept=".apk">
|
||||
<small class="form-text text-muted">Please select a valid APK file.</small>
|
||||
<span asp-validation-for="File" class="text-danger"></span>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label asp-for="VersionName" class="form-label">Version Name:</label>
|
||||
<input asp-for="VersionName" type="text" class="form-control" placeholder="e.g. 1.0.0" required>
|
||||
<small class="form-text text-muted">Enter the version name (e.g. 1.0.0, 2.1.3).</small>
|
||||
<span asp-validation-for="VersionName" class="text-danger"></span>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label asp-for="VersionCode" class="form-label">Version Code:</label>
|
||||
<input asp-for="VersionCode" type="text" class="form-control" placeholder="e.g. 100" required>
|
||||
<small class="form-text text-muted">Enter the version code (numeric value).</small>
|
||||
<span asp-validation-for="VersionCode" class="text-danger"></span>
|
||||
</div>
|
||||
<div style="margin-top:12px;">
|
||||
<label asp-for="SelectedApkType">نوع اپلیکیشن:</label>
|
||||
<select asp-for="SelectedApkType" asp-items="Html.GetEnumSelectList<CompanyManagment.App.Contracts.AndroidApkVersion.ApkType>()"></select>
|
||||
</div>
|
||||
<div style="margin-top:12px;">
|
||||
<label asp-for="IsForce">
|
||||
<input asp-for="IsForce" type="checkbox">
|
||||
آپدیت اجباری (Force Update)
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<button type="submit" class="btn btn-primary">Upload APK</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div style="margin-top:12px;">
|
||||
<label asp-for="SelectedApkType">نوع اپلیکیشن:</label>
|
||||
<select asp-for="SelectedApkType" asp-items="Html.GetEnumSelectList<CompanyManagment.App.Contracts.AndroidApkVersion.ApkType>()"></select>
|
||||
</div>
|
||||
<div style="margin-top:12px;">
|
||||
<label asp-for="IsForce">
|
||||
<input asp-for="IsForce" type="checkbox">
|
||||
آپدیت اجباری (Force Update)
|
||||
</label>
|
||||
</div>
|
||||
<button type="submit" style="margin-top:12px;">Upload</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<form asp-page-handler="ShiftDate" id="8" method="post">
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ using Microsoft.Extensions.Options;
|
||||
using Parbad;
|
||||
using Parbad.AspNetCore;
|
||||
using Parbad.Gateway.Sepehr;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using static ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk.IndexModel2;
|
||||
|
||||
namespace ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk
|
||||
@@ -46,6 +47,16 @@ namespace ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk
|
||||
|
||||
|
||||
[BindProperty] public IFormFile File { get; set; }
|
||||
|
||||
[BindProperty]
|
||||
[Required(ErrorMessage = "لطفا نام ورژن را وارد کنید")]
|
||||
[Display(Name = "نام ورژن")]
|
||||
public string VersionName { get; set; }
|
||||
|
||||
[BindProperty]
|
||||
[Required(ErrorMessage = "لطفا کد ورژن را وارد کنید")]
|
||||
[Display(Name = "کد ورژن")]
|
||||
public string VersionCode { get; set; }
|
||||
[BindProperty] public ApkType SelectedApkType { get; set; }
|
||||
[BindProperty] public bool IsForce { get; set; }
|
||||
|
||||
@@ -70,7 +81,7 @@ namespace ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk
|
||||
|
||||
public async Task<IActionResult> OnPostUpload()
|
||||
{
|
||||
var result = await _application.CreateAndActive(File, SelectedApkType, IsForce);
|
||||
var result = await _application.CreateAndActive(File, VersionName, VersionCode, SelectedApkType, IsForce);
|
||||
ViewData["message"] = result.Message;
|
||||
return Page();
|
||||
}
|
||||
|
||||
@@ -408,7 +408,7 @@ app.MapHub<CreateContractTarckingHub>("/trackingHub");
|
||||
app.MapHub<SendAccountMessage>("/trackingSmsHub");
|
||||
app.MapHub<HolidayApiHub>("/trackingHolidayHub");
|
||||
app.MapHub<CheckoutHub>("/trackingCheckoutHub");
|
||||
app.MapHub<FaceEmbeddingHub>("/trackingFaceEmbeddingHub");
|
||||
// app.MapHub<FaceEmbeddingHub>("/trackingFaceEmbeddingHub");
|
||||
app.MapRazorPages();
|
||||
app.MapControllers();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user