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 9 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
64 changes: 64 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,66 @@ 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);
var referenceData = jss.Deserialize <Dictionary<string, object>> (jss.Serialize(body["referenceData"]));
var instanceId = (string)referenceData["instanceId"];
var fileKey = (string)referenceData["fileKey"];

try
{
var fileKeyObj = jss.Deserialize<Dictionary<string, object>>(fileKey);
var fileName = (string)fileKeyObj["fileName"];
var userAddress = (string)fileKeyObj["userAddress"];

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", "&"));
}
catch (Exception e)
{
context.Response.Write("{ \"error\": \"File not found!\"}");
}

}
}
}
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
64 changes: 64 additions & 0 deletions web/documentserver-example/csharp/WebEditor.ashx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ public void ProcessRequest(HttpContext context)
case "rename":
Rename(context);
break;
case "reference":
Reference(context);
break;
}
}

Expand Down Expand Up @@ -409,5 +412,66 @@ 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);
var referenceData = jss.Deserialize <Dictionary<string, object>> (jss.Serialize(body["referenceData"]));
var instanceId = (string)referenceData["instanceId"];
var fileKey = (string)referenceData["fileKey"];

try
{
var fileKeyObj = jss.Deserialize<Dictionary<string, object>>(fileKey);
var fileName = (string)fileKeyObj["fileName"];
var userAddress = (string)fileKeyObj["userAddress"];

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", "&"));
}
catch (Exception e)
{
context.Response.Write("{ \"error\": \"File not found!\"}");
}

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package com.onlyoffice.integration.controllers;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import com.onlyoffice.integration.documentserver.callbacks.CallbackHandler;
import com.onlyoffice.integration.documentserver.managers.jwt.JwtManager;
import com.onlyoffice.integration.documentserver.storage.FileStorageMutator;
Expand Down Expand Up @@ -445,4 +446,37 @@ public String rename(@RequestBody final JSONObject body) {
return e.getMessage();
}
}

@PostMapping("/reference")
@ResponseBody
public String reference(@RequestBody final JSONObject body) {
try {
String instanceId = (String) body.get("instanceId");
JSONObject fileKey = (JSONObject) body.get("fileKey");
Gson gson = new Gson();
String fileKeyValue = gson.toJson(fileKey);

String fileName = (String) fileKey.get("fileName");
String userAddress = (String) fileKey.get("userAddress");
HashMap<String, Object> referenceData = new HashMap<>();
referenceData.put("instanceId", storagePathBuilder.getServerUrl(true));
referenceData.put("fileKey", fileKeyValue);

HashMap<String, Object> data = new HashMap<>();
data.put("fileType", fileUtility.getFileExtension(fileName));
data.put("url", documentManager.getDownloadUrl(fileName, true));
data.put("directUrl", documentManager.getDownloadUrl(fileName, true));
data.put("referenceData", referenceData);
data.put("path", referenceData);

if (jwtManager.tokenEnabled()) {
String token = jwtManager.createToken(data);
data.put("token", token);
}
return gson.toJson(data);
} catch (Exception e) {
e.printStackTrace();
return "{ \"error\" : 1, \"message\" : \"" + e.getMessage() + "\"}";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package com.onlyoffice.integration.documentserver.models.filemodel;

import com.onlyoffice.integration.documentserver.managers.document.DocumentManager;
import com.onlyoffice.integration.documentserver.models.configurations.Info;
import lombok.Getter;
import lombok.Setter;
Expand All @@ -43,4 +44,5 @@ public class Document { // the parameters pertaining to the document (title, ur
as file name when the document is downloaded */
private String url; // the absolute URL where the source viewed or edited document is stored
private String directUrl;
private ReferenceData referenceData;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.onlyoffice.integration.documentserver.models.filemodel;

import java.util.HashMap;
import java.util.Map;
import com.onlyoffice.integration.documentserver.storage.FileStoragePathBuilder;
import org.springframework.beans.factory.annotation.Autowired;

public class ReferenceData {
@Autowired
private FileStoragePathBuilder storagePathBuilder;
private final String instanceId;
private final Map<String, String> fileKey;
public ReferenceData(final String fileName, final String curUserHostAddress, final User user) {
instanceId = storagePathBuilder.getServerUrl(true);
Map<String, String> fileKeyList = new HashMap<>();
if (!user.getId().equals("uid-0")) {
fileKeyList.put("fileName", fileName);
fileKeyList.put("userAddress", curUserHostAddress);
} else {
fileKeyList = null;
}
fileKey = fileKeyList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,18 @@
}
};

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

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

if (config.editorConfig.createUrl) {
Expand Down
Loading