Skip to content
Snippets Groups Projects
Commit 0a8dd46b authored by Benedikt Heinrichs's avatar Benedikt Heinrichs
Browse files

Implement a GetDownloadUrl method

parent 620549b8
No related branches found
No related tags found
1 merge request!30New: Implement GetUploadUrl & GetDownloadUrl
......@@ -180,14 +180,35 @@ namespace Coscine.Api.Blob.Controllers
}
}
/// <summary>
/// This method returns the download url for a resource and path
/// </summary>
/// <param name="resourceId">Id of the resource</param>
/// <param name="path">Path to the to downloaded file</param>
/// <returns>Uri of the download url in the form of: "{ data: { url: url } }"</returns>
[HttpGet("[controller]/downloadUrl/{resourceId}/{*path}")]
public async Task<IActionResult> GetDownloadUrl(string resourceId, string path)
{
return await GetUrl(resourceId, path,
(resourceTypeDefinition, path, version, resourceTypeOptions)
=> resourceTypeDefinition.GetEntryDownloadUrl(path, version, resourceTypeOptions));
}
/// <summary>
/// This method returns the upload url for a resource and path
/// </summary>
/// <param name="resourceId">Id of the resource</param>
/// <param name="path">Path to the to uploaded file</param>
/// <returns>Uri of the upload url</returns>
/// <returns>Uri of the upload url in the form of: "{ data: { url: url } }"</returns>
[HttpGet("[controller]/uploadUrl/{resourceId}/{*path}")]
public async Task<IActionResult> GetUploadUrl(string resourceId, string path)
{
return await GetUrl(resourceId, path,
(resourceTypeDefinition, path, version, resourceTypeOptions)
=> resourceTypeDefinition.GetEntryStoreUrl(path, version, resourceTypeOptions));
}
private async Task<IActionResult> GetUrl(string resourceId, string path, Func<ResourceTypeDefinition, string, string, Dictionary<string, string>, Task<Uri>> receiver)
{
var rawPath = path;
......@@ -216,15 +237,14 @@ namespace Coscine.Api.Blob.Controllers
return BadRequest($"No provider for: \"{resource.Type.DisplayName}\".");
}
var entryStoreUrl = await resourceTypeDefinition.GetEntryStoreUrl(rawPath, null, resourceTypeOptions);
if (entryStoreUrl == null)
var entryUrl = await receiver(resourceTypeDefinition, rawPath, null, resourceTypeOptions);
if (entryUrl == null)
{
var hostUrl = await _configuration.GetStringAsync("coscine/local/api/additional/url");
var apiPath = $"/coscine/api/{((System.Reflection.Assembly.GetEntryAssembly() != null) ? System.Reflection.Assembly.GetEntryAssembly().GetName().Name : System.Reflection.Assembly.GetExecutingAssembly().GetName().Name)}";
entryStoreUrl = new Uri($"{hostUrl}{apiPath}/Blob/{resourceId}/{rawPath}");
entryUrl = new Uri($"{hostUrl}{apiPath}/Blob/{resourceId}/{rawPath}");
}
return Ok($"{{ \"data\": {{ \"entryStoreUrl\": \"{entryStoreUrl}\" }} }}");
return Ok($"{{ \"data\": {{ \"url\": \"{entryUrl}\" }} }}");
}
/// <summary>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment