This commit is contained in:
Sergey Linnik
2022-02-11 10:54:03 +03:00
parent 03332b3cd9
commit c4c819c513
16 changed files with 43 additions and 36 deletions

View File

@ -165,18 +165,20 @@ namespace OnlineEditorsExample
// get the path to the history file version
public static string HistoryPath(string fileName, string userAddress, string version, string file)
{
{
var directory = "";
if (Path.IsPathRooted(WebConfigurationManager.AppSettings["storage-path"]))
{
directory = WebConfigurationManager.AppSettings["storage-path"] + "\\";
}else
}
else
{
directory = HttpRuntime.AppDomainAppPath + WebConfigurationManager.AppSettings["storage-path"] + CurUserHostAddress(userAddress) + "\\";
}
var filepath = directory + Path.GetFileName(fileName) + "-hist" + "\\" + version + "\\" + file;
return filepath;
}
// get the path to the forcesaved file version
public static string ForcesavePath(string fileName, string userAddress, Boolean create)
{

View File

@ -358,11 +358,12 @@ namespace OnlineEditorsExample
dataObj.Add("fileType", ext.Replace(".", ""));
dataObj.Add("key", key);
// write file url to the data object
var prevFileUrl = i == currentVersion ? FileUri : MakePublicHistoryUrl(FileName,i.ToString(), "prev" + ext);
var prevFileUrl = i == currentVersion ? FileUri : MakePublicHistoryUrl(FileName, i.ToString(), "prev" + ext);
if (Path.IsPathRooted(storagePath))
{
prevFileUrl = i == currentVersion ? getDownloadUrl(FileName) : getDownloadUrl(Directory.GetFiles(verDir, "prev.*")[0].Replace(storagePath + "\\", ""));
}
dataObj.Add("url", prevFileUrl); // write file url to the data object
dataObj.Add("version", i);
if (i > 1) // check if the version number is greater than 1 (the file was modified)
@ -387,7 +388,7 @@ namespace OnlineEditorsExample
{ "url", prev["url"] },
});
// write the path to the diff.zip archive with differences in this file version
var changesUrl = MakePublicHistoryUrl(FileName,(i-1).ToString(), "diff.zip");
var changesUrl = MakePublicHistoryUrl(FileName, (i - 1).ToString(), "diff.zip");
dataObj.Add("changesUrl", changesUrl);
}
if (JwtManager.Enabled)
@ -522,12 +523,12 @@ namespace OnlineEditorsExample
private string MakePublicHistoryUrl(string filename, string version, string file)
{
var fileUrl = new UriBuilder(_Default.GetServerUrl(true));
fileUrl.Path = HttpRuntime.AppDomainAppVirtualPath
+ (HttpRuntime.AppDomainAppVirtualPath.EndsWith("/") ? "" : "/")
+ "webeditor.ashx";
fileUrl.Query = "type=downloadhistory&fileName=" + HttpUtility.UrlEncode(filename)
+"&ver=" + version + "&file="+ file +
"&userAddress=" + HttpUtility.UrlEncode(HttpContext.Current.Request.UserHostAddress);
fileUrl.Path = HttpRuntime.AppDomainAppVirtualPath
+ (HttpRuntime.AppDomainAppVirtualPath.EndsWith("/") ? "" : "/")
+ "webeditor.ashx";
fileUrl.Query = "type=downloadhistory&fileName=" + HttpUtility.UrlEncode(filename)
+ "&ver=" + version + "&file=" + file
+ "&userAddress=" + HttpUtility.UrlEncode(HttpContext.Current.Request.UserHostAddress);
return fileUrl.ToString();
}

View File

@ -6,14 +6,13 @@
<compilation debug="true" targetFramework="4.5" />
<authentication mode="Windows" />
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID" />
<identity impersonate="true" />
</system.web>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="52428800" />

View File

@ -138,7 +138,7 @@ namespace OnlineEditorsExample
var userAddress = context.Request["userAddress"];
var fileName = Path.GetFileName(context.Request["fileName"]);
var status = (TrackerStatus) (int) fileData["status"]; // get status from the request body
var saved = 0; // editing
var saved = 0;
switch (status)
{
case TrackerStatus.Editing:
@ -194,7 +194,7 @@ namespace OnlineEditorsExample
context.Response.Write("{\"error\":" + saved + "}");
return;
}
context.Response.Write("{\"error\":0}");
context.Response.Write("{\"error\":" + saved + "}");
}
// remove a file
@ -350,7 +350,9 @@ namespace OnlineEditorsExample
context.Response.Write("JWT validation failed");
return;
}
}else {
}
else
{
context.Response.StatusCode = (int)HttpStatusCode.Forbidden;
context.Response.Write("JWT validation failed");
return;
@ -358,7 +360,7 @@ namespace OnlineEditorsExample
}
var filePath = _Default.HistoryPath(fileName, userAddress, version, file); // get the path to the force saved document version
download(filePath, context);
}
catch (Exception)