-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
163 additions
and
81 deletions.
There are no files selected for viewing
31 changes: 23 additions & 8 deletions
31
ODPC.Server/Features/Documenten/DocumentBijwerken/DocumentBijwerkenController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 17 additions & 12 deletions
29
ODPC.Server/Features/Documenten/DocumentDownload/DocumentDownloadController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,33 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using ODPC.Apis.Odrc; | ||
using ODPC.Authentication; | ||
|
||
namespace ODPC.Features.Documenten.DocumentDownload | ||
{ | ||
public class DocumentDownloadController(IOdrcClientFactory clientFactory) : ControllerBase | ||
public class DocumentDownloadController(IOdrcClientFactory clientFactory, OdpcUser user) : ControllerBase | ||
{ | ||
[HttpGet("api/{apiVersion}/documenten/{uuid:guid}/download")] | ||
public async Task<IActionResult> Get(string apiVersion, Guid uuid, CancellationToken token) | ||
[HttpGet("api/{version}/documenten/{uuid:guid}/download")] | ||
public async Task<IActionResult> Get(string version, Guid uuid, CancellationToken token) | ||
{ | ||
using var client = clientFactory.Create("Document downloaden"); | ||
using var client = clientFactory.Create("Document ophalen"); | ||
|
||
// TODO: check eigenaar | ||
var url = $"/api/{version}/documenten/{uuid}"; | ||
|
||
var url = "/api/" + apiVersion + "/documenten/" + uuid + "/download"; | ||
using var response = await client.GetAsync(url, HttpCompletionOption.ResponseContentRead, token); | ||
|
||
var response = await client.GetAsync(url, token); | ||
if (!response.IsSuccessStatusCode) | ||
{ | ||
return StatusCode(502); | ||
} | ||
|
||
response.EnsureSuccessStatusCode(); | ||
var json = await response.Content.ReadFromJsonAsync<PublicatieDocument>(token); | ||
|
||
var contentType = response.Content.Headers.ContentType?.ToString() ?? "application/octet-stream"; | ||
var fileName = response.Content.Headers.ContentDisposition?.FileName?.Trim('"') ?? "woo_document"; | ||
var fileStream = await response.Content.ReadAsStreamAsync(token); | ||
if (json?.Eigenaar?.identifier != user.Id) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
return File(fileStream, contentType, fileName); | ||
return new DocumentDownloadResult(Request.Path, "Document downloaden"); | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
ODPC.Server/Features/Documenten/DocumentDownload/DocumentDownloadResult.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using ODPC.Apis.Odrc; | ||
|
||
namespace ODPC.Features.Documenten.DocumentDownload | ||
{ | ||
public class DocumentDownloadResult(string path, string reason) : IActionResult | ||
{ | ||
public async Task ExecuteResultAsync(ActionContext context) | ||
{ | ||
var response = context.HttpContext.Response; | ||
var token = context.HttpContext.RequestAborted; | ||
|
||
using var client = context.HttpContext.RequestServices.GetRequiredService<IOdrcClientFactory>().Create(reason); | ||
using var httpResponse = await client.GetAsync(path, HttpCompletionOption.ResponseContentRead, token); ; | ||
|
||
response.StatusCode = (int)httpResponse.StatusCode; | ||
response.Headers.ContentLength = httpResponse.Content.Headers.ContentLength; | ||
response.Headers.ContentDisposition = httpResponse.Content.Headers.ContentDisposition?.ToString(); | ||
response.Headers.ContentType = httpResponse.Content.Headers.ContentType?.ToString(); | ||
|
||
await httpResponse.Content.CopyToAsync(response.Body, token); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.