Skip to content

Commit

Permalink
- added .env file & made the projects use it
Browse files Browse the repository at this point in the history
- using tailwindcli now
  • Loading branch information
m-GDEV committed Dec 2, 2024
1 parent e09476c commit caf31b4
Show file tree
Hide file tree
Showing 26 changed files with 4,629 additions and 62 deletions.
5 changes: 3 additions & 2 deletions WardrobeManager.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

// Configuration is setup by default to read from (in order of precedence) Environment Variables, appsettings.json
// https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-8.0
string BackendUrl = builder.Configuration["BackendUrl"] ?? throw new Exception("BackendUrl: configuration value not set");
string FrontendUrl = builder.Configuration["FrontendUrl"] ?? throw new Exception("Frontend: configuration value not set");
string BackendUrl = builder.Configuration["WM_BACKEND_URL"] ?? throw new Exception("BackendUrl: configuration value not set");
string FrontendUrl = builder.Configuration["WM_FRONTEND_URL"] ?? throw new Exception("Frontend: configuration value not set");

builder.Services.AddAuthentication(IdentityConstants.ApplicationScheme).AddIdentityCookies();
// Configure app cookie (THIS ALLOWS THE BACKEND AND FRONTEND RUN ON DIFFERENT DOMAINS)
Expand Down Expand Up @@ -101,6 +101,7 @@
app.UseSwaggerUI();
}

// Adds a bunch of auto generated Identity-related routes (/register, /login, etc)
app.MapIdentityApi<AppUser>();
app.UseCors("wasm");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class DataDirectoryService : IDataDirectoryService

public DataDirectoryService(IConfiguration config, IWebHostEnvironment webHostEnvironment)
{
string DataDirectory = config["DataDirectory"] ?? throw new Exception("Data Directory: configuration value not set");
string DataDirectory = config["WM_DATA_DIRECTORY"] ?? throw new Exception("Data Directory: configuration value not set");

_baseDirectory = webHostEnvironment.IsDevelopment() ? Path.GetFullPath(Path.Combine(webHostEnvironment.ContentRootPath, DataDirectory)) : DataDirectory;
}
Expand Down
38 changes: 22 additions & 16 deletions WardrobeManager.Api/Services/Implementation/FileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,12 @@

namespace WardrobeManager.Api.Services.Implementation;

public class FileService : IFileService
public class FileService(
IDataDirectoryService dataDirectoryService,
IWebHostEnvironment webHostEnvironment,
IConfiguration configuration)
: IFileService
{
private readonly IDataDirectoryService _dataDirectoryService;
private readonly IWebHostEnvironment _webHostEnvironment;

public FileService(IDataDirectoryService dataDirectoryService, IWebHostEnvironment webHostEnvironment)
{
_dataDirectoryService = dataDirectoryService;
_webHostEnvironment = webHostEnvironment;
}

public string ParseGuid(Guid guid)
{
return guid.ToString().Replace("{", "").Replace("}", "");
Expand All @@ -31,26 +26,37 @@ public async Task SaveImage(Guid? guid, string ImageBase64)

byte[] imageBytes = Convert.FromBase64String(ImageBase64);

string path = Path.Combine(_dataDirectoryService.GetUploadsDirectory(), ParseGuid(properGuid));
// 5MB default max file size
var max_file_size = configuration["WM_MAX_IMAGE_UPLOAD_SIZE_IN_MB"] ?? "5";
int max_file_size_num = Convert.ToInt32(max_file_size);
max_file_size_num *= 1024;

if (imageBytes.Length > max_file_size_num)
{
throw new Exception(
$"File size too large! Received file size: {imageBytes.Length / 1024} MB. Max file size: {max_file_size_num / 1024} MB");
}

string path = Path.Combine(dataDirectoryService.GetUploadsDirectory(), ParseGuid(properGuid));

await File.WriteAllBytesAsync(path, imageBytes);
}

public async Task<byte[]> GetImage(string guid)
{
string path = Path.Combine(_dataDirectoryService.GetUploadsDirectory(), guid);
string notFound = Path.Combine(_webHostEnvironment.WebRootPath, "images", "notfound.jpg");
string path = Path.Combine(dataDirectoryService.GetUploadsDirectory(), guid);
string notFound = Path.Combine(webHostEnvironment.WebRootPath, "images", "notfound.jpg");

if (File.Exists(path))
{
byte[] imageBytes = await File.ReadAllBytesAsync(path); // 6. Serve the file
byte[] imageBytes = await File.ReadAllBytesAsync(path); // 6. Serve the file
return imageBytes;
}

else
{
byte[] imageBytes = await File.ReadAllBytesAsync(notFound); // 6. Serve the file
byte[] imageBytes = await File.ReadAllBytesAsync(notFound); // 6. Serve the file
return imageBytes;
}
}
}
}
6 changes: 3 additions & 3 deletions WardrobeManager.Api/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
}
},

"BackendUrl": "https://localhost:7026",
"FrontendUrl": "https://localhost:7147",
"DataDirectory": "../data"
"WM_BACKEND_URL": "https://localhost:7026",
"WM_FRONTEND_URL": "https://localhost:7147",
"WM_DATA_DIRECTORY": "../data"
}
12 changes: 0 additions & 12 deletions WardrobeManager.Api/appsettings.Production.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
</div>

@* Modal that pops up when user clicks 'edit' *@
<Modal Id="@ModalId" MaxWidth="40rem">
<Modal Id="@ModalId" MaxWidth="max-w-[40rem]">
<NewOrEditItemSection Editing="true" EditedItem="Item" SubmitForm="HandleEdit"/>
</Modal>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,13 @@
try
{
img = new MemoryStream();
// 5MB max file size
await e.File.OpenReadStream(maxAllowedSize: 1024 * 5000).CopyToAsync(img);

// 5MB default max file size
var max_file_size = _config["WM_MAX_IMAGE_UPLOAD_SIZE_IN_MB"] ?? "5";
int max_file_size_num = Convert.ToInt32(max_file_size);
max_file_size_num *= 1024;

await e.File.OpenReadStream(maxAllowedSize: max_file_size_num).CopyToAsync(img);

newItem.ImageBase64 = Convert.ToBase64String(img.ToArray());

Expand Down
2 changes: 1 addition & 1 deletion WardrobeManager.Presentation/Components/Shared/Image.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@namespace WardrobeManager.Presentation.Components.Shared

<img src="@_config["BackendUrl"]/images/@_imagePath" class="@Css"/>
<img src="@_config["WM_BACKEND_URL"]/images/@_imagePath" class="@Css"/>

@code {
[Parameter] public required Guid? ImageGuid { get; set; }
Expand Down
4 changes: 2 additions & 2 deletions WardrobeManager.Presentation/Components/Shared/Modal.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
@* !! When using this component make sure you put onclick="id.showModal()" in a button or something !! *@

<dialog id="@Id" class="modal">
<div class="modal-box max-w-[@MaxWidth] w-[90%] relative min-h-[20rem] flex flex-row justify-center items-center">
<div class="modal-box @MaxWidthCss w-[90%] relative min-h-[20rem] flex flex-row justify-center items-center">
@ChildContent

</div>
Expand All @@ -20,7 +20,7 @@
{
[Parameter] public required string Id { get; set; }

[Parameter] public string MaxWidth { get; set; } = "70rem";
[Parameter] public string MaxWidthCss { get; set; } = "max-w-[70rem]";

[Parameter] public required RenderFragment ChildContent { get; set; }
}
2 changes: 1 addition & 1 deletion WardrobeManager.Presentation/Pages/Test.razor
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

protected override void OnInitialized()
{
f = $"{_config["BackendUrl"] ?? "terrifier 3 was a great movie"}";
f = $"{_config["WM_BACKEND_URL"] ?? "terrifier 3 was a great movie"}";
_logger.LogCritical(f);
Console.WriteLine(f);
StateHasChanged();
Expand Down
2 changes: 1 addition & 1 deletion WardrobeManager.Presentation/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

// Configuration is setup by default to read from (in order of precedence) Environment Variables, appsettings.json
// https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-8.0
string BackendUrl = builder.Configuration["BackendUrl"] ?? throw new Exception("BackendUrl: configuration value not set");
string BackendUrl = builder.Configuration["WM_BACKEND_URL"] ?? throw new Exception("BackendUrl: configuration value not set");

Console.WriteLine("Hello man" + BackendUrl);

Expand Down
Loading

0 comments on commit caf31b4

Please sign in to comment.