main
Paul Schneider 2 weeks ago
parent 5334646c1b
commit 6936d98840
6 changed files with 15 additions and 18 deletions

@ -4,7 +4,7 @@ FRAMEWORK=net8.0
DESTDIR=/tmp/yavsc DESTDIR=/tmp/yavsc
all: all:
@dotnet build --nologo 2>/dev/null |grep error dotnet build --nologo
clean: clean:
dotnet clean dotnet clean

@ -57,7 +57,7 @@ namespace Yavsc.ApiControllers
List<FileReceivedInfo> received = new List<FileReceivedInfo>(); List<FileReceivedInfo> received = new List<FileReceivedInfo>();
InvalidPathException pathex = null; InvalidPathException pathex = null;
try { try {
destDir = User.InitPostToFileSystem(subdir); destDir = User.EnsureDestinationDirectory(subdir);
} catch (InvalidPathException ex) { } catch (InvalidPathException ex) {
pathex = ex; pathex = ex;
} }

@ -35,8 +35,6 @@ namespace Yavsc.ApiControllers
logger.LogInformation("Put : " + filename); logger.LogInformation("Put : " + filename);
if (!HttpContext.WebSockets.IsWebSocketRequest) if (!HttpContext.WebSockets.IsWebSocketRequest)
return BadRequest("not a web socket"); return BadRequest("not a web socket");
if (!HttpContext.User.Identity.IsAuthenticated)
return new UnauthorizedResult();
var subdirs = filename.Split('/'); var subdirs = filename.Split('/');
var filePath = subdirs.Length > 1 ? string.Join("/", subdirs.Take(subdirs.Length-1)) : null; var filePath = subdirs.Length > 1 ? string.Join("/", subdirs.Take(subdirs.Length-1)) : null;
var shortFileName = subdirs[subdirs.Length-1]; var shortFileName = subdirs[subdirs.Length-1];
@ -55,17 +53,18 @@ namespace Yavsc.ApiControllers
filename filename
); );
hubContext.Clients.All.SendAsync("addPublicStream", new PublicStreamInfo
{
sender = userName,
url = url,
}, $"{userName} is starting a stream!");
string destDir = HttpContext.User.InitPostToFileSystem(filePath); string destDir = HttpContext.User.EnsureDestinationDirectory(filePath);
logger.LogInformation($"Saving flow to {destDir}"); logger.LogInformation($"Saving flow to {destDir}");
var userId = User.GetUserId(); var userId = User.GetUserId();
var user = await dbContext.Users.FirstAsync(u => u.Id == userId); var user = await dbContext.Users.FirstAsync(u => u.Id == userId);
logger.LogInformation("Accepting stream ..."); logger.LogInformation("Accepting stream ...");
_ = hubContext.Clients.All.SendAsync("addPublicStream", new PublicStreamInfo
{
sender = userName,
url = url,
}, $"{userName} is starting a stream!");
await liveProcessor.AcceptStream(HttpContext, user, destDir, shortFileName); await liveProcessor.AcceptStream(HttpContext, user, destDir, shortFileName);
return Ok(); return Ok();
} }

@ -69,7 +69,6 @@ namespace Yavsc.WebApi.Controllers
[HttpPost("~/api/setavatar")] [HttpPost("~/api/setavatar")]
public async Task<IActionResult> SetAvatar() public async Task<IActionResult> SetAvatar()
{ {
var root = User.InitPostToFileSystem(null);
var user = await GetUserData(User.GetUserId()); var user = await GetUserData(User.GetUserId());
if (Request.Form.Files.Count!=1) if (Request.Form.Files.Count!=1)
return new BadRequestResult(); return new BadRequestResult();

@ -1,3 +1,4 @@
using System.ComponentModel.DataAnnotations;
using Yavsc.Attributes.Validation; using Yavsc.Attributes.Validation;
namespace Yavsc.Models.FileSystem namespace Yavsc.Models.FileSystem
{ {
@ -5,10 +6,10 @@ namespace Yavsc.Models.FileSystem
public class MoveFileQuery public class MoveFileQuery
{ {
[ValidRemoteUserFilePath] [ValidRemoteUserFilePath]
[YaStringLength(1, 512)] [StringLength(512)]
public required string Id { get; set; } public required string Id { get; set; }
[YaStringLength(0, 512)] [StringLength(512)]
[ValidRemoteUserFilePath] [ValidRemoteUserFilePath]
public required string To { get; set; } public required string To { get; set; }
} }

@ -47,14 +47,13 @@ namespace Yavsc.Server.Helpers
return $"/{Config.SiteSetup.Avatars}/{user.UserName}.png"; return $"/{Config.SiteSetup.Avatars}/{user.UserName}.png";
} }
public static string InitPostToFileSystem( public static string EnsureDestinationDirectory(
this ClaimsPrincipal user, this ClaimsPrincipal user,
string subpath) string subpath)
{ {
var root = Path.Combine(AbstractFileSystemHelpers.UserFilesDirName, user.Identity.Name); var root = Path.Combine(AbstractFileSystemHelpers.UserFilesDirName, user.Identity.Name);
var diRoot = new DirectoryInfo(root); if (!string.IsNullOrWhiteSpace(subpath))
if (!diRoot.Exists) diRoot.Create(); {
if (!string.IsNullOrWhiteSpace(subpath)) {
if (!subpath.IsValidYavscPath()) if (!subpath.IsValidYavscPath())
{ {
throw new InvalidPathException(); throw new InvalidPathException();
@ -230,7 +229,6 @@ namespace Yavsc.Server.Helpers
var item = new FileReceivedInfo var item = new FileReceivedInfo
(Config.AvatarsOptions.RequestPath.ToUriComponent(), (Config.AvatarsOptions.RequestPath.ToUriComponent(),
user.UserName + ".png"); user.UserName + ".png");
using (var org = formFile.OpenReadStream()) using (var org = formFile.OpenReadStream())
{ {
using Image image = Image.Load(org); using Image image = Image.Load(org);

Loading…