diff --git a/ShadowEditor.Server/Constant.cs b/ShadowEditor.Server/Constant.cs
index d4dc2605..70f0d39d 100644
--- a/ShadowEditor.Server/Constant.cs
+++ b/ShadowEditor.Server/Constant.cs
@@ -50,5 +50,10 @@ namespace ShadowEditor.Server
/// 音频表名
///
public const string AudioCollectionName = "_Audio";
+
+ ///
+ /// MMD表名
+ ///
+ public const string MMDCollectionName = "_MMD";
}
}
diff --git a/ShadowEditor.Server/MMD/IMMDSaver.cs b/ShadowEditor.Server/MMD/IMMDSaver.cs
new file mode 100644
index 00000000..e2782af6
--- /dev/null
+++ b/ShadowEditor.Server/MMD/IMMDSaver.cs
@@ -0,0 +1,22 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Web;
+
+namespace ShadowEditor.Server.MMD
+{
+ ///
+ /// MMD保存器接口
+ ///
+ public interface IMMDSaver
+ {
+ ///
+ /// 保存模型
+ ///
+ /// Web上下文环境
+ ///
+ Result Save(HttpContext context);
+ }
+}
diff --git a/ShadowEditor.Server/MMD/MMDInfo.cs b/ShadowEditor.Server/MMD/MMDInfo.cs
new file mode 100644
index 00000000..5386817c
--- /dev/null
+++ b/ShadowEditor.Server/MMD/MMDInfo.cs
@@ -0,0 +1,74 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ShadowEditor.Server.MMD
+{
+ ///
+ /// MMD信息
+ ///
+ public class MMDInfo
+ {
+ ///
+ /// 资源名称(改名前等同于上传文件名称)
+ ///
+ public string Name { get; set; }
+
+ ///
+ /// 全拼
+ ///
+ public string TotalPinYin { get; set; }
+
+ ///
+ /// 首字母拼音
+ ///
+ public string FirstPinYin { get; set; }
+
+ ///
+ /// 资源类型
+ ///
+ public MMDType Type { get; set; }
+
+ ///
+ /// 下载地址
+ ///
+ public string Url { get; set; }
+
+ ///
+ /// 上传文件名称
+ ///
+ public string FileName { get; set; }
+
+ ///
+ /// 文件大小
+ ///
+ public int FileSize { get; set; }
+
+ ///
+ /// 文件类型
+ ///
+ public string FileType { get; set; }
+
+ ///
+ /// 保存文件名称
+ ///
+ public string SaveName { get; set; }
+
+ ///
+ /// 保存路径
+ ///
+ public string SavePath { get; set; }
+
+ ///
+ /// 上传时间
+ ///
+ public DateTime AddTime { get; set; }
+
+ ///
+ /// 缩略图
+ ///
+ public string Thumbnail { get; set; }
+ }
+}
diff --git a/ShadowEditor.Server/MMD/MMDSaver.cs b/ShadowEditor.Server/MMD/MMDSaver.cs
new file mode 100644
index 00000000..2def30e7
--- /dev/null
+++ b/ShadowEditor.Server/MMD/MMDSaver.cs
@@ -0,0 +1,114 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Web;
+using MongoDB.Bson;
+using ShadowEditor.Server.Helpers;
+
+namespace ShadowEditor.Server.MMD
+{
+ ///
+ /// MMD保存器
+ ///
+ public class MMDSaver : IMMDSaver
+ {
+ public Result Save(HttpContext context)
+ {
+ var Request = context.Request;
+ var Server = context.Server;
+
+ // 文件信息
+ var file = Request.Files[0];
+ var fileName = file.FileName;
+ var fileSize = file.ContentLength;
+ var fileType = file.ContentType;
+ var fileExt = Path.GetExtension(fileName);
+ var fileNameWithoutExt = Path.GetFileNameWithoutExtension(fileName);
+
+ if (fileExt == null || fileExt.ToLower() != ".zip")
+ {
+ return new Result
+ {
+ Code = 300,
+ Msg = "只允许上传zip格式文件!"
+ };
+ }
+
+ // 保存文件
+ var now = DateTime.Now;
+
+ var savePath = $"/Upload/MMD/{now.ToString("yyyyMMddHHmmss")}";
+ var physicalPath = Server.MapPath(savePath);
+
+ var tempPath = physicalPath + "\\temp"; // zip压缩文件临时保存目录
+
+ if (!Directory.Exists(tempPath))
+ {
+ Directory.CreateDirectory(tempPath);
+ }
+
+ file.SaveAs($"{tempPath}\\{fileName}");
+
+ // 解压文件
+ ZipHelper.Unzip($"{tempPath}\\{fileName}", physicalPath);
+
+ // 删除临时目录
+ Directory.Delete(tempPath, true);
+
+ // 判断文件类型
+ string entryFileName = null;
+ var meshType = MMDType.unknown;
+
+ var files = Directory.GetFiles(physicalPath);
+
+ if (files.Where(o => o.ToLower().EndsWith(".pmd")).Count() > 0) // 模型文件
+ {
+ entryFileName = files.Where(o => o.ToLower().EndsWith(".pmd")).FirstOrDefault();
+ entryFileName = $"{savePath}/{Path.GetFileName(entryFileName)}";
+ meshType = MMDType.pmd;
+ }
+ else if (files.Where(o => o.ToLower().EndsWith(".pmx")).Count() > 0) // 模型文件
+ {
+ entryFileName = files.Where(o => o.ToLower().EndsWith(".pmx")).FirstOrDefault();
+ entryFileName = $"{savePath}/{Path.GetFileName(entryFileName)}";
+ meshType = MMDType.pmx;
+ }
+ else if (files.Where(o => o.ToLower().EndsWith(".vmd")).Count() > 0) // 动画文件
+ {
+ entryFileName = files.Where(o => o.ToLower().EndsWith(".vmd")).FirstOrDefault();
+ entryFileName = $"{savePath}/{Path.GetFileName(entryFileName)}";
+ meshType = MMDType.vmd;
+ }
+
+ var pinyin = PinYinHelper.GetTotalPinYin(fileNameWithoutExt);
+
+ // 保存到Mongo
+ var mongo = new MongoHelper();
+
+ var doc = new BsonDocument();
+ doc["AddTime"] = BsonDateTime.Create(now);
+ doc["FileName"] = fileName;
+ doc["FileSize"] = fileSize;
+ doc["FileType"] = fileType;
+ doc["FirstPinYin"] = string.Join("", pinyin.FirstPinYin);
+ doc["Name"] = fileNameWithoutExt;
+ doc["SaveName"] = fileName;
+ doc["SavePath"] = savePath;
+ doc["Thumbnail"] = "";
+ doc["TotalPinYin"] = string.Join("", pinyin.TotalPinYin);
+ doc["Type"] = meshType.ToString();
+ doc["Url"] = entryFileName;
+
+ mongo.InsertOne(Constant.MMDCollectionName, doc);
+
+ return new Result
+ {
+ Code = 200,
+ Msg = "上传成功!"
+ };
+ }
+ }
+}
diff --git a/ShadowEditor.Server/MMD/MMDType.cs b/ShadowEditor.Server/MMD/MMDType.cs
new file mode 100644
index 00000000..4e7c7464
--- /dev/null
+++ b/ShadowEditor.Server/MMD/MMDType.cs
@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ShadowEditor.Server.MMD
+{
+ ///
+ /// 资源类型
+ ///
+ public enum MMDType
+ {
+ unknown, // 未知类型
+ pmd, // 模型文件
+ pmx, // 模型文件
+ vmd, // 动画文件
+ }
+}
diff --git a/ShadowEditor.Server/ShadowEditor.Server.csproj b/ShadowEditor.Server/ShadowEditor.Server.csproj
index 4f9b8ad2..e3c71321 100644
--- a/ShadowEditor.Server/ShadowEditor.Server.csproj
+++ b/ShadowEditor.Server/ShadowEditor.Server.csproj
@@ -105,6 +105,7 @@
+
@@ -119,6 +120,10 @@
+
+
+
+