From ee0a167708c178253dd4fc0f806408195950f4e5 Mon Sep 17 00:00:00 2001 From: rivexe Date: Fri, 17 Feb 2023 11:15:33 +0300 Subject: [PATCH] csharp: search for fileName by path added --- .../csharp/WebEditor.ashx.cs | 70 ++++++++++++------- 1 file changed, 44 insertions(+), 26 deletions(-) diff --git a/web/documentserver-example/csharp/WebEditor.ashx.cs b/web/documentserver-example/csharp/WebEditor.ashx.cs index 221db03d1..9dc5df238 100644 --- a/web/documentserver-example/csharp/WebEditor.ashx.cs +++ b/web/documentserver-example/csharp/WebEditor.ashx.cs @@ -26,6 +26,7 @@ using System.Web.Configuration; using System.Linq; using System.Net; +using System.Net.Sockets; namespace OnlineEditorsExample { @@ -435,43 +436,60 @@ private static void Reference(HttpContext context) 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 } - }; - - if (JwtManager.Enabled) + userAddress = (string)fileKeyObj["userAddress"]; + if (userAddress == HttpUtility.UrlEncode(_Default.CurUserHostAddress(HttpContext.Current.Request.UserHostAddress))) { - var token = JwtManager.Encode(data); - data.Add("token", token); + fileName = (string)fileKeyObj["fileName"]; } + } - context.Response.Write(jss.Serialize(data).Replace(@"\u0026", "&")); + if (fileName == "" && userAddress != "") + { + var path = (string)body["path"]; + path = Path.GetFileName(path); + if (File.Exists(_Default.StoragePath(path, userAddress))) + { + fileName = path; + } } - 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