PageUpdateInfoController.cs 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. using Attribute;
  2. using Common;
  3. using Dto;
  4. using Vo;
  5. using Enums;
  6. using Filters;
  7. using Infrastructure;
  8. using Infrastructure.Model;
  9. using Mapster;
  10. using Microsoft.AspNetCore.Mvc;
  11. using Middleware;
  12. using Model;
  13. using Services;
  14. using Model.Base;
  15. using System.IO.Compression;
  16. using Aliyun.OSS;
  17. namespace Controllers
  18. {
  19. /// <summary>
  20. /// PageUpdateInfo)Controller
  21. /// </summary>
  22. // [Route("PageUpdateInfo")]
  23. // [ApiExplorerSettings(GroupName = "PageUpdateInfo")]
  24. public class PageUpdateInfoController : BaseController
  25. {
  26. private readonly IPageUpdateInfoService _PageUpdateInfoService;
  27. private readonly IAppBottomNavsService _AppBottomNavsService;
  28. private readonly IFileUpdateInfoService _FileUpdateInfoService;
  29. private readonly IAppSourceSetService _AppSourceSetService;
  30. public PageUpdateInfoController(IPageUpdateInfoService PageUpdateInfoService, IAppBottomNavsService AppBottomNavsService, IFileUpdateInfoService FileUpdateInfoService, IAppSourceSetService AppSourceSetService)
  31. {
  32. _PageUpdateInfoService = PageUpdateInfoService;
  33. _AppBottomNavsService = AppBottomNavsService;
  34. _FileUpdateInfoService = FileUpdateInfoService;
  35. _AppSourceSetService = AppSourceSetService;
  36. }
  37. public string makeAppInitData(OssClient client, AppSourceSet set, MakeAppInitDataDto parm, string EncryptType = "des")
  38. {
  39. string AppInfoList = _AppBottomNavsService.makeAppInitData(parm.kind, parm.appVersion, EncryptType);
  40. string FileInfoList = _FileUpdateInfoService.makeAppInitData(parm.kind, parm.appVersion, EncryptType);
  41. string PageInfoList = _PageUpdateInfoService.makeAppInitData(client, set, parm.kind, parm.appVersion, EncryptType);
  42. return AppInfoList + "#cut#" + FileInfoList + "#cut#" + PageInfoList;
  43. }
  44. [HttpGet]
  45. [Route("/noauth/pageinfo")]
  46. public string page(string v = "4.2.0", string k = "creater", string c = "", int p = 0, string et = "des")
  47. {
  48. var set = _AppSourceSetService.GetFirst(m => m.projectId == p && m.kind == k);
  49. if(set != null)
  50. {
  51. var client = new OssClient(set.endPoint, set.accessKeyId, set.accessKeySecret);
  52. string appini = makeAppInitData(client, set, new MakeAppInitDataDto()
  53. {
  54. kind = k,
  55. appVersion = v,
  56. projectId = p,
  57. }, et);
  58. if (!string.IsNullOrEmpty(appini))
  59. {
  60. if (appini.Contains("#cut#"))
  61. {
  62. string[] appinidata = appini.Split(new string[] { "#cut#" }, StringSplitOptions.None);
  63. string AppInfoList = appinidata[0];
  64. string SystemSet = appinidata[1];
  65. string PageInfoList = appinidata[2];
  66. string GotoPages = appinidata[3];
  67. string LibFile = appinidata[4];
  68. AppInfoList = System.Text.RegularExpressions.Regex.Unescape(AppInfoList);
  69. SystemSet = System.Text.RegularExpressions.Regex.Unescape(SystemSet);
  70. PageInfoList = System.Text.RegularExpressions.Regex.Unescape(PageInfoList);
  71. GotoPages = System.Text.RegularExpressions.Regex.Unescape(GotoPages);
  72. LibFile = System.Text.RegularExpressions.Regex.Unescape(LibFile);
  73. string startPath = "";
  74. string zipPath = "";
  75. string zipKey = "";
  76. if(c == "ios")
  77. {
  78. Function.WritePage("ini", "AppInfoList.ini", AppInfoList);
  79. Function.WritePage("ini", "SystemSet.ini", SystemSet);
  80. Function.WritePage("ini", "PageInfoList.ini", PageInfoList);
  81. Function.WritePage("ini", "GotoPages.ini", GotoPages);
  82. Function.WritePage("ini", "LibFile.ini", LibFile);
  83. startPath = Function.getPath("ini");
  84. zipPath = Function.getPath("ini.zip");
  85. zipKey = "ini.zip";
  86. }
  87. else
  88. {
  89. Function.WritePage("txt", "AppInfoList.txt", AppInfoList);
  90. Function.WritePage("txt", "SystemSet.txt", SystemSet);
  91. Function.WritePage("txt", "PageInfoList.txt", PageInfoList);
  92. Function.WritePage("txt", "GotoPages.txt", GotoPages);
  93. Function.WritePage("txt", "LibFile.txt", LibFile);
  94. startPath = Function.getPath(path_str: "txt");
  95. zipPath = Function.getPath("txt.zip");
  96. zipKey = "txt.zip";
  97. }
  98. if(System.IO.File.Exists(zipPath))
  99. {
  100. System.IO.File.Delete(zipPath);
  101. }
  102. ZipFile.CreateFromDirectory(startPath, zipPath);
  103. // 上传文件
  104. var result = client.PutObject(set.bucketName, zipKey, zipPath, new ObjectMetadata()
  105. {
  106. ExpirationTime = DateTime.Parse("2050-12-31 23:59:59")
  107. });
  108. if (!string.IsNullOrEmpty(result.ETag))
  109. {
  110. if (result.ETag.Length == 32)
  111. {
  112. if (System.IO.File.Exists(zipPath))
  113. {
  114. System.IO.File.Delete(zipPath);
  115. }
  116. }
  117. }
  118. var url = client.GeneratePresignedUri(set.bucketName, zipKey);
  119. return url.ToString();
  120. }
  121. }
  122. }
  123. return "fail";
  124. }
  125. [HttpGet]
  126. [Route("/noauth/static")]
  127. public string staticFileUpload(int p, string v = "4.2.0", string k = "creater")
  128. {
  129. var set = _AppSourceSetService.GetFirst(m => m.projectId == p && m.kind == k);
  130. if(set != null)
  131. {
  132. var client = new OssClient(set.endPoint, set.accessKeyId, set.accessKeySecret);
  133. var list = _FileUpdateInfoService.GetList(m => m.kind == k && m.appVersion == v);
  134. foreach(var sub in list)
  135. {
  136. string key = set.path + "/" + v + "/" + sub.path + sub.fileName;
  137. string localPath = "/staticFile/" + key;
  138. var fileObj = client.GetObject(set.bucketName, key);
  139. System.IO.MemoryStream stream = new System.IO.MemoryStream();
  140. fileObj.ResponseStream.CopyTo(stream);
  141. var fileData = stream.ToArray();
  142. if(fileData.Length > 0)
  143. {
  144. string fileFullName = Function.getPath(localPath);
  145. string folder = fileFullName.Substring(0, fileFullName.LastIndexOf("/"));
  146. if(!System.IO.Directory.Exists(folder))
  147. {
  148. System.IO.Directory.CreateDirectory(folder);
  149. }
  150. System.IO.File.WriteAllBytes(fileFullName, fileData);
  151. }
  152. }
  153. string startPath = Function.getPath("/staticFile/" + set.path + "/" + v + "/");
  154. string filePath = "/staticOutFile/" + set.path + "/" + v + "/static.zip";
  155. string zipKey = set.path + "/" + v + "/static.zip";
  156. string zipPath = Function.getPath(filePath);
  157. string zipFolder = zipPath.Substring(0, zipPath.LastIndexOf("/"));
  158. if(!System.IO.Directory.Exists(zipFolder))
  159. {
  160. System.IO.Directory.CreateDirectory(zipFolder);
  161. }
  162. if(System.IO.File.Exists(zipPath))
  163. {
  164. System.IO.File.Delete(zipPath);
  165. }
  166. ZipFile.CreateFromDirectory(startPath, zipPath);
  167. // 上传文件
  168. var result = client.PutObject(set.bucketName, zipKey, zipPath, new ObjectMetadata()
  169. {
  170. ExpirationTime = DateTime.Parse("2050-12-31 23:59:59")
  171. });
  172. if (!string.IsNullOrEmpty(result.ETag))
  173. {
  174. if (result.ETag.Length == 32)
  175. {
  176. if (System.IO.File.Exists(zipPath))
  177. {
  178. System.IO.File.Delete(zipPath);
  179. }
  180. }
  181. }
  182. var url = client.GeneratePresignedUri(set.bucketName, zipKey);
  183. return url.ToString();
  184. }
  185. return "fail";
  186. }
  187. }
  188. }