Skip to content
Snippets Groups Projects
Commit ac9343c7 authored by Marcel Nellesen's avatar Marcel Nellesen
Browse files

Fix: Removed Download and Upload Url functions

parent e26d7e9d
No related branches found
No related tags found
1 merge request!31Sprint/2021 07
...@@ -180,73 +180,6 @@ namespace Coscine.Api.Blob.Controllers ...@@ -180,73 +180,6 @@ 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 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;
var user = _authenticator.GetUser();
path = $"/{path}";
var checkPath = CheckPath(path);
if (checkPath != null)
{
return checkPath;
}
var checkResourceId = CheckResource(resourceId, out Resource resource);
if (checkResourceId != null)
{
return checkResourceId;
}
var checkUser = CheckUser(user, resource);
if (checkUser != null)
{
return checkUser;
}
var resourceTypeOptions = _resourceModel.GetResourceTypeOptions(resource.Id);
var resourceTypeDefinition = ResourceTypeFactory.CreateResourceTypeObject(resource.Type.DisplayName, _configuration);
if (resourceTypeDefinition == null)
{
return BadRequest($"No provider for: \"{resource.Type.DisplayName}\".");
}
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)}";
entryUrl = new Uri($"{hostUrl}{apiPath}/Blob/{resourceId}/{rawPath}");
}
return Ok($"{{ \"data\": {{ \"url\": \"{entryUrl}\" }} }}");
}
/// <summary> /// <summary>
/// This method uploads a given File /// This method uploads a given File
/// </summary> /// </summary>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment