From: jocloud Date: Thu, 21 May 2020 13:35:41 +0000 (+0000) Subject: 퍼블리시 환경 재 세팅 및 컨트롤러에 STATIC 메소드 정의 X-Git-Url: https://git.insang.kr/gitweb/?a=commitdiff_plain;h=e799c09e0b8db87cfb254bdb07787a1de637df22;p=ZipProject.git 퍼블리시 환경 재 세팅 및 컨트롤러에 STATIC 메소드 정의 --- diff --git a/ZipProject/Controllers/WebZipController.cs b/ZipProject/Controllers/WebZipController.cs index 02eac29..b37a0be 100644 --- a/ZipProject/Controllers/WebZipController.cs +++ b/ZipProject/Controllers/WebZipController.cs @@ -13,78 +13,128 @@ using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json.Linq; using ZipProject.Models; -namespace ZipProject.Controllers { - public class WebZipController : Controller { +namespace ZipProject.Controllers +{ + public class WebZipController : Controller + { private readonly ISession session; - public WebZipController (IHttpContextAccessor httpContextAccessor) { + public WebZipController(IHttpContextAccessor httpContextAccessor) + { this.session = httpContextAccessor.HttpContext.Session; } // GET: // - public IActionResult Index (string partial_name) { - if (string.IsNullOrEmpty (HttpContext.Session.GetString ("lang"))) { - session.SetString ("lang", "kr"); + public IActionResult Index(string partial_name) + { + if (string.IsNullOrEmpty(HttpContext.Session.GetString("lang"))) + { + session.SetString("lang", "kr"); } - if (string.IsNullOrEmpty (partial_name)) + if (string.IsNullOrEmpty(partial_name)) ViewData["partial_page"] = "partial_zip"; else ViewData["partial_page"] = partial_name; - return View (); + return View(); } - public IActionResult En () { - session.SetString ("lang", "en"); - return Redirect ("/"); + public IActionResult En() + { + session.SetString("lang", "en"); + return Redirect("/"); } - public IActionResult Kr () { - session.SetString ("lang", "kr"); - return Redirect ("/"); + public IActionResult Kr() + { + session.SetString("lang", "kr"); + return Redirect("/"); } //파일업로드 사이즈 3GB (3(GB) * 1024(MB) * 1024(KB) * 1024(byte)) - [RequestSizeLimit (3221225472)] - public ActionResult FileUpload (string dirList, List files, string fileKeyPair, string format, string uuid) { - JObject keyPair_FileDir = JObject.Parse (fileKeyPair); + [RequestSizeLimit(3221225472)] + public ActionResult FileUpload(string dirList, List files, string fileKeyPair, string format, string uuid) + { + JObject keyPair_FileDir = JObject.Parse(fileKeyPair); Console.WriteLine(dirList); - Dictionary data = new Dictionary (); - ZipModel zipModel = new ZipModel (); + Dictionary data = new Dictionary(); + ZipModel zipModel = new ZipModel(); - Dictionary test= new Dictionary (); + Dictionary test = new Dictionary(); - string[] listDir = dirList.Split (','); + string[] listDir = dirList.Split(','); string filename = listDir[0] + "." + format; - zipModel.SetParam (keyPair_FileDir, listDir, files, uuid, uuid); - zipModel.MakeZip (); + zipModel.SetParam(keyPair_FileDir, listDir, files, uuid, uuid); + zipModel.MakeZip(); - return Json (""); + return Json(""); } - public async Task FileUploadProgress (string uuid) { - SimpleLongPolling longPolling = new SimpleLongPolling (uuid); - var msg = await longPolling.WaitAsync (); - return Json (msg); + public async Task FileUploadProgress(string uuid) + { + SimpleLongPolling longPolling = new SimpleLongPolling(uuid); + var msg = await longPolling.WaitAsync(); + return Json(msg); } - public ActionResult DownloadZip (string uuid) { - string path = Environment.CurrentDirectory + "/wwwroot/zipfiles/" + uuid + ".zip"; - byte[] file = System.IO.File.ReadAllBytes (path); - System.IO.File.Delete (path); - return File (file, "application/zip"); + public ActionResult DownloadZip(string uuid) + { + string path; +#if !DEBUG + path = Environment.CurrentDirectory + "/release/netcoreapp2.1/publish/wwwroot/zipfiles/" + uuid + ".zip"; +#else + path = Environment.CurrentDirectory + "/wwwroot/zipfiles/" + uuid + ".zip"; +#endif + byte[] file = System.IO.File.ReadAllBytes(path); + System.IO.File.Delete(path); + return File(file, "application/zip"); } - public ActionResult tst () { + public ActionResult tst() + { double now = 1; double per = 1; - now = now + (int) 1; - return Json (per == (int) 1); + now = now + (int)1; + return Json(per == (int)1); } - public ActionResult Error () { - return View (new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); + public ActionResult Error() + { + return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); + } + + [HttpGet("/static/{name}")] + public IActionResult Static(string name) + { + string path; + string re_name = name.Replace(":", "/"); + string type = re_name.Split('.')[re_name.Split('.').Count() - 1]; + string content_type; + Dictionary pair = new Dictionary(){ + {"css", "text/css"}, + {"js", "text/javascript"}, + {"json", "application/json"}, + {"etc", "Multipart/related"} + }; + + try + { + content_type = pair[type]; + } + catch (KeyNotFoundException) + { + content_type = pair["etc"]; + } + +#if !DEBUG + path = Environment.CurrentDirectory + "/release/netcoreapp2.1/publish/wwwroot/" + re_name; +#else + path = Environment.CurrentDirectory + "/wwwroot/" + re_name; +#endif + + byte[] file = System.IO.File.ReadAllBytes(path); + return File(file, content_type, "StaticFile"); } } diff --git a/ZipProject/Models/LanguagePack.cs b/ZipProject/Models/LanguagePack.cs index 9549928..6c8babd 100644 --- a/ZipProject/Models/LanguagePack.cs +++ b/ZipProject/Models/LanguagePack.cs @@ -8,11 +8,11 @@ namespace ZipProject.Models { public static string GetText (string lang, string id) { #if !DEBUG - string path = Environment.CurrentDirectory + "release/netcoreapp2.1/publish/wwwroot/Language/" + lang + ".json"; + string path = Environment.CurrentDirectory + "/release/netcoreapp2.1/publish/wwwroot/Language/" + lang + ".json"; #else string path = Environment.CurrentDirectory + "/wwwroot/Language/" + lang + ".json"; #endif - + string json = File.OpenText (path).ReadToEnd (); dynamic result = JsonConvert.DeserializeObject (json); diff --git a/ZipProject/Program.cs b/ZipProject/Program.cs index 8a75a99..acc4dc8 100644 --- a/ZipProject/Program.cs +++ b/ZipProject/Program.cs @@ -8,20 +8,23 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; -namespace ZipProject { - public class Program { - public static void Main (string[] args) { +namespace ZipProject +{ + public class Program + { + public static void Main(string[] args) + { string port; - #if !DEBUG //published - port= "5001"; - #else //debug - port= "9999"; - #endif - CreateWebHostBuilder (args).UseUrls ("http://localhost:" + port).Build ().Run (); +#if !DEBUG //published + port= "5001"; +#else //debug + port = "9999"; +#endif + CreateWebHostBuilder(args).UseUrls("http://localhost:" + port).Build().Run(); } - public static IWebHostBuilder CreateWebHostBuilder (string[] args) => - WebHost.CreateDefaultBuilder (args) - .UseStartup (); + public static IWebHostBuilder CreateWebHostBuilder(string[] args) => + WebHost.CreateDefaultBuilder(args) + .UseStartup(); } } \ No newline at end of file diff --git a/ZipProject/Startup.cs b/ZipProject/Startup.cs index 231c935..9cb0b59 100644 --- a/ZipProject/Startup.cs +++ b/ZipProject/Startup.cs @@ -46,11 +46,15 @@ namespace ZipProject { app.UseCookiePolicy (); app.UseSession (); app.UseStatusCodePages ("text/plain", "status code page, status code: {0}"); - app.UseMvc (routes => { routes.MapRoute ( name: "default", - template: "{controller=WebZip}/{action=Index}/{id?}"); + template: "{controller=WebZip}/{action=Index}/{id?}" + ); + // routes.MapRoute( + // name: "static", + // template: "static/{controller=WebZip}/{action=Static}/{name?}" + // ); }); } diff --git a/ZipProject/Views/Shared/_Layout.cshtml b/ZipProject/Views/Shared/_Layout.cshtml index 3019ee3..6e2fea8 100644 --- a/ZipProject/Views/Shared/_Layout.cshtml +++ b/ZipProject/Views/Shared/_Layout.cshtml @@ -1,4 +1,4 @@ - + @@ -15,28 +15,29 @@ @ViewData["Title"] - - + + - - + + +