-
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
5 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
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,14 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Fedora | ||
{ | ||
public interface IFedora | ||
{ | ||
public Task<string> Proxy(string contentType, string path); | ||
|
||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
LeedsExperiment/Preservation.API/Controllers/FedoraController.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,28 @@ | ||
using Fedora; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace Preservation.API.Controllers | ||
{ | ||
[ApiController] | ||
[Route("api/fedora")] | ||
public class FedoraController : Controller | ||
{ | ||
private IFedora fedora; | ||
|
||
public FedoraController(IFedora fedora) | ||
{ | ||
this.fedora = fedora; | ||
} | ||
|
||
[HttpGet(Name = "FedoraProxy")] | ||
[Route("{contentTypeMajor}/{contentTypeMinor}/{*path}")] | ||
public async Task<IActionResult> Index(string contentTypeMajor, string contentTypeMinor, string? path) | ||
{ | ||
// in WebAPI, path is not giving us the full path | ||
var fullPath = string.Join("/", Request.Path.ToString().Split('/')[5..]); | ||
var contentType = $"{contentTypeMajor}/{contentTypeMinor}"; | ||
var result = await fedora.Proxy(contentType, fullPath); | ||
return Content(result, contentType); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using Fedora; | ||
using Preservation.API; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net.Http.Json; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Preservation | ||
{ | ||
public class Fedora : IFedora | ||
{ | ||
private readonly HttpClient _httpClient; | ||
|
||
public Fedora(HttpClient httpClient) | ||
{ | ||
_httpClient = httpClient; | ||
} | ||
|
||
public async Task<string> Proxy(string contentType, string path) | ||
{ | ||
var req = new HttpRequestMessage(); | ||
req.Headers.Accept.Clear(); | ||
req.Headers.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue(contentType)); | ||
req.RequestUri = new Uri(path, UriKind.Relative); | ||
var response = await _httpClient.SendAsync(req); | ||
var raw = await response.Content.ReadAsStringAsync(); | ||
return raw; | ||
} | ||
} | ||
} |
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