2 Commits

Author SHA1 Message Date
65b4ea9476 Fix merge
All checks were successful
Game Ideas build for PR / build_test (pull_request) Successful in 38s
2025-05-18 16:59:59 +02:00
163a251579 fix select bugs 2025-05-18 16:59:30 +02:00
8 changed files with 0 additions and 125 deletions

View File

@@ -1,9 +0,0 @@
namespace GameIdeas.Shared.Enum;
public enum BucketType
{
GameIcon,
GameCover,
GameMedia,
UserIcon
}

View File

@@ -1,3 +0,0 @@
namespace GameIdeas.Shared.Exceptions;
public class BucketTypeMissingException(string message) : Exception(message);

View File

@@ -1,4 +0,0 @@
namespace GameIdeas.Shared.Exceptions;
public class EnvironmentVariableMissingException(string valueName) :
Exception($"Missing environment variable with key: {valueName}");

View File

@@ -1,19 +0,0 @@
using GameIdeas.Shared.Enum;
using GameIdeas.Shared.Exceptions;
namespace GameIdeas.Shared.Extensions;
public static class BucketExtension
{
public static string GetBucket(this BucketType bucketType)
{
return bucketType switch
{
BucketType.GameIcon => "icons",
BucketType.GameCover => "covers",
BucketType.GameMedia => "medias",
BucketType.UserIcon => "users",
_ => throw new BucketTypeMissingException($"Bucket type {bucketType} not exist")
};
}
}

View File

@@ -1,27 +0,0 @@
using GameIdeas.Shared.Enum;
using GameIdeas.WebAPI.Services.Files;
using Microsoft.AspNetCore.Mvc;
namespace GameIdeas.WebAPI.Controllers;
public class FileController(
IFileService fileService,
ILoggerFactory loggerFactory) : Controller
{
private readonly ILogger<FileController> Logger = loggerFactory.CreateLogger<FileController>();
[HttpPost]
[RequestSizeLimit(100_000_000_000)] // 100 GB
public async Task<IActionResult> UploadFile([FromForm] IFormFile file, [FromQuery] BucketType type)
{
try
{
return Ok(await fileService.UploadFile(file, type));
}
catch (Exception e)
{
Logger.LogError(e, "Failed uploading files");
return StatusCode(500, e.Message);
}
}
}

View File

@@ -20,7 +20,6 @@
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference> </PackageReference>
<PackageReference Include="Minio" Version="6.0.4" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" /> <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
</ItemGroup> </ItemGroup>

View File

@@ -1,54 +0,0 @@
using Minio;
using GameIdeas.Shared.Exceptions;
using Minio.DataModel.Args;
using GameIdeas.Shared.Enum;
using GameIdeas.Shared.Extensions;
namespace GameIdeas.WebAPI.Services.Files;
public class FileService : IFileService
{
private readonly IMinioClient MinioClient;
public FileService()
{
var minioEndpoint = Environment.GetEnvironmentVariable("MINIO_ENDPOINT")
?? throw new EnvironmentVariableMissingException("MINIO_ENDPOINT");
var minioAccessKey = Environment.GetEnvironmentVariable("MINIO_ACCESS_KEY")
?? throw new EnvironmentVariableMissingException("MINIO_ACCESS_KEY");
var minioSecretKey= Environment.GetEnvironmentVariable("MINIO_SECRET_KEY")
?? throw new EnvironmentVariableMissingException("MINIO_SECRET_KEY");
MinioClient = new MinioClient()
.WithEndpoint(minioEndpoint)
.WithCredentials(minioAccessKey, minioSecretKey)
.Build();
}
public async Task<string> UploadFile(IFormFile file, BucketType bucketType)
{
var fileName = Path.GetFileName(file.FileName);
var bucket = bucketType.GetBucket();
bool found = await MinioClient.BucketExistsAsync(new BucketExistsArgs().WithBucket(bucket));
if (!found)
{
await MinioClient.MakeBucketAsync(new MakeBucketArgs().WithBucket(bucket));
}
using var stream = file.OpenReadStream();
var args = new PutObjectArgs()
.WithBucket(bucket)
.WithObject(fileName)
.WithStreamData(stream)
.WithObjectSize(file.Length)
.WithContentType(file.ContentType);
await MinioClient.PutObjectAsync(args);
return $"/{bucket}/{fileName}";
}
}

View File

@@ -1,8 +0,0 @@
using GameIdeas.Shared.Enum;
namespace GameIdeas.WebAPI.Services.Files;
public interface IFileService
{
Task<string> UploadFile(IFormFile file, BucketType bucketType);
}