Skip to content

Commit 8c4fb24

Browse files
committed
csharp-mvc: search for fileName by path added
1 parent ee0a167 commit 8c4fb24

File tree

1 file changed

+44
-26
lines changed

1 file changed

+44
-26
lines changed

web/documentserver-example/csharp-mvc/WebEditor.ashx.cs

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -614,46 +614,64 @@ private static void Reference(HttpContext context)
614614

615615
var jss = new JavaScriptSerializer();
616616
var body = jss.Deserialize<Dictionary<string, object>>(fileData);
617-
var referenceData = jss.Deserialize <Dictionary<string, object>> (jss.Serialize(body["referenceData"]));
617+
var referenceData = jss.Deserialize<Dictionary<string, object>>(jss.Serialize(body["referenceData"]));
618618
var instanceId = (string)referenceData["instanceId"];
619619
var fileKey = (string)referenceData["fileKey"];
620+
var fileName = "";
621+
var userAddress = "";
620622

621-
try
623+
if (instanceId == _Default.GetServerUrl(false))
622624
{
623625
var fileKeyObj = jss.Deserialize<Dictionary<string, object>>(fileKey);
624-
var fileName = (string)fileKeyObj["fileName"];
625-
var userAddress = (string)fileKeyObj["userAddress"];
626-
627-
var data = new Dictionary<string, object>() {
628-
{ "fileType", (Path.GetExtension(fileName) ?? "").ToLower() },
629-
{ "url", DocEditor.getDownloadUrl(fileName)},
630-
{ "directUrl", DocEditor.getDownloadUrl(fileName) },
631-
{ "referenceData", new Dictionary<string, string>()
632-
{
633-
{ "fileKey", jss.Serialize(new Dictionary<string, object>{
634-
{"fileName", fileName},
635-
{"userAddress", HttpUtility.UrlEncode(_Default.CurUserHostAddress(HttpContext.Current.Request.UserHostAddress))}
636-
})
637-
},
638-
{"instanceId", _Default.GetServerUrl(false) }
639-
},
640-
{ "path", fileName }
626+
userAddress = (string)fileKeyObj["userAddress"];
627+
if (userAddress == HttpUtility.UrlEncode(_Default.CurUserHostAddress(HttpContext.Current.Request.UserHostAddress)))
628+
{
629+
fileName = (string)fileKeyObj["fileName"];
641630
}
642-
};
631+
}
643632

644-
if (JwtManager.Enabled)
633+
if (fileName == "" && userAddress != "")
634+
{
635+
var path = (string)body["path"];
636+
path = Path.GetFileName(path);
637+
if (File.Exists(_Default.StoragePath(path, userAddress)))
645638
{
646-
var token = JwtManager.Encode(data);
647-
data.Add("token", token);
639+
fileName = path;
648640
}
649-
650-
context.Response.Write(jss.Serialize(data).Replace(@"\u0026", "&"));
651641
}
652-
catch (Exception e)
642+
643+
if (fileName == "")
653644
{
654645
context.Response.Write("{ \"error\": \"File not found!\"}");
646+
return;
655647
}
656648

649+
var data = new Dictionary<string, object>() {
650+
{ "fileType", (Path.GetExtension(fileName) ?? "").ToLower() },
651+
{ "url", DocEditor.getDownloadUrl(fileName)},
652+
{ "directUrl", DocEditor.getDownloadUrl(fileName) },
653+
{ "referenceData", new Dictionary<string, string>()
654+
{
655+
{ "fileKey", jss.Serialize(new Dictionary<string, object>{
656+
{"fileName", fileName},
657+
{"userAddress", HttpUtility.UrlEncode(_Default.CurUserHostAddress(HttpContext.Current.Request.UserHostAddress))}
658+
})
659+
},
660+
{"instanceId", _Default.GetServerUrl(false) }
661+
}
662+
},
663+
{ "path", fileName }
664+
};
665+
666+
if (JwtManager.Enabled)
667+
{
668+
var token = JwtManager.Encode(data);
669+
data.Add("token", token);
670+
}
671+
672+
context.Response.Write(jss.Serialize(data).Replace(@"\u0026", "&"));
657673
}
674+
675+
}
658676
}
659677
}

0 commit comments

Comments
 (0)