From 8c4fb244c005b7f4e2e68d5f4f77e0d93dc6746a Mon Sep 17 00:00:00 2001 From: rivexe Date: Fri, 17 Feb 2023 11:19:42 +0300 Subject: [PATCH] csharp-mvc: search for fileName by path added --- .../csharp-mvc/WebEditor.ashx.cs | 70 ++++++++++++------- 1 file changed, 44 insertions(+), 26 deletions(-) diff --git a/web/documentserver-example/csharp-mvc/WebEditor.ashx.cs b/web/documentserver-example/csharp-mvc/WebEditor.ashx.cs index 3e924e3bd..344f25473 100644 --- a/web/documentserver-example/csharp-mvc/WebEditor.ashx.cs +++ b/web/documentserver-example/csharp-mvc/WebEditor.ashx.cs @@ -614,46 +614,64 @@ private static void Reference(HttpContext context) var jss = new JavaScriptSerializer(); var body = jss.Deserialize>(fileData); - var referenceData = jss.Deserialize > (jss.Serialize(body["referenceData"])); + var referenceData = jss.Deserialize>(jss.Serialize(body["referenceData"])); var instanceId = (string)referenceData["instanceId"]; var fileKey = (string)referenceData["fileKey"]; + var fileName = ""; + var userAddress = ""; - try + if (instanceId == _Default.GetServerUrl(false)) { var fileKeyObj = jss.Deserialize>(fileKey); - var fileName = (string)fileKeyObj["fileName"]; - var userAddress = (string)fileKeyObj["userAddress"]; - - var data = new Dictionary() { - { "fileType", (Path.GetExtension(fileName) ?? "").ToLower() }, - { "url", DocEditor.getDownloadUrl(fileName)}, - { "directUrl", DocEditor.getDownloadUrl(fileName) }, - { "referenceData", new Dictionary() - { - { "fileKey", jss.Serialize(new Dictionary{ - {"fileName", fileName}, - {"userAddress", HttpUtility.UrlEncode(_Default.CurUserHostAddress(HttpContext.Current.Request.UserHostAddress))} - }) - }, - {"instanceId", _Default.GetServerUrl(false) } - }, - { "path", fileName } + userAddress = (string)fileKeyObj["userAddress"]; + if (userAddress == HttpUtility.UrlEncode(_Default.CurUserHostAddress(HttpContext.Current.Request.UserHostAddress))) + { + fileName = (string)fileKeyObj["fileName"]; } - }; + } - if (JwtManager.Enabled) + if (fileName == "" && userAddress != "") + { + var path = (string)body["path"]; + path = Path.GetFileName(path); + if (File.Exists(_Default.StoragePath(path, userAddress))) { - var token = JwtManager.Encode(data); - data.Add("token", token); + fileName = path; } - - context.Response.Write(jss.Serialize(data).Replace(@"\u0026", "&")); } - catch (Exception e) + + if (fileName == "") { context.Response.Write("{ \"error\": \"File not found!\"}"); + return; } + var data = new Dictionary() { + { "fileType", (Path.GetExtension(fileName) ?? "").ToLower() }, + { "url", DocEditor.getDownloadUrl(fileName)}, + { "directUrl", DocEditor.getDownloadUrl(fileName) }, + { "referenceData", new Dictionary() + { + { "fileKey", jss.Serialize(new Dictionary{ + {"fileName", fileName}, + {"userAddress", HttpUtility.UrlEncode(_Default.CurUserHostAddress(HttpContext.Current.Request.UserHostAddress))} + }) + }, + {"instanceId", _Default.GetServerUrl(false) } + } + }, + { "path", fileName } + }; + + if (JwtManager.Enabled) + { + var token = JwtManager.Encode(data); + data.Add("token", token); + } + + context.Response.Write(jss.Serialize(data).Replace(@"\u0026", "&")); } + + } } } \ No newline at end of file