feat(csharp): refresh file config

This commit is contained in:
sshakndr
2024-12-09 16:54:45 +07:00
parent 05b4e9d63d
commit a6a1c4a4cc
4 changed files with 96 additions and 2 deletions

View File

@ -1,5 +1,6 @@
# Change Log
- csharp: refresh config
- nodejs: refresh config
- nodejs: support vsdx in visio editor
- nodejs: support pages, numbers, key formats

View File

@ -199,6 +199,18 @@
}
};
var onRequestRefreshFile = function(event) {
let xhr = new XMLHttpRequest();
xhr.open("GET", "webeditor.ashx?type=config&fileName=" + encodeURIComponent(config.document.title) +
"&directUrl=" + !!config.document.directUrl +
"&permissions=" + encodeURIComponent(JSON.stringify(config.document.permissions)));
xhr.send();
xhr.onload = function () {
innerAlert(xhr.responseText);
docEditor.refreshFile(JSON.parse(xhr.responseText));
};
};
var onRequestOpen = function (event) { // user open external data source
innerAlert("onRequestOpen");
var windowName = event.data.windowName;
@ -337,7 +349,7 @@
};
if (config.editorConfig.user.id) {
config.events['onRequestRefreshFile'] = onRequestRefreshFile;
config.events['onRequestClose'] = onRequestClose;
config.events['onRequestHistory'] = function (event) { // the user is trying to show the document version history

View File

@ -77,7 +77,8 @@ namespace OnlineEditorsExample
"Can't view chat",
"Can't protect file",
"View file without collaboration",
"Cant submit forms"
"Cant submit forms",
"Cant refresh outdated file"
};
private static List<User> users = new List<User>() {

View File

@ -93,6 +93,9 @@ namespace OnlineEditorsExample
case "formats":
Formats(context);
break;
case "config":
Config(context);
break;
}
}
@ -815,6 +818,83 @@ namespace OnlineEditorsExample
}
}
private static void Config(HttpContext context) {
try
{
var fileName = context.Request.QueryString.Get("fileName");
var directUrl = context.Request.QueryString.Get("directUrl").ToLower() == "true";
var permissions = context.Request.QueryString.Get("permissions") != null
? context.Request.QueryString.Get("permissions")
: "{}";
var userAdress = HttpUtility.UrlEncode(_Default.CurUserHostAddress(HttpContext.Current.Request.UserHostAddress));
if (string.IsNullOrEmpty(fileName) || !File.Exists(_Default.StoragePath(fileName, userAdress)))
{
context.Response.Write("{ \"error\": \"File is not exist\"}");
return;
}
var id = context.Request.Cookies.GetOrDefault("uid", null);
var user = Users.getUser(id);
var callbackUrl = new UriBuilder(_Default.GetServerUrl(true));
callbackUrl.Path = HttpRuntime.AppDomainAppVirtualPath
+ (HttpRuntime.AppDomainAppVirtualPath.EndsWith("/") ? "" : "/")
+ "webeditor.ashx";
callbackUrl.Query = "type=track" + "&fileName="
+ HttpUtility.UrlEncode(fileName)
+ "&userAddress=" + HttpUtility.UrlEncode(_Default.CurUserHostAddress(HttpContext.Current.Request.UserHostAddress));
var callback = callbackUrl.ToString();
var jss = new JavaScriptSerializer();
var config = new Dictionary<string, object>
{
{
"document", new Dictionary<string, object>
{
{"key", ServiceConverter.GenerateRevisionId(_Default.CurUserHostAddress(null)
+ "/" + Path.GetFileName(_Default.FileUri(fileName, true))
+ "/" + File.GetLastWriteTime(_Default.StoragePath(fileName, null)).GetHashCode())},
{"title", fileName},
{"url", DocEditor.getDownloadUrl(fileName)},
{"permissions", JsonConvert.DeserializeObject<Dictionary<string, object>>(permissions)},
{"directUrl", directUrl ? DocEditor.getDownloadUrl(fileName, false) : null},
{
"referenceData", new Dictionary<string, object>
{
{"fileKey", !user.id.Equals("uid-0") ?
jss.Serialize(new Dictionary<string, object>{
{"fileName", fileName},
{"userAddress", userAdress}
}) : null },
{"instanceId", _Default.GetServerUrl(false)}
}
}
}
},
{
"editorConfig", new Dictionary<string, object>
{
{"callbackUrl", callback},
{"mode", "edit"}
}
}
};
if (JwtManager.Enabled)
{
var token = JwtManager.Encode(config);
config.Add("token", token);
}
context.Response.Write(jss.Serialize(config));
}
catch (Exception e)
{
context.Response.Write("{ \"error\": \"" + e.Message + "\"}");
}
}
// delete a forgotten file from the document server
private static void RemoveForgotten(HttpContext context)
{