3a0e1bc2a4
Added filePath config
160 lines
5.4 KiB
C#
160 lines
5.4 KiB
C#
using Step.Model.DTOModels;
|
|
using Step.NC;
|
|
using Step.Utils;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Net;
|
|
using System.Net.Http;
|
|
using static Step.Model.Constants;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Web.Http;
|
|
using static CMS_CORE_Library.DataStructures;
|
|
using System.Linq;
|
|
using static Step.Config.ServerConfig;
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
namespace Step.Controllers.WebApi
|
|
{
|
|
[RoutePrefix("api/file_manager")]
|
|
public class NcFileController : ApiController
|
|
{
|
|
[Route("files"), HttpGet]
|
|
public IHttpActionResult GetFileList(string filePath = "")
|
|
{
|
|
using (NcHandler ncHandler = new NcHandler())
|
|
{
|
|
ncHandler.Connect();
|
|
|
|
CmsError cmsError = ncHandler.GetFileList(filePath, out List<PreviewFileModel> fileList);
|
|
if (cmsError.IsError())
|
|
return BadRequest(cmsError.localizationKey);
|
|
|
|
return Ok(fileList);
|
|
}
|
|
}
|
|
|
|
[Route("file/info"), HttpGet]
|
|
public IHttpActionResult GetFileInfo([FromUri]string filePath)
|
|
{
|
|
using (NcHandler ncHandler = new NcHandler())
|
|
{
|
|
ncHandler.Connect();
|
|
|
|
CmsError cmsError = ncHandler.GetFileInfo(filePath, out InfoFile fileInfo);
|
|
if (cmsError.IsError())
|
|
return BadRequest(cmsError.localizationKey);
|
|
|
|
return Ok(fileInfo);
|
|
}
|
|
}
|
|
|
|
[Route("file/active"), HttpPut]
|
|
public IHttpActionResult SetActiveProgram([FromUri]string filePath)
|
|
{
|
|
using (NcHandler ncHandler = new NcHandler())
|
|
{
|
|
ncHandler.Connect();
|
|
|
|
CmsError cmsError = ncHandler.SetActiveProgramInfo(filePath, out DTOActiveProgramDataModel fileInfo);
|
|
if (cmsError.IsError())
|
|
return BadRequest(cmsError.localizationKey);
|
|
|
|
return Ok(fileInfo);
|
|
}
|
|
}
|
|
|
|
[Route("file/deactivate"), HttpPut]
|
|
public IHttpActionResult DeactivateProgram()
|
|
{
|
|
using (NcHandler ncHandler = new NcHandler())
|
|
{
|
|
ncHandler.Connect();
|
|
|
|
CmsError cmsError = ncHandler.DeactivateProgram(out DTOActiveProgramDataModel fileInfo);
|
|
if (cmsError.IsError())
|
|
return BadRequest(cmsError.localizationKey);
|
|
|
|
return Ok(fileInfo);
|
|
}
|
|
}
|
|
|
|
[Route("upload"), HttpPost]
|
|
public async Task<IHttpActionResult> UpdloadProgramWithImage()
|
|
{
|
|
if (!Request.Content.IsMimeMultipartContent())
|
|
{
|
|
throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
|
|
}
|
|
|
|
List<FormItem> formItems = await MultipartHandler.ManageMultiPartFileAsync(Request);
|
|
|
|
foreach (FormItem item in formItems)
|
|
{
|
|
if (item.IsAFile)
|
|
{
|
|
if(item.ParameterName == "file")
|
|
{
|
|
using (NcHandler ncHandler = new NcHandler())
|
|
{
|
|
ncHandler.Connect();
|
|
|
|
File.WriteAllBytes(TEMP_FILE + item.FileName, item.Data);
|
|
|
|
CmsError cmsError = ncHandler.UploadPartProgramAndActivate(TEMP_FILE, item.FileName, out ActiveProgramDataModel programData);
|
|
if (cmsError.IsError())
|
|
return BadRequest(cmsError.localizationKey);
|
|
}
|
|
}
|
|
else if(item.ParameterName == "image")
|
|
{
|
|
File.WriteAllBytes(PART_PRG_IMAGES + item.FileName, item.Data);
|
|
}
|
|
}
|
|
}
|
|
|
|
return Ok();
|
|
}
|
|
|
|
[Route("shared_files"), HttpGet]
|
|
public IHttpActionResult GetSharedFolderFileList(string sharedPath)
|
|
{
|
|
List<object> filelist = new List<object>();
|
|
|
|
string sharedFullPath = NcConfig.SharedPath + sharedPath;
|
|
|
|
if (!Directory.Exists(sharedFullPath))
|
|
{
|
|
return NotFound();
|
|
}
|
|
|
|
foreach (string item in Directory.GetDirectories(sharedFullPath))
|
|
{
|
|
filelist.Add(new
|
|
{
|
|
Name = Path.GetFileName(item),
|
|
AbsolutePath = NcConfig.SharedPath + sharedPath,
|
|
Path = sharedPath,
|
|
IsDirectory = true
|
|
});
|
|
}
|
|
|
|
string sharedNcPath = NcConfig.SharedName + sharedPath.Replace('\\', '/');
|
|
|
|
foreach (string item in Directory.GetFiles(sharedFullPath))
|
|
{
|
|
if (VALID_FILE_EXTENSIONS.Contains(Path.GetExtension(item).ToLower()))
|
|
filelist.Add(new
|
|
{
|
|
Name = Path.GetFileName(item),
|
|
AbsolutePath = sharedNcPath + "/" + Path.GetFileName(item),
|
|
Path = sharedPath + "\\" + Path.GetFileName(item),
|
|
IsDirectory = false
|
|
});
|
|
}
|
|
|
|
return Ok(filelist);
|
|
}
|
|
}
|
|
} |