Skip to content

Commit 54f501c

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

File tree

1 file changed

+52
-26
lines changed

1 file changed

+52
-26
lines changed

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

Lines changed: 52 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -614,46 +614,72 @@ 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+
try
645636
{
646-
var token = JwtManager.Encode(data);
647-
data.Add("token", token);
637+
var path = (string)body["path"];
638+
path = Path.GetFileName(path);
639+
if (File.Exists(_Default.StoragePath(path, userAddress)))
640+
{
641+
fileName = path;
642+
}
643+
}
644+
catch
645+
{
646+
context.Response.Write("{ \"error\": \"Path not found!\"}");
647+
return;
648648
}
649-
650-
context.Response.Write(jss.Serialize(data).Replace(@"\u0026", "&"));
651649
}
652-
catch (Exception e)
650+
651+
if (fileName == "")
653652
{
654653
context.Response.Write("{ \"error\": \"File not found!\"}");
654+
return;
655655
}
656656

657+
var data = new Dictionary<string, object>() {
658+
{ "fileType", (Path.GetExtension(fileName) ?? "").ToLower() },
659+
{ "url", DocEditor.getDownloadUrl(fileName)},
660+
{ "directUrl", DocEditor.getDownloadUrl(fileName) },
661+
{ "referenceData", new Dictionary<string, string>()
662+
{
663+
{ "fileKey", jss.Serialize(new Dictionary<string, object>{
664+
{"fileName", fileName},
665+
{"userAddress", HttpUtility.UrlEncode(_Default.CurUserHostAddress(HttpContext.Current.Request.UserHostAddress))}
666+
})
667+
},
668+
{"instanceId", _Default.GetServerUrl(false) }
669+
}
670+
},
671+
{ "path", fileName }
672+
};
673+
674+
if (JwtManager.Enabled)
675+
{
676+
var token = JwtManager.Encode(data);
677+
data.Add("token", token);
678+
}
679+
680+
context.Response.Write(jss.Serialize(data).Replace(@"\u0026", "&"));
657681
}
682+
683+
}
658684
}
659685
}

0 commit comments

Comments
 (0)