refactoring

This commit is contained in:
Paul Schneider 2025-02-14 00:20:35 +00:00
commit 8e8f4d3896
367 changed files with 217 additions and 364 deletions

View file

@ -0,0 +1,26 @@
using Microsoft.AspNetCore.Authorization;
namespace Yavsc.ViewModels.Auth
{
public class EditPermission : IAuthorizationRequirement
{
public EditPermission()
{
}
}
public class ReadPermission: IAuthorizationRequirement
{
public ReadPermission()
{
}
}
public class DeletePermission: IAuthorizationRequirement
{
public DeletePermission()
{
}
}
}

View file

@ -0,0 +1,25 @@
using System.IO;
using Microsoft.AspNetCore.Authorization;
using Yavsc.Models.Blog;
namespace Yavsc.ViewModels.Auth {
public class FileSpotInfo : IAuthorizationRequirement
{
public DirectoryInfo PathInfo { get; private set; }
public FileSpotInfo(string path, BlogPost b) {
PathInfo = new DirectoryInfo(path);
AuthorId = b.AuthorId;
BlogEntryId = b.Id;
}
public string AuthorId { get; private set; }
public long BlogEntryId { get; private set; }
}
}

View file

@ -0,0 +1,9 @@
using Microsoft.AspNetCore.Authorization;
namespace Yavsc.ViewModels.Auth
{
public class ModerationRequirement : IAuthorizationRequirement
{
public ModerationRequirement() {}
}
}

View file

@ -0,0 +1,8 @@
using Microsoft.AspNetCore.Authorization;
namespace Yavsc.ViewModels.Auth
{
public class PrivateChatEntryRequirement : IAuthorizationRequirement
{
}
}

View file

@ -0,0 +1,12 @@
using Microsoft.Extensions.FileProviders;
namespace Yavsc.ViewModels.Auth
{
public class ViewFileContext
{
public string UserName { get; set; }
public IFileInfo File { get; set; }
public string Path { get; set; }
}
}

View file

@ -0,0 +1,11 @@
using Microsoft.AspNetCore.Authorization;
namespace Yavsc.ViewModels.Auth
{
public class ViewRequirement : IAuthorizationRequirement
{
public ViewRequirement()
{
}
}
}

View file

@ -0,0 +1,34 @@
//
// ChatHub.cs
//
// Author:
// Paul Schneider <paul@pschneider.fr>
//
// Copyright (c) 2016-2019 GNU GPL
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System.Collections.Generic;
namespace Yavsc
{
public class ChatRoomInfo
{
public string Name;
public List<string> Users = new List<string>();
public List<string> Ops = new List<string>();
public List<string> Hops = new List<string>();
public string Topic;
}
}

View file

@ -0,0 +1,38 @@
using System.Linq;
using Yavsc.Models.Workflow;
namespace Yavsc.ViewModels.FrontOffice
{
public partial class PerformerProfileViewModel
{
public string UserName { get; set; }
public string PerformerId { get; set; }
public bool Active { get; set; }
public bool AcceptNotifications { get; set; }
public bool AcceptPublicContact { get; set; }
public UserActivity Context { get; set; }
public object Settings { get; set; }
public UserActivity[] Extra { get; set; }
public string WebSite { get; set; }
public string SettingsClassName { get; set; }
public PerformerProfileViewModel(PerformerProfile profile, string activityCode, object settings)
{
UserName = profile.Performer.UserName;
PerformerId = profile.PerformerId;
Active = profile.Active;
AcceptNotifications = profile.AcceptNotifications;
AcceptPublicContact = profile.AcceptPublicContact;
Context = profile.Activity.FirstOrDefault(a => a.DoesCode == activityCode);
SettingsClassName = Context.Does.SettingsClassName;
Settings = settings;
WebSite = profile.WebSite;
Extra = profile.Activity.Where(a => a.DoesCode != activityCode).ToArray();
}
}
}

View file

@ -0,0 +1,92 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Net.WebSockets;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Yavsc.Helpers;
using Yavsc.Models;
using Yavsc.Models.FileSystem;
namespace Yavsc.ViewModels.Streaming
{
public class LiveCastClient
{
public string UserName { get; set; }
public WebSocket Socket { get; set; }
}
public class LiveEntryViewModel
{
public string UserName { get; set; }
public string FlowId { get; set; }
}
public class LiveCastHandler : IDisposable
{
public WebSocket Socket { get; set; }
public ConcurrentDictionary<string, WebSocket> Listeners { get; set; } = new ConcurrentDictionary<string, WebSocket>();
public CancellationTokenSource TokenSource { get; set; } = new CancellationTokenSource();
public void Dispose()
{
}
public async Task<FileRecievedInfo> ReceiveUserFile(ApplicationUser user, ILogger logger, string root, Queue<ArraySegment<byte>> queue, string destFileName, Func<bool> isEndOfInput)
{
// TODO lock user's disk usage for this scope,
// this process is not safe at concurrent access.
long usage = user.DiskUsage;
var item = new FileRecievedInfo
{
FileName = AbstractFileSystemHelpers.FilterFileName(destFileName),
DestDir = root
};
var fi = new FileInfo(Path.Combine(root, item.FileName));
if (fi.Exists)
{
item.Overriden = true;
usage -= fi.Length;
}
logger.LogInformation("Opening the file");
using (var dest = fi.Open(FileMode.Create, FileAccess.Write, FileShare.Read))
{
logger.LogInformation("Appening to file");
while (!isEndOfInput() || queue.Count > 0)
{
if (queue.Count > 0)
{
var buffer = queue.Dequeue();
logger.LogInformation($"writing {buffer.Count} bytes...");
await dest.WriteAsync(buffer.Array, buffer.Offset, buffer.Count);
logger.LogInformation($"done.");
usage += buffer.Count;
}
if (usage >= user.DiskQuota) break;
if (queue.Count == 0 && !isEndOfInput())
{
await Task.Delay(100);
}
}
user.DiskUsage = usage;
dest.Close();
}
if (usage >= user.DiskQuota)
{
item.QuotaOffensed = true;
}
user.DiskUsage = usage;
return item;
}
}
}