Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/reference data #346

Merged
merged 30 commits into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
2e75037
php: referenceData
rivexe Feb 13, 2023
69caf53
csharp: referenceData
rivexe Feb 14, 2023
75046b8
csharp-mvc: referenceData
rivexe Feb 14, 2023
9213143
chsarp: fix referenceData - path-parameter in ajax-handler added
rivexe Feb 15, 2023
8147608
csharp-mvc: fix referenceData - path-parameter in ajax-handler added
rivexe Feb 15, 2023
97ba0da
java: referenceData
rivexe Feb 15, 2023
43875b0
java-spring: ReferenceData
rivexe Feb 15, 2023
55734a1
ruby: referenceData
rivexe Feb 16, 2023
1b1d07e
python: referenceData
rivexe Feb 16, 2023
42b7c83
php: search for fileName by path added
rivexe Feb 17, 2023
7d1c3a9
python: search for fileName by path added
rivexe Feb 17, 2023
f76c611
ruby: search for fileName by path added
rivexe Feb 17, 2023
ee0a167
csharp: search for fileName by path added
rivexe Feb 17, 2023
54f501c
csharp-mvc: search for fileName by path added
rivexe Feb 17, 2023
63b7641
csharp: fix - "Path not found" - error handled
rivexe Feb 17, 2023
e88c2e9
java: search for fileName by path added + json-data fix
rivexe Feb 17, 2023
e729afd
java-spring: search for fileName by path added + json-data fix
rivexe Feb 17, 2023
8d2cbca
php: fix - search for filename by path
rivexe Feb 20, 2023
9d54ec7
python: fix - search for filename by path
rivexe Feb 20, 2023
d23e139
csharp: fix - search for filename by path
rivexe Feb 21, 2023
4f26ff6
csharp-mvc: fix - search for filename by path
rivexe Feb 21, 2023
4eff2e7
ruby: fix - search for filename by path
rivexe Feb 21, 2023
21d1fd9
java: fix - search for filename by path
rivexe Feb 21, 2023
61d64e9
java-spring: fix - search for filename by path
rivexe Feb 22, 2023
82bc0e6
csharp: unnecessary replace of symbols deleted.
rivexe Feb 27, 2023
060f28e
csharp-mvc: unnecessary replace of symbols deleted
rivexe Feb 27, 2023
4fa2049
csharp-mvc: names of helpers fixed + check of empty filename-string (…
rivexe Feb 27, 2023
61a8490
csharp: check of empty filename-string (logical error fixed)
rivexe Feb 27, 2023
469a8c0
Merge branch 'develop' into feature/referenceData
rivexe Feb 27, 2023
4d4951f
referenceData to changelog
LinneyS Feb 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions web/documentserver-example/csharp-mvc/Models/FileModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,17 @@ public string GetDocConfig(HttpRequest request, UrlHelper url)
{ "favorite", favorite}
}
},
{
"referenceData", new Dictionary<string, string>()
{
{ "fileKey", !user.id.Equals("uid-0") ?
jss.Serialize(new Dictionary<string, object>{
{"fileName", FileName},
{"userAddress", HttpUtility.UrlEncode(_Default.CurUserHostAddress(HttpContext.Current.Request.UserHostAddress))}
rivexe marked this conversation as resolved.
Show resolved Hide resolved
}) : null },
{"instanceId", _Default.GetServerUrl(false) }
}
},
{
// the permission for the document to be edited and downloaded or not
"permissions", new Dictionary<string, object>
Expand Down
13 changes: 13 additions & 0 deletions web/documentserver-example/csharp-mvc/Views/Home/Editor.aspx
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,18 @@
}
};

var onRequestReferenceData = function (event) { // user refresh external data source
event.data.directUrl = !!config.document.directUrl;
let xhr = new XMLHttpRequest();
xhr.open("POST", "webeditor.ashx?type=reference");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(JSON.stringify(event.data));
xhr.onload = function () {
console.log(xhr.responseText);
docEditor.setReferenceData(JSON.parse(xhr.responseText));
}
};

config = <%= Model.GetDocConfig(Request, Url) %>;

config.width = "100%";
Expand Down Expand Up @@ -239,6 +251,7 @@
};
// prevent file renaming for anonymous users
config.events['onRequestRename'] = onRequestRename;
config.events['onRequestReferenceData'] = onRequestReferenceData;
}

if (config.editorConfig.createUrl) {
Expand Down
94 changes: 94 additions & 0 deletions web/documentserver-example/csharp-mvc/WebEditor.ashx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ public void ProcessRequest(HttpContext context)
case "rename":
Rename(context);
break;
case "reference":
Reference(context);
break;
}
}

Expand Down Expand Up @@ -591,5 +594,96 @@ private static void Rename(HttpContext context)
TrackManager.commandRequest("meta", docKey, meta);
context.Response.Write("{ \"result\": \"OK\"}");
}

private static void Reference(HttpContext context)
{
string fileData;
try
{
using (var receiveStream = context.Request.InputStream)
using (var readStream = new StreamReader(receiveStream))
{
fileData = readStream.ReadToEnd();
if (string.IsNullOrEmpty(fileData)) return;
}
}
catch (Exception e)
{
throw new HttpException((int)HttpStatusCode.BadRequest, e.Message);
}

var jss = new JavaScriptSerializer();
var body = jss.Deserialize<Dictionary<string, object>>(fileData);
Dictionary<string, object> referenceData = null;
var fileName = "";
var userAddress = "";

if (body.ContainsKey("referenceData"))
{
referenceData = jss.Deserialize<Dictionary<string, object>>(jss.Serialize(body["referenceData"]));
var instanceId = (string)referenceData["instanceId"];
var fileKey = (string)referenceData["fileKey"];
if (instanceId == _Default.GetServerUrl(false))
{
var fileKeyObj = jss.Deserialize<Dictionary<string, object>>(fileKey);
userAddress = (string)fileKeyObj["userAddress"];
if (userAddress == HttpUtility.UrlEncode(_Default.CurUserHostAddress(HttpContext.Current.Request.UserHostAddress)))
{
fileName = (string)fileKeyObj["fileName"];
}
}
}

if (fileName != "")
{
try
{
var path = (string)body["path"];
path = Path.GetFileName(path);
if (File.Exists(_Default.StoragePath(path, null)))
{
fileName = path;
}
}
catch
{
context.Response.Write("{ \"error\": \"Path not found!\"}");
return;
}
}

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", "&"));
}

}
rivexe marked this conversation as resolved.
Show resolved Hide resolved
}
}
14 changes: 14 additions & 0 deletions web/documentserver-example/csharp/DocEditor.aspx
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,19 @@
}
};

var onRequestReferenceData = function (event) { // user refresh external data source

event.data.directUrl = !!config.document.directUrl;
let xhr = new XMLHttpRequest();
xhr.open("POST", "webeditor.ashx?type=reference");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(JSON.stringify(event.data));
xhr.onload = function () {
console.log(xhr.responseText);
docEditor.setReferenceData(JSON.parse(xhr.responseText));
}
};

config = <%= DocConfig %>;

config.width = "100%";
Expand Down Expand Up @@ -242,6 +255,7 @@
};
// prevent file renaming for anonymous users
config.events['onRequestRename'] = onRequestRename;
config.events['onRequestReferenceData'] = onRequestReferenceData;
}

if (config.editorConfig.createUrl) {
Expand Down
11 changes: 11 additions & 0 deletions web/documentserver-example/csharp/DocEditor.aspx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,17 @@ protected void Page_Load(object sender, EventArgs e)
{ "favorite", favorite }
}
},
{
"referenceData", new Dictionary<string, string>()
{
{ "fileKey", !user.id.Equals("uid-0") ?
jss.Serialize(new Dictionary<string, object>{
{"fileName", FileName},
{"userAddress", HttpUtility.UrlEncode(_Default.CurUserHostAddress(HttpContext.Current.Request.UserHostAddress))}
}) : null },
{"instanceId", _Default.GetServerUrl(false) }
}
},
{
// the permission for the document to be edited and downloaded or not
"permissions", new Dictionary<string, object>
Expand Down
93 changes: 93 additions & 0 deletions web/documentserver-example/csharp/WebEditor.ashx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
using System.Web.Configuration;
using System.Linq;
using System.Net;
using System.Net.Sockets;

namespace OnlineEditorsExample
{
Expand Down Expand Up @@ -71,6 +72,9 @@ public void ProcessRequest(HttpContext context)
case "rename":
Rename(context);
break;
case "reference":
Reference(context);
break;
}
}

Expand Down Expand Up @@ -409,5 +413,94 @@ private static void Rename(HttpContext context)
TrackManager.commandRequest("meta", docKey, meta);
context.Response.Write("{ \"result\": \"OK\"}");
}

private static void Reference(HttpContext context)
{
string fileData;
try
{
using (var receiveStream = context.Request.InputStream)
using (var readStream = new StreamReader(receiveStream))
{
fileData = readStream.ReadToEnd();
if (string.IsNullOrEmpty(fileData)) return;
}
}
catch (Exception e)
{
throw new HttpException((int)HttpStatusCode.BadRequest, e.Message);
}

var jss = new JavaScriptSerializer();
var body = jss.Deserialize<Dictionary<string, object>>(fileData);
Dictionary<string, object> referenceData = null;
var fileName = "";
var userAddress = "";

if (body.ContainsKey("referenceData"))
{
referenceData = jss.Deserialize<Dictionary<string, object>>(jss.Serialize(body["referenceData"]));
var instanceId = (string)referenceData["instanceId"];
var fileKey = (string)referenceData["fileKey"];
if (instanceId == _Default.GetServerUrl(false))
{
var fileKeyObj = jss.Deserialize<Dictionary<string, object>>(fileKey);
userAddress = (string)fileKeyObj["userAddress"];
if (userAddress == HttpUtility.UrlEncode(_Default.CurUserHostAddress(HttpContext.Current.Request.UserHostAddress)))
{
fileName = (string)fileKeyObj["fileName"];
}
}
}

if (fileName != "")
{
try
{
var path = (string)body["path"];
path = Path.GetFileName(path);
if (File.Exists(_Default.StoragePath(path, null)))
{
fileName = path;
}
}
catch
{
context.Response.Write("{ \"error\": \"Path not found!\"}");
return;
}
}

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", "&"));
}
}
}
Loading