2024-05-02 15:24:13 -07:00

43 lines
1.2 KiB
C#

using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.IO;
using System.Linq;
using WebAPI;
using WebAPI.Services.Interfaces;
namespace Church.Net.WebAPI.Controllers
{
[Route("[controller]")]
[ApiController]
public class FileListController : ControllerBase
{
private readonly ILoggingService loggingService;
public FileListController(ILoggingService loggingService)
{
this.loggingService = loggingService;
}
[HttpGet("{*filePath}")]
public ActionResult<string[]> Get(string filePath)
{
string folderRootPath = "";
string folderPath = "";
try
{
#if DEBUG
folderRootPath = "//ArkNAS/docker/ChurchAPI/App_Data/Files";
#else
folderRootPath = "/App_Data/Files";
#endif
folderPath = System.IO.Path.Combine(folderRootPath, filePath);
return Directory.GetFiles(folderPath).Select(s=>s.Replace(folderRootPath,"").Replace(filePath, "").Replace("\\","/")).ToArray();
}
catch (System.Exception ex)
{
loggingService.Error(ex);
return NotFound();
}
}
}
}