Skip to content

Commit

Permalink
csharp: search for fileName by path added
Browse files Browse the repository at this point in the history
  • Loading branch information
rivexe committed Feb 17, 2023
1 parent f76c611 commit ee0a167
Showing 1 changed file with 44 additions and 26 deletions.
70 changes: 44 additions & 26 deletions web/documentserver-example/csharp/WebEditor.ashx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
using System.Web.Configuration;
using System.Linq;
using System.Net;
using System.Net.Sockets;

namespace OnlineEditorsExample
{
Expand Down Expand Up @@ -435,43 +436,60 @@ private static void Reference(HttpContext context)
var referenceData = jss.Deserialize <Dictionary<string, object>> (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<Dictionary<string, object>>(fileKey);
var fileName = (string)fileKeyObj["fileName"];
var userAddress = (string)fileKeyObj["userAddress"];

var data = new Dictionary<string, object>() {
{ "fileType", (Path.GetExtension(fileName) ?? "").ToLower() },
{ "url", DocEditor.getDownloadUrl(fileName)},
{ "directUrl", DocEditor.getDownloadUrl(fileName) },
{ "referenceData", new Dictionary<string, string>()
{
{ "fileKey", jss.Serialize(new Dictionary<string, object>{
{"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<string, object>() {
{ "fileType", (Path.GetExtension(fileName) ?? "").ToLower() },
{ "url", DocEditor.getDownloadUrl(fileName)},
{ "directUrl", DocEditor.getDownloadUrl(fileName) },
{ "referenceData", new Dictionary<string, string>()
{
{ "fileKey", jss.Serialize(new Dictionary<string, object>{
{"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", "&"));

}
}
}

0 comments on commit ee0a167

Please sign in to comment.