using Attribute; using Common; using Dto; using Vo; using Enums; using Filters; using Infrastructure; using Infrastructure.Model; using Mapster; using Microsoft.AspNetCore.Mvc; using Middleware; using Model; using Services; using Model.Base; using System.IO.Compression; using Aliyun.OSS; namespace Controllers { /// /// PageUpdateInfo)Controller /// // [Route("PageUpdateInfo")] // [ApiExplorerSettings(GroupName = "PageUpdateInfo")] public class PageUpdateInfoController : BaseController { private readonly IPageUpdateInfoService _PageUpdateInfoService; private readonly IAppBottomNavsService _AppBottomNavsService; private readonly IFileUpdateInfoService _FileUpdateInfoService; private readonly IAppSourceSetService _AppSourceSetService; public PageUpdateInfoController(IPageUpdateInfoService PageUpdateInfoService, IAppBottomNavsService AppBottomNavsService, IFileUpdateInfoService FileUpdateInfoService, IAppSourceSetService AppSourceSetService) { _PageUpdateInfoService = PageUpdateInfoService; _AppBottomNavsService = AppBottomNavsService; _FileUpdateInfoService = FileUpdateInfoService; _AppSourceSetService = AppSourceSetService; } public string makeAppInitData(OssClient client, AppSourceSet set, MakeAppInitDataDto parm, string EncryptType = "des") { string AppInfoList = _AppBottomNavsService.makeAppInitData(parm.kind, parm.appVersion, EncryptType); string FileInfoList = _FileUpdateInfoService.makeAppInitData(parm.kind, parm.appVersion, EncryptType); string PageInfoList = _PageUpdateInfoService.makeAppInitData(client, set, parm.kind, parm.appVersion, EncryptType); return AppInfoList + "#cut#" + FileInfoList + "#cut#" + PageInfoList; } [HttpGet] [Route("/noauth/pageinfo")] public string page(string v = "4.2.0", string k = "creater", string c = "", int p = 0, string et = "des") { var set = _AppSourceSetService.GetFirst(m => m.projectId == p && m.kind == k); if(set != null) { var client = new OssClient(set.endPoint, set.accessKeyId, set.accessKeySecret); string appini = makeAppInitData(client, set, new MakeAppInitDataDto() { kind = k, appVersion = v, projectId = p, }, et); if (!string.IsNullOrEmpty(appini)) { if (appini.Contains("#cut#")) { string[] appinidata = appini.Split(new string[] { "#cut#" }, StringSplitOptions.None); string AppInfoList = appinidata[0]; string SystemSet = appinidata[1]; string PageInfoList = appinidata[2]; string GotoPages = appinidata[3]; string LibFile = appinidata[4]; AppInfoList = System.Text.RegularExpressions.Regex.Unescape(AppInfoList); SystemSet = System.Text.RegularExpressions.Regex.Unescape(SystemSet); PageInfoList = System.Text.RegularExpressions.Regex.Unescape(PageInfoList); GotoPages = System.Text.RegularExpressions.Regex.Unescape(GotoPages); LibFile = System.Text.RegularExpressions.Regex.Unescape(LibFile); string startPath = ""; string zipPath = ""; string zipKey = ""; if(c == "ios") { Function.WritePage("ini", "AppInfoList.ini", AppInfoList); Function.WritePage("ini", "SystemSet.ini", SystemSet); Function.WritePage("ini", "PageInfoList.ini", PageInfoList); Function.WritePage("ini", "GotoPages.ini", GotoPages); Function.WritePage("ini", "LibFile.ini", LibFile); startPath = Function.getPath("ini"); zipPath = Function.getPath("ini.zip"); zipKey = "ini.zip"; } else { Function.WritePage("txt", "AppInfoList.txt", AppInfoList); Function.WritePage("txt", "SystemSet.txt", SystemSet); Function.WritePage("txt", "PageInfoList.txt", PageInfoList); Function.WritePage("txt", "GotoPages.txt", GotoPages); Function.WritePage("txt", "LibFile.txt", LibFile); startPath = Function.getPath(path_str: "txt"); zipPath = Function.getPath("txt.zip"); zipKey = "txt.zip"; } if(System.IO.File.Exists(zipPath)) { System.IO.File.Delete(zipPath); } ZipFile.CreateFromDirectory(startPath, zipPath); // 上传文件 var result = client.PutObject(set.bucketName, zipKey, zipPath, new ObjectMetadata() { ExpirationTime = DateTime.Parse("2050-12-31 23:59:59") }); if (!string.IsNullOrEmpty(result.ETag)) { if (result.ETag.Length == 32) { if (System.IO.File.Exists(zipPath)) { System.IO.File.Delete(zipPath); } } } var url = client.GeneratePresignedUri(set.bucketName, zipKey); return url.ToString(); } } } return "fail"; } [HttpGet] [Route("/noauth/static")] public string staticFileUpload(int p, string v = "4.2.0", string k = "creater") { var set = _AppSourceSetService.GetFirst(m => m.projectId == p && m.kind == k); if(set != null) { var client = new OssClient(set.endPoint, set.accessKeyId, set.accessKeySecret); var list = _FileUpdateInfoService.GetList(m => m.kind == k && m.appVersion == v); foreach(var sub in list) { string key = set.path + "/" + v + "/" + sub.path + sub.fileName; string localPath = "/staticFile/" + key; var fileObj = client.GetObject(set.bucketName, key); System.IO.MemoryStream stream = new System.IO.MemoryStream(); fileObj.ResponseStream.CopyTo(stream); var fileData = stream.ToArray(); if(fileData.Length > 0) { string fileFullName = Function.getPath(localPath); string folder = fileFullName.Substring(0, fileFullName.LastIndexOf("/")); if(!System.IO.Directory.Exists(folder)) { System.IO.Directory.CreateDirectory(folder); } System.IO.File.WriteAllBytes(fileFullName, fileData); } } string startPath = Function.getPath("/staticFile/" + set.path + "/" + v + "/"); string filePath = "/staticOutFile/" + set.path + "/" + v + "/static.zip"; string zipKey = set.path + "/" + v + "/static.zip"; string zipPath = Function.getPath(filePath); string zipFolder = zipPath.Substring(0, zipPath.LastIndexOf("/")); if(!System.IO.Directory.Exists(zipFolder)) { System.IO.Directory.CreateDirectory(zipFolder); } if(System.IO.File.Exists(zipPath)) { System.IO.File.Delete(zipPath); } ZipFile.CreateFromDirectory(startPath, zipPath); // 上传文件 var result = client.PutObject(set.bucketName, zipKey, zipPath, new ObjectMetadata() { ExpirationTime = DateTime.Parse("2050-12-31 23:59:59") }); if (!string.IsNullOrEmpty(result.ETag)) { if (result.ETag.Length == 32) { if (System.IO.File.Exists(zipPath)) { System.IO.File.Delete(zipPath); } } } var url = client.GeneratePresignedUri(set.bucketName, zipKey); return url.ToString(); } return "fail"; } } }