refactoring
This commit is contained in:
parent
49826eae4a
commit
8e8f4d3896
367 changed files with 217 additions and 364 deletions
26
src/Yavsc.Server/ViewModels/Auth/EditRequirement.cs
Normal file
26
src/Yavsc.Server/ViewModels/Auth/EditRequirement.cs
Normal 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()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
25
src/Yavsc.Server/ViewModels/Auth/FileSpotInfo.cs
Normal file
25
src/Yavsc.Server/ViewModels/Auth/FileSpotInfo.cs
Normal 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; }
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
namespace Yavsc.ViewModels.Auth
|
||||
{
|
||||
public class ModerationRequirement : IAuthorizationRequirement
|
||||
{
|
||||
public ModerationRequirement() {}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
namespace Yavsc.ViewModels.Auth
|
||||
{
|
||||
public class PrivateChatEntryRequirement : IAuthorizationRequirement
|
||||
{
|
||||
}
|
||||
}
|
||||
12
src/Yavsc.Server/ViewModels/Auth/ViewFileContext.cs
Normal file
12
src/Yavsc.Server/ViewModels/Auth/ViewFileContext.cs
Normal 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; }
|
||||
}
|
||||
}
|
||||
11
src/Yavsc.Server/ViewModels/Auth/ViewRequirement.cs
Normal file
11
src/Yavsc.Server/ViewModels/Auth/ViewRequirement.cs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
namespace Yavsc.ViewModels.Auth
|
||||
{
|
||||
public class ViewRequirement : IAuthorizationRequirement
|
||||
{
|
||||
public ViewRequirement()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
34
src/Yavsc.Server/ViewModels/Chat/ChatRoomInfo.cs
Normal file
34
src/Yavsc.Server/ViewModels/Chat/ChatRoomInfo.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
92
src/Yavsc.Server/ViewModels/LiveCastHandler.cs
Normal file
92
src/Yavsc.Server/ViewModels/LiveCastHandler.cs
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue