Move downloads to new controller
This commit is contained in:
@@ -0,0 +1,111 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Web.Mvc;
|
||||||
|
using LeafWeb.Core.Entities;
|
||||||
|
using LeafWeb.Core.Utility;
|
||||||
|
using LeafWeb.WebCms.Models;
|
||||||
|
using LeafWeb.WebCms.Utility;
|
||||||
|
using Umbraco.Web.Mvc;
|
||||||
|
|
||||||
|
namespace LeafWeb.WebCms.Controllers
|
||||||
|
{
|
||||||
|
public class DownloadController : BaseController
|
||||||
|
{
|
||||||
|
[ActionLog]
|
||||||
|
public ActionResult Results(string token)
|
||||||
|
{
|
||||||
|
var leafInput = DataService.GetLeafInput(token);
|
||||||
|
|
||||||
|
if (leafInput == null)
|
||||||
|
return View("DownloadNotFound");
|
||||||
|
|
||||||
|
var zip = leafInput.GetOutputFileZip(LeafOutputFileType.ToUser);
|
||||||
|
|
||||||
|
var filename = leafInput.Identifier.FilterValidFilename() + ".zip";
|
||||||
|
|
||||||
|
return new FileContentResult(zip, "application/zip") { FileDownloadName = filename };
|
||||||
|
}
|
||||||
|
|
||||||
|
[MemberAuthorize(AllowGroup = "Authenticated,Administrator")]
|
||||||
|
public ActionResult Input(int id)
|
||||||
|
{
|
||||||
|
return GetInputZip(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
[MemberAuthorize(AllowGroup = "Authenticated,Administrator")]
|
||||||
|
public ActionResult OutputToUser(int id)
|
||||||
|
{
|
||||||
|
return GetOutputZip(id, LeafOutputFileType.ToUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
[MemberAuthorize(AllowGroup = "Administrator")]
|
||||||
|
public ActionResult OutputNotToUser(int id)
|
||||||
|
{
|
||||||
|
return GetOutputZip(id, LeafOutputFileType.NotToUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
[MemberAuthorize(AllowGroup = "Authenticated,Administrator")]
|
||||||
|
public ActionResult OutputCleanedInput(int id)
|
||||||
|
{
|
||||||
|
return GetOutputZip(id, LeafOutputFileType.CleanedInput);
|
||||||
|
}
|
||||||
|
|
||||||
|
[MemberAuthorize(AllowGroup = "Authenticated,Administrator")]
|
||||||
|
public ActionResult ResultsInputZip(LeafDataQuery query)
|
||||||
|
{
|
||||||
|
return GetResults(query, LeafInput.GetInputFilesZip, $"LeafWeb_{DateTime.Now:yyyy-dd-MM--HH-mm-ss}_Input.zip");
|
||||||
|
}
|
||||||
|
|
||||||
|
[MemberAuthorize(AllowGroup = "Authenticated,Administrator")]
|
||||||
|
public ActionResult ResultsOutputZip(LeafDataQuery query)
|
||||||
|
{
|
||||||
|
return GetResults(query, LeafInput.GetOutputFilesZip_ToUser, $"LeafWeb_{DateTime.Now:yyyy-dd-MM--HH-mm-ss}_Output.zip");
|
||||||
|
}
|
||||||
|
|
||||||
|
private ActionResult GetOutputZip(int id, LeafOutputFileType type)
|
||||||
|
{
|
||||||
|
var leafInput = DataService.GetLeafInput(id);
|
||||||
|
|
||||||
|
if (leafInput == null)
|
||||||
|
return View("DownloadNotFound");
|
||||||
|
|
||||||
|
var zip = leafInput.GetOutputFileZip(type);
|
||||||
|
|
||||||
|
var filename = $"{leafInput.Identifier.FilterValidFilename()}_{type}.zip";
|
||||||
|
|
||||||
|
return new FileContentResult(zip, "application/zip") { FileDownloadName = filename };
|
||||||
|
}
|
||||||
|
|
||||||
|
private ActionResult GetInputZip(int id)
|
||||||
|
{
|
||||||
|
var leafInput = DataService.GetLeafInput(id);
|
||||||
|
|
||||||
|
if (leafInput == null)
|
||||||
|
return View("DownloadNotFound");
|
||||||
|
|
||||||
|
var zip = leafInput.GetInputFileZip();
|
||||||
|
|
||||||
|
var filename = $"{leafInput.Identifier.FilterValidFilename()}_Input.zip";
|
||||||
|
|
||||||
|
return new FileContentResult(zip, "application/zip") { FileDownloadName = filename };
|
||||||
|
}
|
||||||
|
|
||||||
|
private ActionResult GetResults(LeafDataQuery query, Func<IEnumerable<LeafInput>, byte[]> getZip, string filename)
|
||||||
|
{
|
||||||
|
var resultItems =
|
||||||
|
DataService.GetLeafInputsOrdered();
|
||||||
|
|
||||||
|
resultItems
|
||||||
|
= QueryFilter.Search(resultItems, query, Members.GetCurrentLoginStatus()?.Email);
|
||||||
|
|
||||||
|
if (resultItems == null)
|
||||||
|
return View("DownloadNotFound");
|
||||||
|
|
||||||
|
var zip = getZip(resultItems);
|
||||||
|
|
||||||
|
//var filename = $"LeafWeb_{DateTime.Now:yyyy-dd-MM--HH-mm-ss}_Input.zip";
|
||||||
|
|
||||||
|
return new FileContentResult(zip, "application/zip") { FileDownloadName = filename };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -108,82 +108,6 @@ namespace LeafWeb.WebCms.Controllers
|
|||||||
return View(viewModel);
|
return View(viewModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActionResult DownloadInput(int id)
|
|
||||||
{
|
|
||||||
return GetInputZip(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ActionResult DownloadOutputToUser(int id)
|
|
||||||
{
|
|
||||||
return GetOutputZip(id, LeafOutputFileType.ToUser);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ActionResult DownloadOutputNotToUser(int id)
|
|
||||||
{
|
|
||||||
return GetOutputZip(id, LeafOutputFileType.NotToUser);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ActionResult DownloadOutputCleanedInput(int id)
|
|
||||||
{
|
|
||||||
return GetOutputZip(id, LeafOutputFileType.CleanedInput);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ActionResult DownloadResultsInputZip(LeafDataQuery query)
|
|
||||||
{
|
|
||||||
return GetResults(query, LeafInput.GetInputFilesZip, $"LeafWeb_{DateTime.Now:yyyy-dd-MM--HH-mm-ss}_Input.zip");
|
|
||||||
}
|
|
||||||
|
|
||||||
public ActionResult DownloadResultsOutputZip(LeafDataQuery query)
|
|
||||||
{
|
|
||||||
return GetResults(query, LeafInput.GetOutputFilesZip_ToUser, $"LeafWeb_{DateTime.Now:yyyy-dd-MM--HH-mm-ss}_Output.zip");
|
|
||||||
}
|
|
||||||
|
|
||||||
private ActionResult GetOutputZip(int id, LeafOutputFileType type)
|
|
||||||
{
|
|
||||||
var leafInput = DataService.GetLeafInput(id);
|
|
||||||
|
|
||||||
if (leafInput == null)
|
|
||||||
return View("DownloadNotFound");
|
|
||||||
|
|
||||||
var zip = leafInput.GetOutputFileZip(type);
|
|
||||||
|
|
||||||
var filename = $"{leafInput.Identifier.FilterValidFilename()}_{type}.zip";
|
|
||||||
|
|
||||||
return new FileContentResult(zip, "application/zip") { FileDownloadName = filename };
|
|
||||||
}
|
|
||||||
|
|
||||||
private ActionResult GetInputZip(int id)
|
|
||||||
{
|
|
||||||
var leafInput = DataService.GetLeafInput(id);
|
|
||||||
|
|
||||||
if (leafInput == null)
|
|
||||||
return View("DownloadNotFound");
|
|
||||||
|
|
||||||
var zip = leafInput.GetInputFileZip();
|
|
||||||
|
|
||||||
var filename = $"{leafInput.Identifier.FilterValidFilename()}_Input.zip";
|
|
||||||
|
|
||||||
return new FileContentResult(zip, "application/zip") { FileDownloadName = filename };
|
|
||||||
}
|
|
||||||
|
|
||||||
private ActionResult GetResults(LeafDataQuery query, Func<IEnumerable<LeafInput>, byte[]> getZip, string filename)
|
|
||||||
{
|
|
||||||
var resultItems =
|
|
||||||
DataService.GetLeafInputsOrdered();
|
|
||||||
|
|
||||||
resultItems
|
|
||||||
= QueryFilter.Search(resultItems, query, Members.GetCurrentLoginStatus()?.Email);
|
|
||||||
|
|
||||||
if (resultItems == null)
|
|
||||||
return View("DownloadNotFound");
|
|
||||||
|
|
||||||
var zip = getZip(resultItems);
|
|
||||||
|
|
||||||
//var filename = $"LeafWeb_{DateTime.Now:yyyy-dd-MM--HH-mm-ss}_Input.zip";
|
|
||||||
|
|
||||||
return new FileContentResult(zip, "application/zip") { FileDownloadName = filename };
|
|
||||||
}
|
|
||||||
|
|
||||||
[ActionLog]
|
[ActionLog]
|
||||||
public ActionResult Delete(int id)
|
public ActionResult Delete(int id)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using LeafWeb.Core.Entities;
|
using LeafWeb.Core.Entities;
|
||||||
@@ -71,20 +72,5 @@ namespace LeafWeb.WebCms.Controllers
|
|||||||
select li;
|
select li;
|
||||||
return View(viewModel);
|
return View(viewModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
[ActionLog]
|
|
||||||
public ActionResult Download(string token)
|
|
||||||
{
|
|
||||||
var leafInput = DataService.GetLeafInput(token);
|
|
||||||
|
|
||||||
if (leafInput == null)
|
|
||||||
return View("DownloadNotFound");
|
|
||||||
|
|
||||||
var zip = leafInput.GetOutputFileZip(LeafOutputFileType.ToUser);
|
|
||||||
|
|
||||||
var filename = leafInput.Identifier.FilterValidFilename() + ".zip";
|
|
||||||
|
|
||||||
return new FileContentResult(zip, "application/zip") { FileDownloadName = filename };
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -12,16 +12,16 @@
|
|||||||
<span class="fa fa-download"></span> Download
|
<span class="fa fa-download"></span> Download
|
||||||
</button>
|
</button>
|
||||||
<div class="dropdown-menu" aria-labelledby="downloadButton">
|
<div class="dropdown-menu" aria-labelledby="downloadButton">
|
||||||
<a href="@Url.Action("DownloadInput", "Queue", new {id = Model.LeafInputId})"
|
<a href="@Url.Action("Input", "Download", new {id = Model.LeafInputId})"
|
||||||
class="dropdown-item">
|
class="dropdown-item">
|
||||||
Input
|
Input
|
||||||
</a>
|
</a>
|
||||||
<a href="@Url.Action("DownloadOutputToUser", "Queue", new {id = Model.LeafInputId})"
|
<a href="@Url.Action("OutputToUser", "Download", new {id = Model.LeafInputId})"
|
||||||
class="dropdown-item @if (!Model.HasOutputFiles) {<text> disabled</text>}">
|
class="dropdown-item @if (!Model.HasOutputFiles) {<text> disabled</text>}">
|
||||||
ToUser
|
ToUser
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<a href="@Url.Action("DownloadOutputNotToUser", "Queue", new {id = Model.LeafInputId})"
|
<a href="@Url.Action("OutputNotToUser", "Download", new {id = Model.LeafInputId})"
|
||||||
class="dropdown-item @if (!Model.HasOutputFiles) {<text> disabled</text>}">
|
class="dropdown-item @if (!Model.HasOutputFiles) {<text> disabled</text>}">
|
||||||
NotToUser
|
NotToUser
|
||||||
</a>
|
</a>
|
||||||
|
|||||||
@@ -109,10 +109,10 @@ else
|
|||||||
@helper DownloadResults()
|
@helper DownloadResults()
|
||||||
{
|
{
|
||||||
<div class="btn-group" role="group" aria-label="Download">
|
<div class="btn-group" role="group" aria-label="Download">
|
||||||
<a class="btn btn-outline-secondary small" role="button" href="@Url.Action("DownloadResultsInputZip", "Queue", Model.Q.GetNameValueCollection().ToRouteValueDictionary())">
|
<a class="btn btn-outline-secondary small" role="button" href="@Url.Action("ResultsInputZip", "Download", Model.Q.GetNameValueCollection().ToRouteValueDictionary())">
|
||||||
<span class="fa fa-download"></span> Input
|
<span class="fa fa-download"></span> Input
|
||||||
</a>
|
</a>
|
||||||
<a class="btn btn-outline-secondary small" role="button" href="@Url.Action("DownloadResultsOutputZip", "Queue", Model.Q.GetNameValueCollection().ToRouteValueDictionary())">
|
<a class="btn btn-outline-secondary small" role="button" href="@Url.Action("ResultsOutputZip", "Download", Model.Q.GetNameValueCollection().ToRouteValueDictionary())">
|
||||||
<span class="fa fa-download"></span> Output
|
<span class="fa fa-download"></span> Output
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -11,11 +11,11 @@
|
|||||||
<span class="fa fa-download"></span> Download
|
<span class="fa fa-download"></span> Download
|
||||||
</button>
|
</button>
|
||||||
<div class="dropdown-menu" aria-labelledby="downloadButton">
|
<div class="dropdown-menu" aria-labelledby="downloadButton">
|
||||||
<a href="@Url.Action("DownloadInput", "Queue", new {id = Model.LeafInputId})"
|
<a href="@Url.Action("Input", "Download", new {id = Model.LeafInputId})"
|
||||||
class="dropdown-item">
|
class="dropdown-item">
|
||||||
Input
|
Input
|
||||||
</a>
|
</a>
|
||||||
<a href="@Url.Action("DownloadOutputToUser", "Queue", new {id = Model.LeafInputId})"
|
<a href="@Url.Action("OutputToUser", "Download", new {id = Model.LeafInputId})"
|
||||||
class="dropdown-item @if (!Model.HasOutputFiles) {<text> disabled</text>}">
|
class="dropdown-item @if (!Model.HasOutputFiles) {<text> disabled</text>}">
|
||||||
ToUser
|
ToUser
|
||||||
</a>
|
</a>
|
||||||
|
|||||||
@@ -74,13 +74,13 @@
|
|||||||
|
|
||||||
@helper DownloadInput(dynamic item)
|
@helper DownloadInput(dynamic item)
|
||||||
{
|
{
|
||||||
<a href="@Url.Action("DownloadInput", "Queue", new {id = item.Id})" class="dropdown-item">
|
<a href="@Url.Action("Input", "Download", new {id = item.Id})" class="dropdown-item">
|
||||||
<span class="fa fa-download"></span> Input
|
<span class="fa fa-download"></span> Input
|
||||||
</a>
|
</a>
|
||||||
}
|
}
|
||||||
@helper DownloadOutputToUser(dynamic item)
|
@helper DownloadOutputToUser(dynamic item)
|
||||||
{
|
{
|
||||||
<a href="@Url.Action("DownloadOutputToUser", "Queue", new {id = item.Id})" class="dropdown-item @DisableItem(!item.HasOutputFiles)">
|
<a href="@Url.Action("OutputToUser", "Download", new {id = item.Id})" class="dropdown-item @DisableItem(!item.HasOutputFiles)">
|
||||||
<span class="fa fa-download"></span> ToUser
|
<span class="fa fa-download"></span> ToUser
|
||||||
</a>
|
</a>
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -351,7 +351,7 @@
|
|||||||
<rules>
|
<rules>
|
||||||
<rule name="ResultsDownload" stopProcessing="true">
|
<rule name="ResultsDownload" stopProcessing="true">
|
||||||
<match url="Results/Download(.*)" />
|
<match url="Results/Download(.*)" />
|
||||||
<action type="Rewrite" url="/umbraco/surface/Results/Download{R:1}" />
|
<action type="Rewrite" url="/umbraco/surface/Download/Results{R:1}" />
|
||||||
</rule>
|
</rule>
|
||||||
<rule name="MembershipVerify" stopProcessing="true">
|
<rule name="MembershipVerify" stopProcessing="true">
|
||||||
<match url="^verify$" />
|
<match url="^verify$" />
|
||||||
|
|||||||
@@ -1004,7 +1004,7 @@
|
|||||||
<Content Include="Views\MacroPartials\BannerLink.cshtml" />
|
<Content Include="Views\MacroPartials\BannerLink.cshtml" />
|
||||||
<Content Include="Views\MacroPartials\Membership\Login.cshtml" />
|
<Content Include="Views\MacroPartials\Membership\Login.cshtml" />
|
||||||
<Content Include="Views\Queue\Index.cshtml" />
|
<Content Include="Views\Queue\Index.cshtml" />
|
||||||
<Content Include="Views\Queue\DownloadNotFound.cshtml" />
|
<Content Include="Views\Shared\DownloadNotFound.cshtml" />
|
||||||
<Content Include="Views\Queue\Details.cshtml" />
|
<Content Include="Views\Queue\Details.cshtml" />
|
||||||
<Content Include="Views\MacroPartials\BlogHighlights.cshtml" />
|
<Content Include="Views\MacroPartials\BlogHighlights.cshtml" />
|
||||||
<Content Include="Views\MacroPartials\Queue.cshtml" />
|
<Content Include="Views\MacroPartials\Queue.cshtml" />
|
||||||
@@ -1099,6 +1099,7 @@
|
|||||||
<Compile Include="Backload\Helper\ResultCreator.Classic.cs" />
|
<Compile Include="Backload\Helper\ResultCreator.Classic.cs" />
|
||||||
<Compile Include="Backload\Helper\ResultCreator.cs" />
|
<Compile Include="Backload\Helper\ResultCreator.cs" />
|
||||||
<Compile Include="Controllers\CompileFlag.cs" />
|
<Compile Include="Controllers\CompileFlag.cs" />
|
||||||
|
<Compile Include="Controllers\DownloadController.cs" />
|
||||||
<Compile Include="Controllers\EnforceTrueAttribute.cs" />
|
<Compile Include="Controllers\EnforceTrueAttribute.cs" />
|
||||||
<Compile Include="Controllers\ActionLogAttribute.cs" />
|
<Compile Include="Controllers\ActionLogAttribute.cs" />
|
||||||
<Compile Include="Controllers\BackloadController.cs" />
|
<Compile Include="Controllers\BackloadController.cs" />
|
||||||
|
|||||||
Reference in New Issue
Block a user