New Project
Ani 폴더 리스트 가져오는 API
This commit is contained in:
11
VideoArchiveAPI/Config.cs
Normal file
11
VideoArchiveAPI/Config.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace VideoArchiveAPI
|
||||
{
|
||||
|
||||
public class Config
|
||||
{
|
||||
public const string SectionName = "Config";
|
||||
public int Port { get; set; }
|
||||
public string Location { get; set; }
|
||||
}
|
||||
|
||||
}
|
58
VideoArchiveAPI/Controllers/VideoController.cs
Normal file
58
VideoArchiveAPI/Controllers/VideoController.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace VideoArchiveAPI.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class VideoController : ControllerBase
|
||||
{
|
||||
private readonly ILogger<VideoController> _logger;
|
||||
private readonly Config _config;
|
||||
|
||||
public VideoController(ILogger<VideoController> logger, IOptions<Config> config)
|
||||
{
|
||||
_logger = logger;
|
||||
_config = config.Value;
|
||||
}
|
||||
|
||||
[HttpGet(Name = "VideoController")]
|
||||
public ActionResult<List<string>> Get()
|
||||
{
|
||||
GetData getData = new GetData();
|
||||
|
||||
List<string> directorys = getData.GetSubDirectories(_config.Location);
|
||||
if (directorys.Count == 0)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
else
|
||||
{
|
||||
return Ok(directorys);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class GetData
|
||||
{
|
||||
public List<string> GetSubDirectories(string path)
|
||||
{
|
||||
List<string> directorys = new List<string>();
|
||||
string[] dirs = System.IO.Directory.GetDirectories(path);
|
||||
foreach (string dir in dirs)
|
||||
{
|
||||
string[] subDirs = System.IO.Directory.GetDirectories(dir);
|
||||
if(subDirs.Length == 0)
|
||||
{
|
||||
directorys.Add(dir.Replace(path,"").Replace("\\", ""));
|
||||
}
|
||||
else
|
||||
{
|
||||
directorys.AddRange(GetSubDirectories(dir));
|
||||
}
|
||||
}
|
||||
return directorys;
|
||||
}
|
||||
}
|
||||
}
|
37
VideoArchiveAPI/Program.cs
Normal file
37
VideoArchiveAPI/Program.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System.Net;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text.Json;
|
||||
using VideoArchiveAPI;
|
||||
|
||||
string configPath = "config.json";
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// configPath <20><> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ִ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
configPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), configPath);
|
||||
|
||||
if (!System.IO.File.Exists(configPath))
|
||||
{
|
||||
string defaultSetting = "{\"Config\": {\"Port\": 8981,\"Location\": \".\\\\\"}}";
|
||||
System.IO.File.WriteAllText(configPath , defaultSetting);
|
||||
|
||||
|
||||
}
|
||||
|
||||
builder.Configuration.AddJsonFile(configPath, optional: false, reloadOnChange: true);
|
||||
builder.Services.Configure<Config>(builder.Configuration.GetSection("Config"));
|
||||
Config localConfig = builder.Configuration.GetSection(Config.SectionName).Get<Config>();
|
||||
|
||||
builder.WebHost.ConfigureKestrel((context, serverOptions) =>
|
||||
{
|
||||
serverOptions.Listen(IPAddress.Loopback, localConfig.Port);
|
||||
});
|
||||
|
||||
builder.Services.AddControllers();
|
||||
var app = builder.Build();
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
app.Run();
|
41
VideoArchiveAPI/Properties/launchSettings.json
Normal file
41
VideoArchiveAPI/Properties/launchSettings.json
Normal file
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"$schema": "http://json.schemastore.org/launchsettings.json",
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:54419",
|
||||
"sslPort": 44360
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"applicationUrl": "http://localhost:5151",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"applicationUrl": "https://localhost:7261;http://localhost:5151",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
13
VideoArchiveAPI/VideoArchiveAPI.csproj
Normal file
13
VideoArchiveAPI/VideoArchiveAPI.csproj
Normal file
@@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
6
VideoArchiveAPI/VideoArchiveAPI.http
Normal file
6
VideoArchiveAPI/VideoArchiveAPI.http
Normal file
@@ -0,0 +1,6 @@
|
||||
@VideoArchiveAPI_HostAddress = http://localhost:5151
|
||||
|
||||
GET {{VideoArchiveAPI_HostAddress}}/weatherforecast/
|
||||
Accept: application/json
|
||||
|
||||
###
|
8
VideoArchiveAPI/appsettings.Development.json
Normal file
8
VideoArchiveAPI/appsettings.Development.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
9
VideoArchiveAPI/appsettings.json
Normal file
9
VideoArchiveAPI/appsettings.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
Reference in New Issue
Block a user