메시지를 입력하세요

This commit is contained in:
2025-05-13 14:33:25 +09:00
parent 25acef9cc2
commit 471a1b1cf0
9 changed files with 230 additions and 0 deletions

25
a4PaperHolder.sln Normal file
View File

@@ -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

View File

@@ -0,0 +1,36 @@
@page
@model a4PaperHolder.Pages.IndexModel
<h2>파일 목록</h2>
<ul>
@foreach (var file in Model.Files)
{
<li>
<strong>@file.Name</strong>
<strong>@file.HashName</strong>
<div>
@if (file.MimeType.StartsWith("text"))
{
<iframe src="/view?name=@file.Name" width="600" height="400"></iframe>
}
else if (file.MimeType.StartsWith("image"))
{
<img src="/view?name=@file.Name" width="300" />
}
else if (file.MimeType.StartsWith("video"))
{
<video src="/view?name=@file.Name" width="600" controls></video>
}
else if (file.MimeType.StartsWith("audio"))
{
<audio src="/view?name=@file.Name" controls></audio>
}
else
{
<a href="/view?name=@file.Name" download>다운로드</a>
}
</div>
</li>
}
</ul>

View File

@@ -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<6D><73><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ڵ<EFBFBD> <20>ؽ<EFBFBD><D8BD><EFBFBD><EFBFBD><EFBFBD>Ʈ<EFBFBD><EFBFBD><E8BFAD> <20><><EFBFBD>ڿ<EFBFBD><DABF><EFBFBD> <20>ٲ<EFBFBD><D9B2>ش<EFBFBD> ī<><C4AB><EFBFBD><EFBFBD>
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<FileItem> 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; }
}
}

36
a4PaperHolder/Program.cs Normal file
View File

@@ -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();

View File

@@ -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"
}
}
}
}

View File

@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ActiveDebugProfile>https</ActiveDebugProfile>
<RazorPage_SelectedScaffolderID>RazorPageScaffolder</RazorPage_SelectedScaffolderID>
<RazorPage_SelectedScaffolderCategoryPath>root/Common/RazorPage</RazorPage_SelectedScaffolderCategoryPath>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

View File

@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}