diff --git a/Makefile b/Makefile index 988f8c56..bde8014f 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ FRAMEWORK=net8.0 DESTDIR=/tmp/yavsc all: - @dotnet build --nologo 2>/dev/null |grep error + dotnet build --nologo clean: dotnet clean diff --git a/src/Api/Controllers/Blogspot/FileSystemApiController.cs b/src/Api/Controllers/Blogspot/FileSystemApiController.cs index c17ebd58..f91b9e6e 100644 --- a/src/Api/Controllers/Blogspot/FileSystemApiController.cs +++ b/src/Api/Controllers/Blogspot/FileSystemApiController.cs @@ -57,7 +57,7 @@ namespace Yavsc.ApiControllers List received = new List(); InvalidPathException pathex = null; try { - destDir = User.InitPostToFileSystem(subdir); + destDir = User.EnsureDestinationDirectory(subdir); } catch (InvalidPathException ex) { pathex = ex; } diff --git a/src/Api/Controllers/Blogspot/FileSystemStream.cs b/src/Api/Controllers/Blogspot/FileSystemStream.cs index e6b3c159..ee6aed0c 100644 --- a/src/Api/Controllers/Blogspot/FileSystemStream.cs +++ b/src/Api/Controllers/Blogspot/FileSystemStream.cs @@ -35,8 +35,6 @@ namespace Yavsc.ApiControllers logger.LogInformation("Put : " + filename); if (!HttpContext.WebSockets.IsWebSocketRequest) return BadRequest("not a web socket"); - if (!HttpContext.User.Identity.IsAuthenticated) - return new UnauthorizedResult(); var subdirs = filename.Split('/'); var filePath = subdirs.Length > 1 ? string.Join("/", subdirs.Take(subdirs.Length-1)) : null; var shortFileName = subdirs[subdirs.Length-1]; @@ -55,17 +53,18 @@ namespace Yavsc.ApiControllers filename ); - hubContext.Clients.All.SendAsync("addPublicStream", new PublicStreamInfo + + string destDir = HttpContext.User.EnsureDestinationDirectory(filePath); + logger.LogInformation($"Saving flow to {destDir}"); + var userId = User.GetUserId(); + var user = await dbContext.Users.FirstAsync(u => u.Id == userId); + logger.LogInformation("Accepting stream ..."); + _ = hubContext.Clients.All.SendAsync("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); - logger.LogInformation("Accepting stream ..."); await liveProcessor.AcceptStream(HttpContext, user, destDir, shortFileName); return Ok(); } diff --git a/src/Api/Controllers/accounting/AccountController.cs b/src/Api/Controllers/accounting/AccountController.cs index 01ff61be..617916af 100644 --- a/src/Api/Controllers/accounting/AccountController.cs +++ b/src/Api/Controllers/accounting/AccountController.cs @@ -69,7 +69,6 @@ namespace Yavsc.WebApi.Controllers [HttpPost("~/api/setavatar")] public async Task SetAvatar() { - var root = User.InitPostToFileSystem(null); var user = await GetUserData(User.GetUserId()); if (Request.Form.Files.Count!=1) return new BadRequestResult(); diff --git a/src/Api/Controllers/Blogspot/MoveFileQuery.cs b/src/Yavsc.Abstract/FileSystem/MoveFileQuery.cs similarity index 73% rename from src/Api/Controllers/Blogspot/MoveFileQuery.cs rename to src/Yavsc.Abstract/FileSystem/MoveFileQuery.cs index a62f79c9..c0f97050 100644 --- a/src/Api/Controllers/Blogspot/MoveFileQuery.cs +++ b/src/Yavsc.Abstract/FileSystem/MoveFileQuery.cs @@ -1,3 +1,4 @@ +using System.ComponentModel.DataAnnotations; using Yavsc.Attributes.Validation; namespace Yavsc.Models.FileSystem { @@ -5,10 +6,10 @@ namespace Yavsc.Models.FileSystem public class MoveFileQuery { [ValidRemoteUserFilePath] - [YaStringLength(1, 512)] + [StringLength(512)] public required string Id { get; set; } - [YaStringLength(0, 512)] + [StringLength(512)] [ValidRemoteUserFilePath] public required string To { get; set; } } diff --git a/src/Yavsc.Server/Helpers/FileSystemHelpers.cs b/src/Yavsc.Server/Helpers/FileSystemHelpers.cs index 9c8ab5fc..d3929a50 100644 --- a/src/Yavsc.Server/Helpers/FileSystemHelpers.cs +++ b/src/Yavsc.Server/Helpers/FileSystemHelpers.cs @@ -47,14 +47,13 @@ namespace Yavsc.Server.Helpers return $"/{Config.SiteSetup.Avatars}/{user.UserName}.png"; } - public static string InitPostToFileSystem( + public static string EnsureDestinationDirectory( this ClaimsPrincipal user, string subpath) { var root = Path.Combine(AbstractFileSystemHelpers.UserFilesDirName, user.Identity.Name); - var diRoot = new DirectoryInfo(root); - if (!diRoot.Exists) diRoot.Create(); - if (!string.IsNullOrWhiteSpace(subpath)) { + if (!string.IsNullOrWhiteSpace(subpath)) + { if (!subpath.IsValidYavscPath()) { throw new InvalidPathException(); @@ -230,7 +229,6 @@ namespace Yavsc.Server.Helpers var item = new FileReceivedInfo (Config.AvatarsOptions.RequestPath.ToUriComponent(), user.UserName + ".png"); - using (var org = formFile.OpenReadStream()) { using Image image = Image.Load(org);