Skip to content

Commit

Permalink
csharp-mvc: 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 ee0a167 commit 54f501c
Showing 1 changed file with 52 additions and 26 deletions.
78 changes: 52 additions & 26 deletions web/documentserver-example/csharp-mvc/WebEditor.ashx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -614,46 +614,72 @@ private static void Reference(HttpContext context)

var jss = new JavaScriptSerializer();
var body = jss.Deserialize<Dictionary<string, object>>(fileData);
var referenceData = jss.Deserialize <Dictionary<string, object>> (jss.Serialize(body["referenceData"]));
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 }
userAddress = (string)fileKeyObj["userAddress"];
if (userAddress == HttpUtility.UrlEncode(_Default.CurUserHostAddress(HttpContext.Current.Request.UserHostAddress)))
{
fileName = (string)fileKeyObj["fileName"];
}
};
}

if (JwtManager.Enabled)
if (fileName == "" && userAddress != "")
{
try
{
var token = JwtManager.Encode(data);
data.Add("token", token);
var path = (string)body["path"];
path = Path.GetFileName(path);
if (File.Exists(_Default.StoragePath(path, userAddress)))
{
fileName = path;
}
}
catch
{
context.Response.Write("{ \"error\": \"Path not found!\"}");
return;
}

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<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 54f501c

Please sign in to comment.