106 lines
3.2 KiB
C#
106 lines
3.2 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Net;
|
|
using System.Net.Http;
|
|
using System.Reflection;
|
|
using System.Web.Http;
|
|
using 电子展板.Base;
|
|
using 电子展板.Utility;
|
|
using 电子展板.Utility.Core;
|
|
using 电子展板.Utility.Extension;
|
|
using 电子展板.Utility.Logs;
|
|
using 电子展板.Utility.Other;
|
|
using 电子展板.Utility.Web;
|
|
|
|
namespace 电子展板.Controller
|
|
{
|
|
public class IndexController : BaseController
|
|
{
|
|
/// <summary>
|
|
/// 主界面
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet, Route(""), Route("index.html")]
|
|
public ActionResult Index()
|
|
{
|
|
return Resouce("/Views/Index.html", "text/html");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获得配置信息
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet, Route("getConfig")]
|
|
public ActionResult GetConfig()
|
|
{
|
|
return Json(GlobalVariable.Config);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 上传图片。
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost, Route("uploadImage")]
|
|
public ActionResult UploadImage()
|
|
{
|
|
if (!Request.Content.IsMimeMultipartContent())
|
|
{
|
|
throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
|
|
}
|
|
string path = MyEnvironment.Root("/Upload");
|
|
var provider = new WithExtensionMultipartFormDataStreamProvider(path, UUID.StrSnowId);
|
|
var fileData = Request.Content.ReadAsMultipartAsync(provider).Result;
|
|
if (fileData.FileData.Count == 0)
|
|
{
|
|
return Error();
|
|
}
|
|
var file = fileData.FileData[0];
|
|
string virtualPath = "/Upload/" + Path.GetFileName(file.LocalFileName);
|
|
return Success("上传成功", virtualPath);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 图形显示
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
[HttpGet, Route("Upload/{id}")]
|
|
public ActionResult GetUploadFile([FromUri] string id)
|
|
{
|
|
string filePath = MyEnvironment.Root($"/Upload/{id}");
|
|
string contentType = System.Web.MimeMapping.GetMimeMapping(filePath);
|
|
return PhysicalFile(filePath, contentType, id);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 保存配置文件
|
|
/// </summary>
|
|
/// <param name="config"></param>
|
|
/// <returns></returns>
|
|
[HttpPost, Route("save")]
|
|
public ActionResult Save([FromBody] MyConfig config)
|
|
{
|
|
LogHelper.Instance.Info($"用户保存了配置:{JsonHelper.ToJson(config)}");
|
|
//保存
|
|
PropertyInfo[] propertyInfos = typeof(MyConfig).GetProperties();
|
|
foreach (PropertyInfo propertyInfo in propertyInfos)
|
|
{
|
|
object value = propertyInfo.GetValue(config);
|
|
propertyInfo.SetValue(GlobalVariable.Config, value);
|
|
}
|
|
GlobalVariable.SaveConfig();
|
|
//保存并修改界面
|
|
EventBus.Instance.Publish("save", "");
|
|
return Success();
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|