refacts
This commit is contained in:
parent
1bd9c00cd8
commit
bcadc733bb
6 changed files with 15 additions and 18 deletions
2
Makefile
2
Makefile
|
|
@ -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
|
|
||||||
|
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,
|
sender = userName,
|
||||||
url = url,
|
url = url,
|
||||||
}, $"{userName} is starting a stream!");
|
}, $"{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);
|
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…
Add table
Add a link
Reference in a new issue