Fixing destination file @streaming
This commit is contained in:
parent
5fd2670794
commit
1517b48741
11 changed files with 193 additions and 10 deletions
|
|
@ -180,6 +180,8 @@ namespace Yavsc.ApiControllers
|
|||
}
|
||||
return Ok(new { deleted=id });
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
67
src/Yavsc/ApiControllers/Blogspot/FileSystemStream.cs
Normal file
67
src/Yavsc/ApiControllers/Blogspot/FileSystemStream.cs
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Authorization;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.Data.Entity;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Yavsc.Attributes.Validation;
|
||||
using Yavsc.Helpers;
|
||||
using Yavsc.Models;
|
||||
using Yavsc.Models.Messaging;
|
||||
using Yavsc.Services;
|
||||
|
||||
namespace Yavsc.ApiControllers
|
||||
{
|
||||
[Authorize, Route("api/stream")]
|
||||
public partial class FileSystemStreamController : Controller
|
||||
{
|
||||
private readonly ILogger logger;
|
||||
private readonly ILiveProcessor liveProcessor;
|
||||
readonly ApplicationDbContext dbContext;
|
||||
|
||||
public FileSystemStreamController(ApplicationDbContext context, ILiveProcessor liveProcessor, ILoggerFactory loggerFactory)
|
||||
{
|
||||
this.dbContext = context;
|
||||
this.logger = loggerFactory.CreateLogger<FileSystemStreamController>();
|
||||
this.liveProcessor = liveProcessor;
|
||||
}
|
||||
public async Task<IActionResult> Put([ValidRemoteUserFilePath] string filename)
|
||||
{
|
||||
if (!HttpContext.WebSockets.IsWebSocketRequest)
|
||||
return HttpBadRequest("not a web socket");
|
||||
if (!HttpContext.User.Identity.IsAuthenticated)
|
||||
return new HttpUnauthorizedResult();
|
||||
var subdirs = filename.Split('/');
|
||||
var filePath = subdirs.Length > 1 ? string.Join("/", subdirs.Take(subdirs.Length-1)) : null;
|
||||
var shortFileName = subdirs[subdirs.Length-1];
|
||||
if (shortFileName.IsValidShortFileName())
|
||||
return HttpBadRequest("invalid file name");
|
||||
|
||||
|
||||
var userName = User.GetUserName();
|
||||
var hubContext = Microsoft.AspNet.SignalR.GlobalHost.ConnectionManager.GetHubContext<ChatHub>();
|
||||
string url = string.Format(
|
||||
"{0}/{1}/{2}",
|
||||
Startup.UserFilesOptions.RequestPath.ToUriComponent(),
|
||||
userName,
|
||||
filename
|
||||
);
|
||||
|
||||
hubContext.Clients.All.addPublicStream(new PublicStreamInfo
|
||||
{
|
||||
sender = userName,
|
||||
url = url,
|
||||
}, $"{userName} is starting a stream!");
|
||||
|
||||
string destDir = HttpContext.User.InitPostToFileSystem(filePath);
|
||||
logger.LogInformation($"Saving flow to {destDir}");
|
||||
var userId = User.GetUserId();
|
||||
var user = await dbContext.Users.FirstAsync(u => u.Id == userId);
|
||||
|
||||
await liveProcessor.AcceptStream(HttpContext, user, destDir, shortFileName);
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue