download page
This commit is contained in:
parent
78404147b2
commit
41275dc003
|
|
@ -0,0 +1,145 @@
|
|||
using Microsoft.AspNetCore.Mvc;
|
||||
using Nop.Core;
|
||||
using Nop.Plugin.Misc.FruitBankPlugin.Models.App;
|
||||
using Nop.Services.Security;
|
||||
using Nop.Web.Framework;
|
||||
using Nop.Web.Framework.Controllers;
|
||||
using Nop.Web.Framework.Mvc.Filters;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
|
||||
{
|
||||
[Area(AreaNames.ADMIN)]
|
||||
[AuthorizeAdmin]
|
||||
[AutoValidateAntiforgeryToken]
|
||||
public class AppDownloadController : BasePluginController
|
||||
{
|
||||
private readonly IPermissionService _permissionService;
|
||||
private readonly IWebHelper _webHelper;
|
||||
private readonly IWorkContext _workContext;
|
||||
|
||||
public AppDownloadController(
|
||||
IPermissionService permissionService,
|
||||
IWebHelper webHelper,
|
||||
IWorkContext workContext)
|
||||
{
|
||||
_permissionService = permissionService;
|
||||
_webHelper = webHelper;
|
||||
_workContext = workContext;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public virtual async Task<IActionResult> Index()
|
||||
{
|
||||
if (!await _permissionService.AuthorizeAsync(StandardPermission.Orders.ORDERS_CREATE_EDIT_DELETE))
|
||||
return AccessDeniedView();
|
||||
|
||||
var model = new AppDownloadModel
|
||||
{
|
||||
PreviousVersions = new List<AppVersionModel>()
|
||||
};
|
||||
|
||||
var appPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "app", "versions");
|
||||
|
||||
if (Directory.Exists(appPath))
|
||||
{
|
||||
var versionFolders = Directory.GetDirectories(appPath)
|
||||
.Select(d => new DirectoryInfo(d))
|
||||
.OrderByDescending(d => d.Name)
|
||||
.ToList();
|
||||
|
||||
foreach (var folder in versionFolders)
|
||||
{
|
||||
var apkFile = Directory.GetFiles(folder.FullName, "*.apk").FirstOrDefault();
|
||||
if (apkFile != null)
|
||||
{
|
||||
var fileInfo = new FileInfo(apkFile);
|
||||
var fileName = Path.GetFileName(apkFile);
|
||||
var versionModel = new AppVersionModel
|
||||
{
|
||||
Version = folder.Name,
|
||||
DownloadUrl = $"/app/versions/{folder.Name}/{fileName}",
|
||||
FileName = fileName, // Add this
|
||||
FileSizeFormatted = FormatFileSize(fileInfo.Length),
|
||||
ReleaseDate = fileInfo.CreationTime
|
||||
};
|
||||
|
||||
// Set the latest version
|
||||
if (model.CurrentVersion == null)
|
||||
{
|
||||
model.CurrentVersion = folder.Name;
|
||||
model.DownloadUrl = versionModel.DownloadUrl;
|
||||
model.FileName = fileName; // Add this
|
||||
model.FileSizeBytes = fileInfo.Length;
|
||||
model.FileSizeFormatted = versionModel.FileSizeFormatted;
|
||||
model.ReleaseDate = versionModel.ReleaseDate;
|
||||
|
||||
// Read changelog if exists
|
||||
var changelogFile = Path.Combine(folder.FullName, "changelog.txt");
|
||||
if (System.IO.File.Exists(changelogFile))
|
||||
{
|
||||
model.Changelog = await System.IO.File.ReadAllTextAsync(changelogFile);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
model.PreviousVersions.Add(versionModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return View("~/Plugins/Misc.FruitBankPlugin/Areas/Admin/Views/AppDownload/Index.cshtml", model);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public virtual IActionResult Download(string version, string fileName)
|
||||
{
|
||||
// Validate inputs
|
||||
if (string.IsNullOrEmpty(version) || string.IsNullOrEmpty(fileName))
|
||||
return BadRequest();
|
||||
|
||||
// Prevent directory traversal
|
||||
if (version.Contains("..") || fileName.Contains(".."))
|
||||
return BadRequest();
|
||||
|
||||
if (!fileName.EndsWith(".apk", StringComparison.OrdinalIgnoreCase))
|
||||
return BadRequest();
|
||||
|
||||
var filePath = Path.Combine(
|
||||
Directory.GetCurrentDirectory(),
|
||||
"wwwroot",
|
||||
"app",
|
||||
"versions",
|
||||
version,
|
||||
fileName);
|
||||
|
||||
if (!System.IO.File.Exists(filePath))
|
||||
return NotFound();
|
||||
|
||||
var fileBytes = System.IO.File.ReadAllBytes(filePath);
|
||||
|
||||
// Set proper headers for APK download
|
||||
Response.Headers.Add("Content-Disposition", $"attachment; filename=\"{fileName}\"");
|
||||
|
||||
return File(fileBytes, "application/vnd.android.package-archive", fileName);
|
||||
}
|
||||
|
||||
private string FormatFileSize(long bytes)
|
||||
{
|
||||
string[] sizes = { "B", "KB", "MB", "GB", "TB" };
|
||||
double len = bytes;
|
||||
int order = 0;
|
||||
while (len >= 1024 && order < sizes.Length - 1)
|
||||
{
|
||||
order++;
|
||||
len = len / 1024;
|
||||
}
|
||||
return $"{len:0.##} {sizes[order]}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
namespace Nop.Plugin.Misc.FruitBankPlugin.Models.App
|
||||
{
|
||||
public class AppDownloadModel
|
||||
{
|
||||
public string CurrentVersion { get; set; }
|
||||
public string DownloadUrl { get; set; }
|
||||
public string FileName { get; set; } // Add this
|
||||
public long FileSizeBytes { get; set; }
|
||||
public string FileSizeFormatted { get; set; }
|
||||
public DateTime ReleaseDate { get; set; }
|
||||
public string Changelog { get; set; }
|
||||
public List<AppVersionModel> PreviousVersions { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
namespace Nop.Plugin.Misc.FruitBankPlugin.Models.App
|
||||
{
|
||||
|
||||
public class AppVersionModel
|
||||
{
|
||||
public string Version { get; set; }
|
||||
public string DownloadUrl { get; set; }
|
||||
public string FileName { get; set; } // Add this
|
||||
public string FileSizeFormatted { get; set; }
|
||||
public DateTime ReleaseDate { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,167 @@
|
|||
@using System.IO
|
||||
@model Nop.Plugin.Misc.FruitBankPlugin.Models.App.AppDownloadModel
|
||||
|
||||
@{
|
||||
Layout = "_AdminLayout";
|
||||
NopHtml.SetActiveMenuItemSystemName("FruitBank.AppDownload");
|
||||
}
|
||||
|
||||
<div class="content-header clearfix">
|
||||
<h1 class="float-left">
|
||||
Android App letöltés
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
<section class="content">
|
||||
<div class="container-fluid">
|
||||
@if (!string.IsNullOrEmpty(Model.CurrentVersion))
|
||||
{
|
||||
<!-- Latest Version Card -->
|
||||
<div class="card card-default">
|
||||
<div class="card-header">
|
||||
<h3 class="card-title">
|
||||
<i class="fas fa-mobile-alt"></i>
|
||||
Legújabb verzió: @Model.CurrentVersion
|
||||
</h3>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
<div class="alert alert-info">
|
||||
<i class="fas fa-info-circle"></i>
|
||||
<strong>Telepítési útmutató:</strong>
|
||||
<ol class="mb-0 mt-2">
|
||||
<li>Engedélyezd az "Ismeretlen forrásokból" való telepítést a táblagépen (Beállítások → Biztonság)</li>
|
||||
<li>Kattints a "Letöltés" gombra</li>
|
||||
<li>Nyisd meg a letöltött APK fájlt</li>
|
||||
<li>Kövesd a telepítési utasításokat</li>
|
||||
</ol>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<strong>Verzió:</strong> @Model.CurrentVersion<br />
|
||||
<strong>Méret:</strong> @Model.FileSizeFormatted<br />
|
||||
<strong>Kiadás dátuma:</strong> @Model.ReleaseDate.ToString("yyyy-MM-dd HH:mm")
|
||||
</div>
|
||||
|
||||
@if (!string.IsNullOrEmpty(Model.Changelog))
|
||||
{
|
||||
<div class="mb-3">
|
||||
<strong>Változások:</strong>
|
||||
<pre class="bg-light p-3 rounded">@Model.Changelog</pre>
|
||||
</div>
|
||||
}
|
||||
|
||||
<a href="@Url.Action("Download", "AppDownload", new { version = Model.CurrentVersion, fileName = Model.FileName })" class="btn btn-primary btn-lg">
|
||||
<i class="fas fa-download"></i>
|
||||
Letöltés (@Model.FileSizeFormatted)
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="col-md-4">
|
||||
<div class="text-center">
|
||||
<!-- QR Code for easy download on tablet -->
|
||||
<div id="qrcode" class="mb-3"></div>
|
||||
<p class="text-muted"><small>Szkenneld be a QR kódot a táblagéppel a közvetlen letöltéshez</small></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (Model.PreviousVersions != null && Model.PreviousVersions.Any())
|
||||
{
|
||||
<!-- Previous Versions Card -->
|
||||
<div class="card card-default collapsed-card">
|
||||
<div class="card-header">
|
||||
<h3 class="card-title">
|
||||
<i class="fas fa-history"></i>
|
||||
Korábbi verziók
|
||||
</h3>
|
||||
<div class="card-tools">
|
||||
<button type="button" class="btn btn-tool" data-card-widget="collapse">
|
||||
<i class="fas fa-plus"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body" style="display: none;">
|
||||
<table class="table table-bordered table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Verzió</th>
|
||||
<th>Méret</th>
|
||||
<th>Kiadás dátuma</th>
|
||||
<th>Letöltés</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var version in Model.PreviousVersions)
|
||||
{
|
||||
<tr>
|
||||
<td>@version.Version</td>
|
||||
<td>@version.FileSizeFormatted</td>
|
||||
<td>@version.ReleaseDate.ToString("yyyy-MM-dd HH:mm")</td>
|
||||
<td>
|
||||
<a href="@Url.Action("Download", "AppDownload", new { version = version.Version, fileName = version.FileName })" class="btn btn-sm btn-secondary" download>
|
||||
<i class="fas fa-download"></i>
|
||||
Letöltés
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="card card-default">
|
||||
<div class="card-body">
|
||||
<div class="alert alert-warning">
|
||||
<i class="fas fa-exclamation-triangle"></i>
|
||||
Nincs elérhető app verzió. Kérlek, helyezd el az APK fájlt a <code>wwwroot/app/versions/</code> mappában.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/qrcodejs@1.0.0/qrcode.min.js"></script>
|
||||
<script>
|
||||
$(function() {
|
||||
@if (!string.IsNullOrEmpty(Model.DownloadUrl))
|
||||
{
|
||||
<text>
|
||||
var downloadUrl = window.location.origin + '@Model.DownloadUrl';
|
||||
new QRCode(document.getElementById("qrcode"), {
|
||||
text: downloadUrl,
|
||||
width: 200,
|
||||
height: 200,
|
||||
colorDark: "#000000",
|
||||
colorLight: "#ffffff",
|
||||
correctLevel: QRCode.CorrectLevel.H
|
||||
});
|
||||
</text>
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
<style>
|
||||
#qrcode {
|
||||
display: inline-block;
|
||||
padding: 10px;
|
||||
background: white;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
#qrcode img {
|
||||
display: block;
|
||||
}
|
||||
</style>
|
||||
|
|
@ -156,6 +156,16 @@ public class RouteProvider : IRouteProvider
|
|||
name: "Plugin.FruitBank.Admin.ManagementPage.ProcessShippingDocument",
|
||||
pattern: "Admin/ManagamentPage/ProcessShippingDocument/{id}",
|
||||
defaults: new { controller = "ManagementPage", action = "ProcessShippingdocument", area = AreaNames.ADMIN });
|
||||
|
||||
endpointRouteBuilder.MapControllerRoute(
|
||||
name: "Plugin.FruitBank.AppDownload",
|
||||
pattern: "Admin/AppDownload",
|
||||
defaults: new { controller = "AppDownload", action = "Index", area = AreaNames.ADMIN });
|
||||
|
||||
endpointRouteBuilder.MapControllerRoute(
|
||||
name: "Plugin.FruitBank.AppDownload.Download",
|
||||
pattern: "Admin/AppDownload/Download/{version}/{fileName}",
|
||||
defaults: new { controller = "AppDownload", action = "Download", area = AreaNames.ADMIN });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -167,6 +167,9 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="Areas\Admin\Views\AppDownload\Index.cshtml">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Areas\Admin\Views\Order\FileUploadGridComponent.cshtml">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
|
|
|
|||
Loading…
Reference in New Issue