Skip to content

Commit

Permalink
fix: precommit failures
Browse files Browse the repository at this point in the history
  • Loading branch information
kirinnee committed Dec 31, 2024
1 parent e81e93d commit dc65924
Show file tree
Hide file tree
Showing 53 changed files with 811 additions and 1,104 deletions.
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ dotnet_style_qualification_for_field = true
dotnet_style_qualification_for_property = true
dotnet_style_qualification_for_method = true
dotnet_style_qualification_for_event = true
dotnet_style_prefer_collection_expression = false
# Language keywords vs BCL types preferences
dotnet_style_predefined_type_for_locals_parameters_members = true
dotnet_style_predefined_type_for_member_access = true
Expand Down
8 changes: 8 additions & 0 deletions .prettierrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
tabWidth: 2
semi: true
singleQuote: true
bracketSpacing: true
trailingComma: all
arrowParens: avoid
printWidth: 120
singleAttributePerLine: false
10 changes: 1 addition & 9 deletions App/Config/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -713,15 +713,7 @@
"DatabaseOption": {
"type": "object",
"additionalProperties": false,
"required": [
"Host",
"User",
"Password",
"Port",
"Database",
"AutoMigrate",
"Timeout"
],
"required": ["Host", "User", "Password", "Port", "Database", "AutoMigrate", "Timeout"],
"properties": {
"Host": {
"type": "string",
Expand Down
14 changes: 7 additions & 7 deletions App/Config/settings.example.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
$schema: ./schema.json
AllowedHosts: "*"
AllowedHosts: '*'
Kestrel:
Endpoints:
Http:
Expand Down Expand Up @@ -38,14 +38,14 @@ Logs:
Enabled: false
Otlp:
Enabled: false
Endpoint: "sample"
Endpoint: 'sample'
ProcessorType: Batch # or simple
Protocol: Grpc # or HttpProtobuf
Timeout: 30000
BatchSize: 512
QueueSize: 2048
Delay: 5000
Headers: "sample"
Headers: 'sample'

Trace:
Instrument:
Expand Down Expand Up @@ -74,14 +74,14 @@ Trace:
Enabled: false
Otlp:
Enabled: true
Endpoint: "http://otel-oltp-collector.default.svc:4317"
Endpoint: 'http://otel-oltp-collector.default.svc:4317'
Timeout: 30000
ProcessorType: Batch # or simple
Protocol: Grpc # or HttpProtobuf
BatchSize: 512
QueueSize: 2048
Delay: 5000
Headers: ""
Headers: ''

Metrics:
Instrument:
Expand All @@ -95,15 +95,15 @@ Metrics:
ExportInterval: 1000
Otlp:
Enabled: false
Endpoint: ""
Endpoint: ''
ExportInterval: 1000
Timeout: 30000
ProcessorType: Batch # or simple
Protocol: Grpc # or HttpProtobuf
BatchSize: 512
QueueSize: 2048
Delay: 5000
Headers: ""
Headers: ''
Swagger:
Title: Lapras CarboxylicAcid .NET API
Description: Lapras CarboxylicAcid .NET API
Expand Down
20 changes: 10 additions & 10 deletions App/Config/settings.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
$schema: ./schema.json
# Native
AllowedHosts: "*"
AllowedHosts: '*'
Kestrel:
Endpoints:
Http:
Expand Down Expand Up @@ -28,7 +28,7 @@ App:
GenerateConfig: false
Swagger:
Title: Lapras CarboxylicAcid Carbon API
Description: "Sulfone-Zinc: Registry API for CyanPrint"
Description: 'Sulfone-Zinc: Registry API for CyanPrint'
OpenApiContact:
Name: kirinnee
Email: kirinnee97@gmail.com
Expand All @@ -49,14 +49,14 @@ Logs:
Enabled: false
Otlp:
Enabled: false
Endpoint: "http://silicon-otlp-collector.sulfoxide.svc:4317"
Endpoint: 'http://silicon-otlp-collector.sulfoxide.svc:4317'
ProcessorType: Batch # or simple
Protocol: Grpc # or HttpProtobuf
Timeout: 30000
BatchSize: 512
QueueSize: 2048
Delay: 5000
Headers: ""
Headers: ''

Trace:
Instrument:
Expand Down Expand Up @@ -85,14 +85,14 @@ Trace:
Enabled: false
Otlp:
Enabled: false
Endpoint: "http://silicon-otlp-collector.sulfoxide.svc:4317"
Endpoint: 'http://silicon-otlp-collector.sulfoxide.svc:4317'
Timeout: 30000
ProcessorType: Batch # or simple
Protocol: Grpc # or HttpProtobuf
BatchSize: 512
QueueSize: 2048
Delay: 5000
Headers: ""
Headers: ''

Metrics:
Instrument:
Expand All @@ -106,15 +106,15 @@ Metrics:
ExportInterval: 1000
Otlp:
Enabled: false
Endpoint: "http://silicon-otlp-collector.sulfoxide.svc:4317"
Endpoint: 'http://silicon-otlp-collector.sulfoxide.svc:4317'
ExportInterval: 1000
Timeout: 30000
ProcessorType: Batch # or simple
Protocol: Grpc # or HttpProtobuf
BatchSize: 512
QueueSize: 2048
Delay: 5000
Headers: ""
Headers: ''

# Infra-based
Database:
Expand All @@ -138,8 +138,8 @@ Auth:
OnlyAdmin:
Target:
- Admin
Type: "All"
Field: "roles"
Type: 'All'
Field: 'roles'
Issuer: P2Wskb04HSJQRfckShfhtWXwUiUd
Audience: P2Wskb04HSJQRfckShfhtWXwUiUd
Domain: api.descope.com/P2Wskb04HSJQRfckShfhtWXwUiUd
Expand Down
9 changes: 2 additions & 7 deletions App/Error/DomainProblemException.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
namespace App.Error;

public class DomainProblemException : Exception
public class DomainProblemException(IDomainProblem problem) : Exception
{
public DomainProblemException(IDomainProblem problem)
{
this.Problem = problem;
}

public IDomainProblem Problem { get; set; }
public IDomainProblem Problem { get; set; } = problem;
}
15 changes: 3 additions & 12 deletions App/Modules/Common/FileRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,9 @@ public interface IFileRepository
Task<Result<string?>> SignedLink(string store, string key, int seconds);
}

public class FileRepository : IFileRepository
public class FileRepository(IBlockStorageFactory factory, ContentInspector inspector) : IFileRepository
{
private readonly IBlockStorageFactory _factory;
private readonly ContentInspector _inspector;

public FileRepository(IBlockStorageFactory factory, ContentInspector inspector)
{
this._factory = factory;
this._inspector = inspector;
}

private IBlockStorage Store(string key) => this._factory.Get(key);
private IBlockStorage Store(string key) => factory.Get(key);

public Task<Result<string?>> Save(string store, string dir, string name, byte[] content, bool appendExt)
{
Expand All @@ -43,7 +34,7 @@ public FileRepository(IBlockStorageFactory factory, ContentInspector inspector)
{
var s = this.Store(store);
content.Position = 0;
var d = this._inspector
var d = inspector
.Inspect(content)
.MaxBy(x => x.Points)?.Definition;

Expand Down
25 changes: 8 additions & 17 deletions App/Modules/Common/IFileValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,8 @@ public interface IFileValidator
Task<Result<Stream>> Validate(Stream stream, FileValidationParam param);
}

public class FileValidator : IFileValidator
public class FileValidator(ContentInspector inspector, ILogger<FileValidator> logger) : IFileValidator
{
private readonly ContentInspector _inspector;
private readonly ILogger<FileValidator> _logger;

public FileValidator(ContentInspector inspector, ILogger<FileValidator> logger)
{
this._inspector = inspector;
this._logger = logger;
}

public async Task<Result<Stream>> Validate(IFormFile file, FileValidationParam param)
{
using var fStream = new MemoryStream();
Expand All @@ -44,13 +35,13 @@ public Task<Result<Stream>> Validate(Stream stream, FileValidationParam param)
stream.Position = 0;

// Validate file
var d = this._inspector
var d = inspector
.Inspect(stream)
.MaxBy(x => x.Points)?.Definition;
if (d == null)
{
var err = new UnknownFileType("Unknown file format");
this._logger.LogError(err.ToException(), "Server cannot detect the MIME type of the file");
logger.LogError(err.ToException(), "Server cannot detect the MIME type of the file");
return Task.FromResult<Result<Stream>>(err.ToException());
}

Expand All @@ -59,16 +50,16 @@ public Task<Result<Stream>> Validate(Stream stream, FileValidationParam param)
if (mime == null || ext == null)
{
var err = new UnknownFileType("Unknown file format");
this._logger.LogError(err.ToException(), "Server cannot detect the MIME type of the file");
logger.LogError(err.ToException(), "Server cannot detect the MIME type of the file");
return Task.FromResult<Result<Stream>>(err.ToException());
}

this._logger.LogInformation("File is a '{Mime}' file with Extension: {Ext}", mime, ext);
logger.LogInformation("File is a '{Mime}' file with Extension: {Ext}", mime, ext);
if (param.AllowedMime != null && !param.AllowedMime.Contains(mime))
{
var err = new InvalidFileType($"File must be one of '{param.AllowedMime.Humanize()}' but was '{mime}'", mime,
param.AllowedMime);
this._logger.LogError(err.ToException(), "File must be one of '{Allowed}' but was '{Mime}'",
logger.LogError(err.ToException(), "File must be one of '{Allowed}' but was '{Mime}'",
param.AllowedMime.Humanize(), mime);
return Task.FromResult<Result<Stream>>(err.ToException());
}
Expand All @@ -78,7 +69,7 @@ public Task<Result<Stream>> Validate(Stream stream, FileValidationParam param)
var err = new InvalidFileExt(
$"File must be one of '{param.AllowedExt.Humanize()}' but was '{d.File.Extensions.Humanize()}'", ext,
param.AllowedExt);
this._logger.LogError(err.ToException(), "File must be one of '{Allowed}' but was '{Extension}'",
logger.LogError(err.ToException(), "File must be one of '{Allowed}' but was '{Extension}'",
param.AllowedExt.Humanize(), d.File.Extensions.Humanize());
return Task.FromResult<Result<Stream>>(err.ToException());
}
Expand All @@ -90,7 +81,7 @@ public Task<Result<Stream>> Validate(Stream stream, FileValidationParam param)
$"File must be smaller than {maxSize.Bits().Humanize()} but received {stream.Length.Bits().Humanize()}",
stream.Length,
maxSize);
this._logger.LogError(err.ToException(),
logger.LogError(err.ToException(),
"File must be smaller than {AcceptedFileSize} ({AcceptedFileSizeFriendly}) but received {ReceivedFileSize} ({ReceivedFileSizeFriendly})",
maxSize, maxSize.Bits().Humanize(), stream.Length, stream.Length.Bits().Humanize());
return Task.FromResult<Result<Stream>>(err.ToException());
Expand Down
Loading

0 comments on commit dc65924

Please sign in to comment.