public async Task <IActionResult> GetSendFileDownloadData(string encodedSendId, string fileId, [FromBody] SendAccessRequestModel model) { var sendId = new Guid(CoreHelpers.Base64UrlDecode(encodedSendId)); var send = await _sendRepository.GetByIdAsync(sendId); if (send == null) { throw new BadRequestException("Could not locate send"); } var(url, passwordRequired, passwordInvalid) = await _sendService.GetSendFileDownloadUrlAsync(send, fileId, model.Password); if (passwordRequired) { return(new UnauthorizedResult()); } if (passwordInvalid) { await Task.Delay(2000); throw new BadRequestException("Invalid password."); } if (send == null) { throw new NotFoundException(); } return(new ObjectResult(new SendFileDownloadDataResponseModel() { Id = fileId, Url = url, })); }
public async Task <IActionResult> GetSendFileDownloadData(string encodedSendId, string fileId, [FromBody] SendAccessRequestModel model) { // Uncomment whenever we want to require the `send-id` header //if (!_currentContext.HttpContext.Request.Headers.ContainsKey("Send-Id") || // _currentContext.HttpContext.Request.Headers["Send-Id"] != encodedSendId) //{ // throw new BadRequestException("Invalid Send-Id header."); //} var sendId = new Guid(CoreHelpers.Base64UrlDecode(encodedSendId)); var send = await _sendRepository.GetByIdAsync(sendId); if (send == null) { throw new BadRequestException("Could not locate send"); } var(url, passwordRequired, passwordInvalid) = await _sendService.GetSendFileDownloadUrlAsync(send, fileId, model.Password); if (passwordRequired) { return(new UnauthorizedResult()); } if (passwordInvalid) { await Task.Delay(2000); throw new BadRequestException("Invalid password."); } if (send == null) { throw new NotFoundException(); } return(new ObjectResult(new SendFileDownloadDataResponseModel() { Id = fileId, Url = url, })); }