Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Commit

Permalink
Optimized the Code and added a Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
CraftingDragon007 committed Jun 11, 2023
1 parent 8a8ded2 commit ca69da4
Show file tree
Hide file tree
Showing 6 changed files with 208 additions and 201 deletions.
25 changes: 25 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/.idea
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ obj/
riderModule.iml
/_ReSharper.Caches/
/.idea/
config.xml
config.xml
.vscode/
24 changes: 24 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 5102

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["KekUploadServer/KekUploadServer.csproj", "KekUploadServer/"]
RUN dotnet restore "KekUploadServer/KekUploadServer.csproj"
COPY . .
WORKDIR "/src/KekUploadServer"
RUN dotnet build "KekUploadServer.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "KekUploadServer.csproj" -c Release -o /app/publish

FROM base AS final
RUN apt update
RUN apt install -y ffmpeg
RUN rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY --from=publish /app/publish .
RUN mkdir -p /app/config/
WORKDIR /app/config
ENTRYPOINT ["dotnet", "../KekUploadServer.dll"]
82 changes: 47 additions & 35 deletions KekUploadServer/Controllers/FrontendController.cs
Original file line number Diff line number Diff line change
@@ -1,45 +1,57 @@
using Microsoft.AspNetCore.Mvc;

namespace KekUploadServer.Controllers;

public class FrontendController : Controller
namespace KekUploadServer.Controllers
{
[Route("/")]
[HttpGet]
public IActionResult Index()
public class FrontendController : Controller
{
return File(new FileStream(Data.EnsureNotNullConfig().WebRoot + "index.html", FileMode.Open), "text/html");
}
[HttpGet("/")]
public IActionResult Index()
{
var filePath = Path.Combine(Data.EnsureNotNullConfig().WebRoot, "index.html");
return PhysicalFile(filePath, "text/html");
}

[Route("theme.js")]
[HttpGet]
public IActionResult Theme()
{
return File(new FileStream(Data.EnsureNotNullConfig().WebRoot + "theme.js", FileMode.Open), "text/javascript");
}
[HttpGet("theme.js")]
public IActionResult Theme()
{
var filePath = Path.Combine(Data.EnsureNotNullConfig().WebRoot, "theme.js");
return PhysicalFile(filePath, "text/javascript");
}

[Route("themes/{theme}")]
[HttpGet]
public IActionResult Themes(string theme)
{
return File(new FileStream(Data.EnsureNotNullConfig().WebRoot + "themes/" + theme, FileMode.Open), "text/css");
}
[HttpGet("themes/{theme}")]
public IActionResult Themes(string theme)
{
var filePath = Path.Combine(Data.EnsureNotNullConfig().WebRoot, "themes", theme);
return PhysicalFile(filePath, "text/css");
}

[Route("assets/{asset}")]
[HttpGet]
public IActionResult Assets(string asset)
{
var file = Data.EnsureNotNullConfig().WebRoot + "assets/" + asset;
var fileInfo = new FileInfo(file);
return File(new FileStream(file, FileMode.Open),
"text/" + fileInfo.Extension.Replace(".", "").Replace("js", "javascript"));
}
[HttpGet("assets/{asset}")]
public IActionResult Assets(string asset)
{
var filePath = Path.Combine(Data.EnsureNotNullConfig().WebRoot, "assets", asset);
var contentType = GetContentType(filePath);
return PhysicalFile(filePath, contentType);
}

[Route("favicon.{ext}")]
[HttpGet]
public IActionResult Favicon(string ext)
{
return File(new FileStream(Data.EnsureNotNullConfig().WebRoot + "favicon." + ext, FileMode.Open),
"image/" + ext);
[HttpGet("favicon.{ext}")]
public IActionResult Favicon(string ext)
{
var filePath = Path.Combine(Data.EnsureNotNullConfig().WebRoot, $"favicon.{ext}");
var contentType = GetContentType(filePath);
return PhysicalFile(filePath, contentType);
}

private static string GetContentType(string filePath)
{
var extension = Path.GetExtension(filePath);
return extension switch
{
".css" => "text/css",
".js" => "text/javascript",
".png" => "image/png",
".ico" => "image/x-icon",
_ => "application/octet-stream",
};
}
}
}
Loading

0 comments on commit ca69da4

Please sign in to comment.