mirror of
https://github.com/fergalmoran/podnoms.git
synced 2025-12-27 19:58:16 +00:00
Fix 404 on audio upload
This commit is contained in:
@@ -7,6 +7,7 @@ using AutoMapper;
|
||||
using Hangfire;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
using Microsoft.AspNetCore.WebUtilities;
|
||||
@@ -17,6 +18,7 @@ using PodNoms.Api.Models;
|
||||
using PodNoms.Api.Models.ViewModels;
|
||||
using PodNoms.Api.Persistence;
|
||||
using PodNoms.Api.Providers;
|
||||
using PodNoms.Api.Services.Auth;
|
||||
using PodNoms.Api.Services.Processor;
|
||||
using PodNoms.Api.Services.Storage;
|
||||
using PodNoms.Api.Utils;
|
||||
@@ -24,7 +26,7 @@ using PodNoms.Api.Utils;
|
||||
namespace PodNoms.Api.Controllers {
|
||||
[Authorize]
|
||||
[Route("/podcast/{slug}/audioupload")]
|
||||
public class AudioUploadController : Controller {
|
||||
public class AudioUploadController : BaseAuthController {
|
||||
private readonly IPodcastRepository _podcastRepository;
|
||||
private readonly IEntryRepository _entryRepository;
|
||||
private IUnitOfWork _unitOfWork;
|
||||
@@ -35,7 +37,8 @@ namespace PodNoms.Api.Controllers {
|
||||
|
||||
public AudioUploadController(IPodcastRepository podcastRepository, IEntryRepository entryRepository, IUnitOfWork unitOfWork,
|
||||
IOptions<AudioFileStorageSettings> settings, IOptions<StorageSettings> storageSettings,
|
||||
ILoggerFactory loggerFactory, IMapper mapper) {
|
||||
ILoggerFactory loggerFactory, IMapper mapper,
|
||||
UserManager<ApplicationUser> userManager, IHttpContextAccessor contextAccessor) : base(contextAccessor, userManager) {
|
||||
this._mapper = mapper;
|
||||
this._audioFileStorageSettings = settings.Value;
|
||||
this._storageSettings = storageSettings.Value;
|
||||
@@ -52,28 +55,24 @@ namespace PodNoms.Api.Controllers {
|
||||
if (file.Length > _audioFileStorageSettings.MaxUploadFileSize) return BadRequest("Maximum file size exceeded");
|
||||
if (!_audioFileStorageSettings.IsSupported(file.FileName)) return BadRequest("Invalid file type");
|
||||
|
||||
var email = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Email)?.Value;
|
||||
if (!string.IsNullOrEmpty(email)) {
|
||||
var podcast = await _podcastRepository.GetAsync(email, slug);
|
||||
if (podcast == null)
|
||||
return NotFound();
|
||||
var podcast = await _podcastRepository.GetAsync(_userId, slug);
|
||||
if (podcast == null)
|
||||
return NotFound();
|
||||
|
||||
var entry = new PodcastEntry {
|
||||
Title = Path.GetFileName(Path.GetFileNameWithoutExtension(file.FileName)),
|
||||
ImageUrl = $"{_storageSettings.CdnUrl}static/images/default-entry.png",
|
||||
Processed = false,
|
||||
ProcessingStatus = ProcessingStatus.Uploading,
|
||||
Podcast = podcast
|
||||
};
|
||||
var entry = new PodcastEntry {
|
||||
Title = Path.GetFileName(Path.GetFileNameWithoutExtension(file.FileName)),
|
||||
ImageUrl = $"{_storageSettings.CdnUrl}static/images/default-entry.png",
|
||||
Processed = false,
|
||||
ProcessingStatus = ProcessingStatus.Uploading,
|
||||
Podcast = podcast
|
||||
};
|
||||
|
||||
var localFile = await CachedFormFileStorage.CacheItem(file);
|
||||
await _entryRepository.AddOrUpdateAsync(entry);
|
||||
await _unitOfWork.CompleteAsync();
|
||||
var localFile = await CachedFormFileStorage.CacheItem(file);
|
||||
await _entryRepository.AddOrUpdateAsync(entry);
|
||||
await _unitOfWork.CompleteAsync();
|
||||
|
||||
BackgroundJob.Enqueue<IAudioUploadProcessService>(service => service.UploadAudio(entry.Id, localFile));
|
||||
return new OkObjectResult(_mapper.Map<PodcastEntry, PodcastEntryViewModel>(entry));
|
||||
}
|
||||
return NotFound();
|
||||
BackgroundJob.Enqueue<IAudioUploadProcessService>(service => service.UploadAudio(entry.Id, localFile));
|
||||
return new OkObjectResult(_mapper.Map<PodcastEntry, PodcastEntryViewModel>(entry));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user