61 lines
2.0 KiB
C#
61 lines
2.0 KiB
C#
|
|
using CompanyManagment.App.Contracts.AndroidApkVersion;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using ServiceHost.BaseControllers;
|
|
|
|
namespace ServiceHost.Areas.Admin.Controllers;
|
|
|
|
[AllowAnonymous]
|
|
[ApiController]
|
|
[Route("api/android-apk")]
|
|
public class AndroidApkController:AdminBaseController
|
|
{
|
|
private readonly IAndroidApkVersionApplication _apkApp;
|
|
public AndroidApkController(IAndroidApkVersionApplication apkApp)
|
|
{
|
|
_apkApp = apkApp;
|
|
}
|
|
|
|
[HttpGet("check-update")]
|
|
public async Task<IActionResult> CheckUpdate([FromQuery] ApkType type, [FromQuery] int currentVersionCode = 0)
|
|
{
|
|
|
|
var info = await _apkApp.GetLatestActiveInfo(type, currentVersionCode);
|
|
return Ok(new
|
|
{
|
|
latestVersionCode = info.LatestVersionCode,
|
|
latestVersionName = info.LatestVersionName,
|
|
shouldUpdate = info.ShouldUpdate,
|
|
isForceUpdate = info.IsForceUpdate,
|
|
downloadUrl = info.DownloadUrl,
|
|
releaseNotes = info.ReleaseNotes
|
|
});
|
|
}
|
|
|
|
[HttpGet("download")]
|
|
public async Task<IActionResult> Download([FromQuery] ApkType type)
|
|
{
|
|
// Check if APK exists
|
|
if (!_apkApp.HasAndroidApkToDownload(type))
|
|
{
|
|
return NotFound(new { message = $"هیچ فایل APK فعالی برای {type} یافت نشد" });
|
|
}
|
|
|
|
// Get the path to the latest active APK
|
|
var path = await _apkApp.GetLatestActiveVersionPath(type);
|
|
|
|
if (string.IsNullOrEmpty(path) || !System.IO.File.Exists(path))
|
|
{
|
|
return NotFound(new { message = "فایل APK یافت نشد" });
|
|
}
|
|
|
|
// Set appropriate file name for download
|
|
var fileName = type == ApkType.WebView
|
|
? "Gozareshgir.apk"
|
|
: "Gozareshgir-FaceDetection.apk";
|
|
|
|
// Return the file for download
|
|
return PhysicalFile(path, "application/vnd.android.package-archive", fileName);
|
|
}
|
|
} |