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
all:
@dotnet build --nologo 2>/dev/null |grep error
dotnet build --nologo
clean:
dotnet clean

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

@ -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();
}

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

@ -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; }
}

@ -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);

Loading…