mirror of
https://github.com/tengge1/ShadowEditor.git
synced 2026-01-18 15:02:09 +00:00
116 lines
3.0 KiB
C#
116 lines
3.0 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.IO;
|
||
using System.Linq;
|
||
using System.Net;
|
||
using System.Net.Http;
|
||
using System.Web;
|
||
using System.Web.Http;
|
||
using System.Web.Http.Results;
|
||
using MongoDB.Bson;
|
||
using MongoDB.Driver;
|
||
using Newtonsoft.Json.Linq;
|
||
using ShadowEditor.Server.Base;
|
||
using ShadowEditor.Server.Helpers;
|
||
using ShadowEditor.Server.MMD;
|
||
|
||
namespace ShadowEditor.Server.Controllers
|
||
{
|
||
/// <summary>
|
||
/// MMD资源控制器
|
||
/// </summary>
|
||
public class MMDController : ApiBase
|
||
{
|
||
/// <summary>
|
||
/// 获取MMD列表
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[HttpGet]
|
||
public JsonResult List()
|
||
{
|
||
var mongo = new MongoHelper();
|
||
var docs = mongo.FindAll(Constant.MMDCollectionName);
|
||
|
||
docs.Reverse();
|
||
|
||
var data = docs.Select(o => new
|
||
{
|
||
ID = o["_id"].ToString(),
|
||
Name = o["Name"].ToString(),
|
||
TotalPinYin = o["TotalPinYin"].ToString(),
|
||
FirstPinYin = o["FirstPinYin"].ToString(),
|
||
Type = o["Type"].ToString(),
|
||
Url = o["Url"].ToString(),
|
||
Thumbnail = o["Thumbnail"].ToString()
|
||
});
|
||
|
||
return Json(new
|
||
{
|
||
Code = 200,
|
||
Msg = "获取成功!",
|
||
Data = data
|
||
});
|
||
}
|
||
|
||
/// <summary>
|
||
/// 保存MMD资源
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public JsonResult Add()
|
||
{
|
||
var saver = new MMDSaver();
|
||
var result = saver.Save(HttpContext.Current);
|
||
return Json(result);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 删除MMD资源
|
||
/// </summary>
|
||
/// <param name="ID"></param>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
public JsonResult Delete(string ID)
|
||
{
|
||
var mongo = new MongoHelper();
|
||
|
||
var filter = Builders<BsonDocument>.Filter.Eq("_id", BsonObjectId.Create(ID));
|
||
var doc = mongo.FindOne(Constant.MMDCollectionName, filter);
|
||
|
||
if (doc == null)
|
||
{
|
||
return Json(new
|
||
{
|
||
Code = 300,
|
||
Msg = "该模型不存在!"
|
||
});
|
||
}
|
||
|
||
// 删除模型所在目录
|
||
var path = doc["SavePath"].ToString();
|
||
var physicalPath = HttpContext.Current.Server.MapPath(path);
|
||
|
||
try
|
||
{
|
||
Directory.Delete(physicalPath, true);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return Json(new
|
||
{
|
||
Code = 300,
|
||
Msg = ex.Message
|
||
});
|
||
}
|
||
|
||
// 删除MMD信息
|
||
mongo.DeleteOne(Constant.MMDCollectionName, filter);
|
||
|
||
return Json(new
|
||
{
|
||
Code = 200,
|
||
Msg = "删除MMD成功!"
|
||
});
|
||
}
|
||
}
|
||
}
|