diff --git a/a4PaperHolder.sln b/a4PaperHolder.sln new file mode 100644 index 0000000..9e6e831 --- /dev/null +++ b/a4PaperHolder.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.13.35931.197 d17.13 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "a4PaperHolder", "a4PaperHolder\a4PaperHolder.csproj", "{95F1076B-0572-4793-88E2-40D16276519D}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {95F1076B-0572-4793-88E2-40D16276519D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {95F1076B-0572-4793-88E2-40D16276519D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {95F1076B-0572-4793-88E2-40D16276519D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {95F1076B-0572-4793-88E2-40D16276519D}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {40BA2D0D-709F-4322-858E-977E04E6F51C} + EndGlobalSection +EndGlobal diff --git a/a4PaperHolder/Pages/Index.cshtml b/a4PaperHolder/Pages/Index.cshtml new file mode 100644 index 0000000..ea8b557 --- /dev/null +++ b/a4PaperHolder/Pages/Index.cshtml @@ -0,0 +1,36 @@ +@page +@model a4PaperHolder.Pages.IndexModel + +

파일 목록

+ + \ No newline at end of file diff --git a/a4PaperHolder/Pages/Index.cshtml.cs b/a4PaperHolder/Pages/Index.cshtml.cs new file mode 100644 index 0000000..49cc24d --- /dev/null +++ b/a4PaperHolder/Pages/Index.cshtml.cs @@ -0,0 +1,57 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.AspNetCore.StaticFiles; +using System.Security.Cryptography; +using System.Text; +using System.Text.Unicode; + +namespace a4PaperHolder.Pages +{ + public class IndexModel : PageModel + { + private readonly string basePath = Path.Combine(AppContext.BaseDirectory, "NASFiles"); + + //ms ڵ ؽƮ迭 ڿ ٲش ī + static string ByteArrayToString(byte[] byteArray) + { + int i; + StringBuilder stringBuilder = new(byteArray.Length); + for (i = 0; i < byteArray.Length; i++) + { + stringBuilder.Append(byteArray[i].ToString("X2")); + } + return stringBuilder.ToString(); + } + + public List Files { get; set; } = []; + public void OnGet() + { + if (!Directory.Exists(basePath)) + return; + + var provider = new FileExtensionContentTypeProvider(); + Files = [.. Directory.GetFiles(basePath).Select(path => + { + provider.TryGetContentType(path, out var mime); + return new FileItem + { + Name = Path.GetFileName(path), + HashName = ByteArrayToString( + SHA3_512.HashData( + Encoding.Default.GetBytes( + Path.GetFileName(path)))), + Path = path, + MimeType = mime ?? "application/octet-stream" + }; + })]; + } + } + + public class FileItem + { + public required string Name { get; set; } + public required string HashName {get; set; } + public required string Path { get; set; } + public required string MimeType { get; set; } + } +} diff --git a/a4PaperHolder/Program.cs b/a4PaperHolder/Program.cs new file mode 100644 index 0000000..1669785 --- /dev/null +++ b/a4PaperHolder/Program.cs @@ -0,0 +1,36 @@ +using Microsoft.AspNetCore.StaticFiles; +using System.Text; + +var builder = WebApplication.CreateBuilder(args); + +builder.Services.AddRazorPages(); + +var app = builder.Build(); + +//razor가 브라우저에서 돌아가면? brazor 작명센스 조졌네 +app.UseStaticFiles(); +app.MapRazorPages(); + +var basePath = Path.Combine(AppContext.BaseDirectory, "NASFiles"); + +//파일 미리보기 부분 비디오,오디오 유형은 빨리감기 뒤로감기 안되는 사소한 찐빠가 있으나 이런들 어떠하고 저런들 어떠하리 +app.MapGet("/view", (HttpRequest request) => +{ + var fileName = request.Query["name"].ToString(); + + if (fileName.Contains("..") || fileName.Contains(Path.DirectorySeparatorChar)) + return Results.BadRequest("?"); + + var filePath = Path.Combine(basePath, fileName); + + if (!System.IO.File.Exists(filePath)) + return Results.NotFound(); + + var provider = new FileExtensionContentTypeProvider(); + provider.TryGetContentType(filePath, out var contentType); + contentType ??= "application/octet-stream"; + + return Results.File(System.IO.File.OpenRead(filePath), contentType); +}); + +app.Run(); diff --git a/a4PaperHolder/Properties/launchSettings.json b/a4PaperHolder/Properties/launchSettings.json new file mode 100644 index 0000000..2e7c789 --- /dev/null +++ b/a4PaperHolder/Properties/launchSettings.json @@ -0,0 +1,38 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:27040", + "sslPort": 44357 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "http://localhost:5190", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "https://localhost:7012;http://localhost:5190", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/a4PaperHolder/a4PaperHolder.csproj b/a4PaperHolder/a4PaperHolder.csproj new file mode 100644 index 0000000..a975bc7 --- /dev/null +++ b/a4PaperHolder/a4PaperHolder.csproj @@ -0,0 +1,13 @@ + + + + net8.0 + enable + enable + + + + + + + diff --git a/a4PaperHolder/a4PaperHolder.csproj.user b/a4PaperHolder/a4PaperHolder.csproj.user new file mode 100644 index 0000000..674a4a1 --- /dev/null +++ b/a4PaperHolder/a4PaperHolder.csproj.user @@ -0,0 +1,8 @@ + + + + https + RazorPageScaffolder + root/Common/RazorPage + + \ No newline at end of file diff --git a/a4PaperHolder/appsettings.Development.json b/a4PaperHolder/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/a4PaperHolder/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/a4PaperHolder/appsettings.json b/a4PaperHolder/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/a4PaperHolder/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +}