[Frontend][圖資管理] 下載dwg檔程序調整
This commit is contained in:
		
							parent
							
								
									7802738fa4
								
							
						
					
					
						commit
						e4a3cc9597
					
				@ -139,6 +139,8 @@
 | 
				
			|||||||
    var uploader = {};
 | 
					    var uploader = {};
 | 
				
			||||||
    var uploadFiles = {};
 | 
					    var uploadFiles = {};
 | 
				
			||||||
    var curActGraid = 0;
 | 
					    var curActGraid = 0;
 | 
				
			||||||
 | 
					    var cookies = new YourTeam.Utility.Cookie();
 | 
				
			||||||
 | 
					    var token = cookies.get("JWT-Authorization");
 | 
				
			||||||
    $(function () {
 | 
					    $(function () {
 | 
				
			||||||
        initList();
 | 
					        initList();
 | 
				
			||||||
        initDropzone();
 | 
					        initDropzone();
 | 
				
			||||||
@ -283,19 +285,21 @@
 | 
				
			|||||||
    })
 | 
					    })
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    onEvent("click", "a[id^=oriDwgDown]", function () {
 | 
					    onEvent("click", "a[id^=oriDwgDown]", function () {
 | 
				
			||||||
        let cookies = new YourTeam.Utility.Cookie();
 | 
					 | 
				
			||||||
        let rowData = graTable.row($(this).closest("tr")).data();
 | 
					        let rowData = graTable.row($(this).closest("tr")).data();
 | 
				
			||||||
        let apiUrl = baseApiUrl + `/File/Download?type=graph&savename=${rowData.oriSavName}&oriname=${rowData.oriOrgName}`;
 | 
					        let apiUrl = baseApiUrl + `/File/Download?type=graph&savename=${rowData.oriSavName}&oriname=${rowData.oriOrgName}`;
 | 
				
			||||||
        let extname = rowData.oriOrgName?.split(".").slice(-1) || "dwg";
 | 
					        let extname = rowData.oriOrgName?.split(".").slice(-1) || "dwg";
 | 
				
			||||||
        download(cookies.get("JWT-Authorization"), apiUrl, rowData.name + "_原設計圖" + "." + extname);
 | 
					        download(token, apiUrl, rowData.name + "_原設計圖" + "." + extname, function () {
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
    })
 | 
					    })
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    onEvent("click", "a[id^=donDwgDown]", function () {
 | 
					    onEvent("click", "a[id^=donDwgDown]", function () {
 | 
				
			||||||
        let cookies = new YourTeam.Utility.Cookie();
 | 
					 | 
				
			||||||
        let rowData = graTable.row($(this).closest("tr")).data();
 | 
					        let rowData = graTable.row($(this).closest("tr")).data();
 | 
				
			||||||
        let apiUrl = baseApiUrl + `/File/Download?type=graph&savename=${rowData.donSavName}&oriname=${rowData.donOrgName}`;
 | 
					        let apiUrl = baseApiUrl + `/File/Download?type=graph&savename=${rowData.donSavName}&oriname=${rowData.donOrgName}`;
 | 
				
			||||||
        let extname = rowData.donOrgName?.split(".").slice(-1) || "dwg";
 | 
					        let extname = rowData.donOrgName?.split(".").slice(-1) || "dwg";
 | 
				
			||||||
        download(cookies.get("JWT-Authorization"), apiUrl, rowData.name + "_竣工圖" + "." + extname);
 | 
					        download(token, apiUrl, rowData.name + "_竣工圖" + "." + extname, function () {
 | 
				
			||||||
 | 
					           
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
    })
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // 上傳檔案
 | 
					    // 上傳檔案
 | 
				
			||||||
 | 
				
			|||||||
@ -2292,6 +2292,7 @@ License: You must have a valid license purchased only from wrapbootstrap.com (li
 | 
				
			|||||||
                    })
 | 
					                    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    endPageLoading();
 | 
					                    endPageLoading();
 | 
				
			||||||
 | 
					                    $(".yt-alert").YTAlert().hide();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    if (typeof timeOuters != "undefined") {
 | 
					                    if (typeof timeOuters != "undefined") {
 | 
				
			||||||
                        $.each(timeOuters, (idx, timeOut) => {
 | 
					                        $.each(timeOuters, (idx, timeOut) => {
 | 
				
			||||||
 | 
				
			|||||||
@ -1349,7 +1349,7 @@ function toBool(boolstr) {
 | 
				
			|||||||
 * @param {any} url
 | 
					 * @param {any} url
 | 
				
			||||||
 * @param {any} filename
 | 
					 * @param {any} filename
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
async function download(token,url, filename) {
 | 
					async function download(token,url, filename,callback = null) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let toDataURL = function (url) {
 | 
					    let toDataURL = function (url) {
 | 
				
			||||||
        return fetch(url, {
 | 
					        return fetch(url, {
 | 
				
			||||||
@ -1378,6 +1378,7 @@ async function download(token,url, filename) {
 | 
				
			|||||||
        document.body.appendChild(a);
 | 
					        document.body.appendChild(a);
 | 
				
			||||||
        a.click();
 | 
					        a.click();
 | 
				
			||||||
        document.body.removeChild(a);
 | 
					        document.body.removeChild(a);
 | 
				
			||||||
 | 
					        callback ? callback() : "";
 | 
				
			||||||
        return true;
 | 
					        return true;
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        return false;
 | 
					        return false;
 | 
				
			||||||
 | 
				
			|||||||
@ -8,6 +8,10 @@ using System.Collections.Generic;
 | 
				
			|||||||
using System.IdentityModel.Tokens.Jwt;
 | 
					using System.IdentityModel.Tokens.Jwt;
 | 
				
			||||||
using System.IO;
 | 
					using System.IO;
 | 
				
			||||||
using System.Net;
 | 
					using System.Net;
 | 
				
			||||||
 | 
					using System.Web;
 | 
				
			||||||
 | 
					using System.Threading.Tasks;
 | 
				
			||||||
 | 
					using Microsoft.AspNetCore.Http.Features;
 | 
				
			||||||
 | 
					using NPOI.HPSF;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace FrontendWebApi.ApiControllers
 | 
					namespace FrontendWebApi.ApiControllers
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@ -27,7 +31,7 @@ namespace FrontendWebApi.ApiControllers
 | 
				
			|||||||
            graphManageFileSaveAsPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "upload", "graph_manage");
 | 
					            graphManageFileSaveAsPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "upload", "graph_manage");
 | 
				
			||||||
            operationFileSaveAsPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "upload", "operation");
 | 
					            operationFileSaveAsPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "upload", "operation");
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        public bool Download([FromQuery]string type , string savename, string oriname)
 | 
					        public ActionResult Download([FromQuery]string type , string savename)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            var path = "";
 | 
					            var path = "";
 | 
				
			||||||
            if (type == "graph")
 | 
					            if (type == "graph")
 | 
				
			||||||
@ -43,26 +47,27 @@ namespace FrontendWebApi.ApiControllers
 | 
				
			|||||||
            {
 | 
					            {
 | 
				
			||||||
                try
 | 
					                try
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    FileInfo xpath_file = new FileInfo(path);  //要 using System.IO;
 | 
					                    var auth = HttpContext.Request.Headers["Authorization"];
 | 
				
			||||||
 | 
					                    var token = auth.ToString()?.Split("Bearer ")[1];
 | 
				
			||||||
                    // 將傳入的檔名以 FileInfo 來進行解析(只以字串無法做)
 | 
					                    var jwt = new JwtSecurityTokenHandler().ReadJwtToken(token);
 | 
				
			||||||
                    HttpContext.Response.Clear(); //清除buffer
 | 
					                    if (jwt == null)
 | 
				
			||||||
                    HttpContext.Response.ContentType = "application/octet-stream";
 | 
					                        return Unauthorized(HttpStatusCode.Unauthorized);
 | 
				
			||||||
                    // 檔案類型還有下列幾種"application/pdf"、"application/vnd.ms-excel"、"text/xml"、"text/HTML"、"image/JPEG"、"image/GIF"
 | 
					                    else if (!System.IO.File.Exists(path))
 | 
				
			||||||
                    HttpContext.Response.Headers.Add("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(oriname, System.Text.Encoding.UTF8));
 | 
					                        return NotFound("找不到文件");
 | 
				
			||||||
                    // 考慮 utf-8 檔名問題,以 out_file 設定另存的檔名
 | 
					 | 
				
			||||||
                    HttpContext.Response.Headers.Add("Content-Length", xpath_file.Length.ToString()); //表頭加入檔案大小
 | 
					 | 
				
			||||||
                    HttpContext.Response.SendFileAsync(xpath_file.FullName);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    return true;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    var bufferingFeature = HttpContext.Features.Get<IHttpResponseBodyFeature>();
 | 
				
			||||||
 | 
					                    bufferingFeature?.DisableBuffering();
 | 
				
			||||||
 | 
					                    var content = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
 | 
				
			||||||
 | 
					                    var response = File(content, "application/octet-stream");//FileStreamResult
 | 
				
			||||||
 | 
					                    
 | 
				
			||||||
 | 
					                    return response;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                catch (Exception)
 | 
					                catch (Exception)
 | 
				
			||||||
                { return false; }
 | 
					                { return null; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            else
 | 
					            else
 | 
				
			||||||
                return false;
 | 
					                return null;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        [HttpGet]
 | 
					        [HttpGet]
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user