Code cleanup
This commit is contained in:
7
.vscode/settings.json
vendored
7
.vscode/settings.json
vendored
@ -17,5 +17,10 @@
|
||||
"Newtonsoft",
|
||||
"Npgsql",
|
||||
"Yavsc"
|
||||
]
|
||||
],
|
||||
"cSpell.dictionaries": [
|
||||
"fr"
|
||||
],
|
||||
"cSpell.reportUnknownWords": true,
|
||||
"cSpell.language": "fr,fr-FR,en,en-GB"
|
||||
}
|
||||
|
10
SECURITY.md
10
SECURITY.md
@ -1,10 +0,0 @@
|
||||
# Security Policy
|
||||
|
||||
## Supported Versions
|
||||
|
||||
|
||||
| Version | Supported |
|
||||
| ------- | ------------------ |
|
||||
| 1.0.6 | :x: |
|
||||
|
||||
(https://pschneider.fr:84)
|
@ -54,7 +54,7 @@ namespace Yavsc.ApiControllers
|
||||
{
|
||||
if (!ModelState.IsValid) return new BadRequestObjectResult(ModelState);
|
||||
string destDir = null;
|
||||
List<FileRecievedInfo> received = new List<FileRecievedInfo>();
|
||||
List<FileReceivedInfo> received = new List<FileReceivedInfo>();
|
||||
InvalidPathException pathex = null;
|
||||
try {
|
||||
destDir = User.InitPostToFileSystem(subdir);
|
||||
@ -80,7 +80,7 @@ namespace Yavsc.ApiControllers
|
||||
dbContext.SaveChanges(User.GetUserId());
|
||||
received.Add(item);
|
||||
_logger.LogInformation($"Received '{item.FileName}'.");
|
||||
if (item.QuotaOffensed)
|
||||
if (item.QuotaOffense)
|
||||
break;
|
||||
i++;
|
||||
};
|
||||
|
5
src/Directory.Build.props
Normal file
5
src/Directory.Build.props
Normal file
@ -0,0 +1,5 @@
|
||||
<Project >
|
||||
<PropertyGroup>
|
||||
<Version>1.0.8</Version>
|
||||
</PropertyGroup>
|
||||
</Project>
|
@ -1,14 +1,14 @@
|
||||
namespace Yavsc.Abstract.FileSystem
|
||||
{
|
||||
public interface IFileRecievedInfo
|
||||
public interface IFileReceivedInfo
|
||||
{
|
||||
|
||||
string DestDir { get; set; }
|
||||
|
||||
string FileName { get; set; }
|
||||
|
||||
bool Overriden { get; set; }
|
||||
bool Overridden { get; set; }
|
||||
|
||||
bool QuotaOffensed { get; set; }
|
||||
bool QuotaOffense { get; set; }
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<TargetFrameworks>net8.0</TargetFrameworks>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
@ -9,23 +9,23 @@ namespace Yavsc;
|
||||
|
||||
public static class Config
|
||||
{
|
||||
public static string Authority { get; set; }
|
||||
public static string? Authority { get; set; }
|
||||
|
||||
public static IConfigurationRoot? GoogleWebClientConfiguration { get; set; }
|
||||
public static GoogleServiceAccount? GServiceAccount { get; set; }
|
||||
|
||||
public static SiteSettings SiteSetup { get; set; }
|
||||
public static FileServerOptions UserFilesOptions { get; set; }
|
||||
public static FileServerOptions GitOptions { get; set; }
|
||||
public static string AvatarsDirName { set; get; }
|
||||
public static string GitDirName { set; get; }
|
||||
public static SiteSettings SiteSetup { get; set; } = new SiteSettings();
|
||||
public static FileServerOptions? UserFilesOptions { get; set; }
|
||||
public static FileServerOptions? GitOptions { get; set; }
|
||||
public static string AvatarsDirName { set; get; } = "Avatars";
|
||||
public static string GitDirName { set; get; } = "Git";
|
||||
|
||||
public static GoogleAuthSettings GoogleSettings { get; set; }
|
||||
public static SmtpSettings SmtpSetup { get; set; }
|
||||
public static string Temp { get; set; }
|
||||
public static FileServerOptions AvatarsOptions { get; set; }
|
||||
public static string UserBillsDirName { set; get; }
|
||||
public static string UserFilesDirName { set; get; }
|
||||
public static GoogleAuthSettings? GoogleSettings { get; set; }
|
||||
public static SmtpSettings? SmtpSetup { get; set; }
|
||||
public static string? Temp { get; set; }
|
||||
public static FileServerOptions? AvatarsOptions { get; set; }
|
||||
public static string UserBillsDirName { set; get; } = "Bills";
|
||||
public static string UserFilesDirName { set; get; } = "Files";
|
||||
|
||||
|
||||
|
||||
@ -89,5 +89,5 @@ public static class Config
|
||||
},
|
||||
};
|
||||
|
||||
public static PayPalSettings PayPalSettings { get; set; }
|
||||
public static PayPalSettings? PayPalSettings { get; set; }
|
||||
}
|
||||
|
@ -25,22 +25,19 @@ namespace Yavsc.Server.Helpers
|
||||
}
|
||||
}
|
||||
}
|
||||
public static FileRecievedInfo ReceiveProSignature(this ClaimsPrincipal user, string billingCode, long estimateId, IFormFile formFile, string signtype)
|
||||
public static FileReceivedInfo ReceiveProSignature(this ClaimsPrincipal user, string billingCode, long estimateId, IFormFile formFile, string signType)
|
||||
{
|
||||
var item = new FileRecievedInfo
|
||||
{
|
||||
FileName = AbstractFileSystemHelpers.SignFileNameFormat("pro", billingCode, estimateId)
|
||||
};
|
||||
var item = new FileReceivedInfo(
|
||||
Config.SiteSetup.Bills,
|
||||
AbstractFileSystemHelpers.SignFileNameFormat("pro", billingCode, estimateId));
|
||||
|
||||
var destFileName = Path.Combine(Config.SiteSetup.Bills, item.FileName);
|
||||
|
||||
var fi = new FileInfo(destFileName);
|
||||
if (fi.Exists) item.Overriden = true;
|
||||
var fi = new FileInfo(item.FullName);
|
||||
if (fi.Exists) item.Overridden = true;
|
||||
|
||||
using (var org = formFile.OpenReadStream())
|
||||
{
|
||||
using Image image = Image.Load(org);
|
||||
image.Save(destFileName);
|
||||
image.Save(fi.FullName);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
@ -170,26 +167,23 @@ namespace Yavsc.Server.Helpers
|
||||
{
|
||||
user.DiskQuota += quota;
|
||||
}
|
||||
public static FileRecievedInfo ReceiveUserFile(this ApplicationUser user, string root, IFormFile f, string destFileName = null)
|
||||
public static FileReceivedInfo ReceiveUserFile(this ApplicationUser user, string root, IFormFile f, string destFileName = null)
|
||||
{
|
||||
return ReceiveUserFile(user, root, f.OpenReadStream(), destFileName ?? ParseFileNameFromDisposition(f.ContentDisposition), f.ContentType, CancellationToken.None);
|
||||
}
|
||||
|
||||
public static FileRecievedInfo ReceiveUserFile(this ApplicationUser user, string root, Stream inputStream, string destFileName, string contentType, CancellationToken token)
|
||||
public static FileReceivedInfo ReceiveUserFile(this ApplicationUser user, string root, Stream inputStream, string destFileName, string contentType, CancellationToken token)
|
||||
{
|
||||
// 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 item = new FileReceivedInfo
|
||||
(root, AbstractFileSystemHelpers.FilterFileName(destFileName));
|
||||
var fi = new FileInfo(Path.Combine(root, item.FileName));
|
||||
if (fi.Exists)
|
||||
{
|
||||
item.Overriden = true;
|
||||
item.Overridden = true;
|
||||
usage -= fi.Length;
|
||||
}
|
||||
using (var dest = fi.OpenWrite())
|
||||
@ -211,7 +205,7 @@ namespace Yavsc.Server.Helpers
|
||||
}
|
||||
}
|
||||
if (usage >= user.DiskQuota) {
|
||||
item.QuotaOffensed = true;
|
||||
item.QuotaOffense = true;
|
||||
}
|
||||
user.DiskUsage = usage;
|
||||
return item;
|
||||
@ -231,12 +225,12 @@ namespace Yavsc.Server.Helpers
|
||||
|
||||
}
|
||||
|
||||
public static FileRecievedInfo ReceiveAvatar(this ApplicationUser user, IFormFile formFile)
|
||||
public static FileReceivedInfo ReceiveAvatar(this ApplicationUser user, IFormFile formFile)
|
||||
{
|
||||
var item = new FileRecievedInfo
|
||||
{
|
||||
FileName = user.UserName + ".png"
|
||||
};
|
||||
var item = new FileReceivedInfo
|
||||
(Config.AvatarsOptions.RequestPath.ToUriComponent(),
|
||||
user.UserName + ".png");
|
||||
|
||||
using (var org = formFile.OpenReadStream())
|
||||
{
|
||||
using Image image = Image.Load(org);
|
||||
@ -247,14 +241,12 @@ namespace Yavsc.Server.Helpers
|
||||
image.Mutate(x=>x.Resize(32,32));
|
||||
image.Save(Path.Combine(Config.SiteSetup.Avatars,user.UserName + ".xs.png"));
|
||||
}
|
||||
item.DestDir = Config.AvatarsOptions.RequestPath.ToUriComponent();
|
||||
user.Avatar = $"{item.DestDir}/{item.FileName}";
|
||||
return item;
|
||||
}
|
||||
|
||||
public static string GetFileUrl (this LiveFlow flow)
|
||||
{
|
||||
if (flow.DifferedFileName==null) return null;
|
||||
// no server-side backup for this stream
|
||||
return $"{Config.UserFilesOptions.RequestPath}/{flow.Owner.UserName}/live/"+GetFileName(flow);
|
||||
}
|
||||
|
@ -25,18 +25,30 @@ using Yavsc.Abstract.FileSystem;
|
||||
|
||||
namespace Yavsc.Models.FileSystem
|
||||
{
|
||||
public class FileRecievedInfo : IFileRecievedInfo
|
||||
public class FileReceivedInfo : IFileReceivedInfo
|
||||
{
|
||||
public FileRecievedInfo()
|
||||
public FileReceivedInfo(string destDir, string fileName, bool quotaOffense=false)
|
||||
{
|
||||
QuotaOffensed = Overriden = false;
|
||||
DestDir = FileName = null;
|
||||
this.DestDir = destDir;
|
||||
this.FileName = fileName;
|
||||
this.QuotaOffense = quotaOffense;
|
||||
}
|
||||
public static FileReceivedInfo FromPath(string filePath)
|
||||
{
|
||||
FileInfo fi = new FileInfo(filePath);
|
||||
return new FileReceivedInfo(
|
||||
fi.Directory.FullName,
|
||||
fi.Name
|
||||
);
|
||||
}
|
||||
|
||||
public string DestDir { get; set; }
|
||||
|
||||
public string FileName { get; set; }
|
||||
public bool Overriden { get; set; }
|
||||
public bool Overridden { get; set; }
|
||||
|
||||
public bool QuotaOffense { get; set; }
|
||||
public string FullName { get => Path.Combine(DestDir, FileName); }
|
||||
|
||||
public bool QuotaOffensed { get; set; }
|
||||
}
|
||||
}
|
@ -1,51 +1,61 @@
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using Yavsc.Models.Relationship;
|
||||
|
||||
namespace Yavsc
|
||||
{
|
||||
public class SiteSettings
|
||||
{
|
||||
public string Title { get; set; }
|
||||
public string Slogan { get; set; }
|
||||
public string Title { get; set; } = "Yavsc";
|
||||
public string Slogan { get; set; } = "";
|
||||
|
||||
public string StyleSheet { get; set; }
|
||||
public string FavIcon { get; set; }
|
||||
public string Logo { get; set; }
|
||||
public string StyleSheet { get; set; } = "site.css";
|
||||
public string FavIcon { get; set; } = "favicon.ico";
|
||||
public string Logo { get; set; } = "logo.png";
|
||||
/// <summary>
|
||||
/// Conceptually,
|
||||
/// This authorisation server only has this present site as unique audience.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string Audience { get; set; }
|
||||
public string Audience { get; set; } = "lua.pschneider.fr";
|
||||
/// <summary>
|
||||
/// it's a very small company, with one domaine name only,
|
||||
/// so let it be the same as in the Audience field.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string Authority { get; set; }
|
||||
public string Authority { get; set; } = "lua.pschneider.fr";
|
||||
/// <summary>
|
||||
/// Owner's email
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public StaticContact Owner { get; set; }
|
||||
public StaticContact Owner { get; set; } = new StaticContact
|
||||
{
|
||||
EMail = "root@lua.pschneider.fr",
|
||||
Name = "Root"
|
||||
} ;
|
||||
|
||||
/// <summary>
|
||||
/// Administrator's email
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public StaticContact Admin { get; set; }
|
||||
public StaticContact Admin { get; set; } = new StaticContact
|
||||
{
|
||||
EMail = "root@lua.pschneider.fr",
|
||||
Name = "Root"
|
||||
} ;
|
||||
|
||||
public string DataDir { get; set; }
|
||||
public string DataDir { get; set; } = "data";
|
||||
public string Avatars { get; set; } = "avatars";
|
||||
public long Quota { get; set; }
|
||||
public string Blog { get; set; } = "blogs";
|
||||
public string Bills { get; set; } = "bills";
|
||||
public string GitRepository { get; set; } = "sources";
|
||||
|
||||
public string BusinessName { get; set; }
|
||||
public string Street { get; set; }
|
||||
public string PostalCode { get; set; }
|
||||
public string CountryCode { get; set; }
|
||||
public string BusinessName { get; set; } = "Yavsc";
|
||||
public string? Street { get; set; }
|
||||
public string? PostalCode { get; set; }
|
||||
public string? CountryCode { get; set; }
|
||||
|
||||
public string HomeViewName { get; set; }
|
||||
public string HomeViewName { get; set; } = "Home";
|
||||
/// <summary>
|
||||
/// Specifies the directory where should be
|
||||
/// generated pdf files using pandoc
|
||||
@ -53,17 +63,6 @@ namespace Yavsc
|
||||
/// <returns>The temporary directory to use</returns>
|
||||
public string TempDir { get; set; } = "temp";
|
||||
|
||||
/// <summary>
|
||||
/// Only one performer will capture payments
|
||||
/// </summary>
|
||||
/// <returns>user capturing payments id</returns>
|
||||
public string OnlyOnePerformerId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Only one activity will be supported
|
||||
/// </summary>
|
||||
/// <returns>the supported activity code</returns>
|
||||
public string OnlyOneActivityCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Disk usage user list maximum length in memory
|
||||
|
@ -38,23 +38,22 @@ namespace Yavsc.ViewModels.Streaming
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<FileRecievedInfo> ReceiveUserFile(ApplicationUser user, ILogger logger, string root, Queue<ArraySegment<byte>> queue, string destFileName, Func<bool> isEndOfInput)
|
||||
public async Task<FileReceivedInfo> 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 item = new FileReceivedInfo
|
||||
(root, AbstractFileSystemHelpers.FilterFileName(destFileName));
|
||||
|
||||
var fi = new FileInfo(Path.Combine(root, item.FileName));
|
||||
if (fi.Exists)
|
||||
{
|
||||
item.Overriden = true;
|
||||
item.Overridden = true;
|
||||
usage -= fi.Length;
|
||||
}
|
||||
|
||||
logger.LogInformation("Opening the file");
|
||||
using (var dest = fi.Open(FileMode.Create, FileAccess.Write, FileShare.Read))
|
||||
{
|
||||
@ -82,7 +81,7 @@ namespace Yavsc.ViewModels.Streaming
|
||||
}
|
||||
if (usage >= user.DiskQuota)
|
||||
{
|
||||
item.QuotaOffensed = true;
|
||||
item.QuotaOffense = true;
|
||||
}
|
||||
user.DiskUsage = usage;
|
||||
return item;
|
||||
|
@ -4,6 +4,7 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<UserSecretsId>53bd70e8-ff81-497a-847f-a15fd8ea7a09</UserSecretsId>
|
||||
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.11" />
|
||||
|
@ -1,10 +1,9 @@
|
||||
using cli.Model;
|
||||
using Microsoft.Extensions.CommandLineUtils;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.OptionsModel;
|
||||
|
||||
using cli.Model;
|
||||
using cli.Services;
|
||||
using cli.Settings;
|
||||
|
||||
@ -19,7 +18,7 @@ namespace cli.Commands
|
||||
|
||||
public CommandLineApplication Integrate(CommandLineApplication rootApp)
|
||||
{
|
||||
CommandArgument nsarg=null;
|
||||
CommandArgument nameSpaceArg=null;
|
||||
CommandArgument mdClass=null;
|
||||
CommandArgument ctrlName=null;
|
||||
CommandArgument rPath=null;
|
||||
@ -28,7 +27,7 @@ namespace cli.Commands
|
||||
var cmd = rootApp.Command("mvc", config => {
|
||||
config.FullName = "mvc controller";
|
||||
config.Description = "generates an mvc controller";
|
||||
nsarg = config.Argument("ns","default name space");
|
||||
nameSpaceArg = config.Argument("ns","default name space");
|
||||
mdClass = config.Argument("mc","Model class name");
|
||||
ctrlName = config.Argument("cn", "Controller name");
|
||||
rPath = config.Argument("rp", "Relative path");
|
||||
@ -36,11 +35,11 @@ namespace cli.Commands
|
||||
});
|
||||
cmd.OnExecute(() => {
|
||||
var host = new WebHostBuilder();
|
||||
var hostengnine = host.UseEnvironment("Development")
|
||||
var hostEngine = host.UseEnvironment("Development")
|
||||
.UseServer("cli")
|
||||
.UseStartup<Startup>()
|
||||
.Build();
|
||||
var app = hostengnine.Start();
|
||||
var app = hostEngine.Start();
|
||||
var mailer = app.Services.GetService<MvcGenerator>();
|
||||
var loggerFactory = app.Services.GetService<ILoggerFactory>();
|
||||
var logger = loggerFactory.CreateLogger<GenerationCommander>();
|
||||
@ -49,7 +48,7 @@ namespace cli.Commands
|
||||
MvcGenerator generator = app.Services.GetService<MvcGenerator>();
|
||||
|
||||
var modelFullName = mdClass?.Value ?? options?.Value.ModelFullName;
|
||||
var nameSpace = nsarg?.Value?? options?.Value.NameSpace;
|
||||
var nameSpace = nameSpaceArg?.Value?? options?.Value.NameSpace;
|
||||
var dbContext = dbCtx?.Value?? options?.Value.DbContextFullName;
|
||||
var controllerName = ctrlName?.Value?? options?.Value.ControllerName;
|
||||
var relativePath = rPath?.Value ?? options?.Value.RelativePath;
|
||||
|
Reference in New Issue
Block a user