Skip to content
This repository was archived by the owner on Aug 15, 2023. It is now read-only.

Commit efbfe8a

Browse files
authored
Merge pull request #311 from Developer-Autodesk/er/INVGEN-45169-pdf-for-authd-user
INVGEN-45169: for download of Drawing Pdf for authorized user
2 parents e93c09d + b039323 commit efbfe8a

File tree

4 files changed

+21
-9
lines changed

4 files changed

+21
-9
lines changed

WebApplication/Controllers/DownloadController.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929

3030
namespace WebApplication.Controllers
3131
{
32+
// The app is not keeping user session, so it's necessary to pass auth token
33+
// for authenticated users to resolve the downloaded item correctly.
34+
// By implementation the token will be appended by client-side to the end of download URL, so
35+
// the download route should contain optional `token` argument, which will be extracted
36+
// and applied to the execution context by `RouteTokenPipeline` middleware.
3237
[ApiController]
3338
[Route("download")]
3439
[MiddlewareFilter(typeof(RouteTokenPipeline))]
@@ -67,11 +72,12 @@ public async Task<ActionResult> BOM(string projectName, string hash, string toke
6772
return File(stream, "text/csv", "bom.csv");
6873
}
6974

70-
[HttpGet("{projectName}/{hash}/{fileName}")]
71-
public async Task<ActionResult> DrawingViewables(string projectName, string hash, string fileName)
75+
// viewer expects PDF extension, so `drawing.pdf` is a piece of the route
76+
[HttpGet("{projectName}/{hash}/drawing.pdf/{token?}")]
77+
public async Task<ActionResult> DrawingPdf(string projectName, string hash, string token = null)
7278
{
73-
string localFileName = await _userResolver.EnsureLocalFile(projectName, fileName, hash);
74-
return new PhysicalFileResult(localFileName, "application/pdf");
79+
string localFileName = await _userResolver.EnsureLocalFile(projectName, LocalName.DrawingPdf, hash);
80+
return new PhysicalFileResult(localFileName, "application/pdf") { FileDownloadName = LocalName.DrawingPdf };
7581
}
7682

7783
[HttpGet("{projectName}/{hash}/drawing/{token?}")]

WebApplication/Controllers/ProjectsController.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,11 @@ public async Task<ActionResult<ProjectDTO>> CreateProject([FromForm]NewProjectMo
9393
// Check if project already exists
9494
foreach (var existingProjectName in await GetProjectNamesAsync(bucket))
9595
{
96-
if (projectName == existingProjectName) return Conflict();
96+
if (projectName == existingProjectName)
97+
{
98+
_logger.LogError($"Found existing '{projectName}' project");
99+
return Conflict();
100+
}
97101
}
98102

99103
var projectInfo = new ProjectInfo

WebApplication/Job/ExportDrawingPdfJobItem.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,14 @@ public override async Task ProcessJobAsync(IResultSender resultSender)
5252
if (stats != null)
5353
{
5454
url = _linkGenerator.GetPathByAction(controller: "Download",
55-
action: "DrawingViewables",
56-
values: new { projectName = ProjectId, fileName = "drawing.pdf", hash = _hash });
55+
action: "DrawingPdf",
56+
values: new { projectName = ProjectId, hash = _hash });
5757

5858
// when local url starts with slash, it does not work, because it is doubled in url
59-
url = url.IndexOf("/") == 0 ? url.Substring(1) : url;
59+
if (url.StartsWith('/'))
60+
{
61+
url = url.Substring(1);
62+
}
6063
}
6164

6265
await resultSender.SendSuccessAsync(url, stats);

WebApplication/Middleware/RouteTokenHandler.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
using Microsoft.AspNetCore.Routing;
2323
using Microsoft.Extensions.Logging;
2424
using WebApplication.Services;
25-
using WebApplication.State;
2625

2726
namespace WebApplication.Middleware
2827
{

0 commit comments

Comments
 (0)