Skip to content

Commit

Permalink
remove using FileUploader
Browse files Browse the repository at this point in the history
  • Loading branch information
LinneyS committed Nov 13, 2017
1 parent b21190d commit ebe9d39
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 207 deletions.
24 changes: 7 additions & 17 deletions src/main/java/onlyoffice/DocumentManager.java
Expand Up @@ -66,27 +66,17 @@ public static List<String> GetEditedExts()
}
}

public static String GetExternalUri(Long attachmentId, String documentStorageUrl) throws Exception
public static String GetUri(Long attachmentId) throws Exception
{
String key = getKeyOfFile(attachmentId);
String externalUri;

if (CacheMap.containsKey(key))
{
externalUri = CacheMap.get(key);
log.info("externalUri from cache " + externalUri);
return externalUri;
}

InputStream inputStream = AttachmentUtil.getAttachmentData(attachmentId);
String contentType = AttachmentUtil.getMediaType(attachmentId);
SettingsManager settingsManager = (SettingsManager) ContainerManager.getComponent("settingsManager");
String baseUrl = settingsManager.getGlobalSettings().getBaseUrl();

externalUri = ServiceConverter.GetExternalUri(inputStream, inputStream.available(), contentType, key, documentStorageUrl);
String hash = CreateHash(Long.toString(attachmentId));

CacheMap.put(key, externalUri);
log.info("externalUri " + externalUri);
String callbackUrl = baseUrl + callbackServler + "?vkey=" + GeneralUtil.urlEncode(hash);
log.info("callbackUrl " + callbackUrl);

return externalUri;
return callbackUrl;
}

public static String getKeyOfFile(Long attachmentId)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/onlyoffice/OnlyOfficeEditorServlet.java
Expand Up @@ -87,7 +87,7 @@ public void doGet(HttpServletRequest request, HttpServletResponse response)

fileName = AttachmentUtil.getFileName(attachmentId);

externalUrl = DocumentManager.GetExternalUri(attachmentId, apiUrl + properties.getProperty("files.docservice.url.storage"));
externalUrl = DocumentManager.GetUri(attachmentId);

if (AttachmentUtil.checkAccess(attachmentId, user, true))
{
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/onlyoffice/OnlyOfficeSaveFileServlet.java
Expand Up @@ -2,6 +2,7 @@

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.HttpURLConnection;
Expand All @@ -27,6 +28,32 @@ public class OnlyOfficeSaveFileServlet extends HttpServlet
private static final long serialVersionUID = 1L;
private static final Logger log = LogManager.getLogger("onlyoffice.OnlyOfficeSaveFileServlet");

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
String vkey = request.getParameter("vkey");
log.info("vkey = " + vkey);
String attachmentIdString = DocumentManager.ReadHash(vkey);

Long attachmentId = Long.parseLong(attachmentIdString);
log.info("attachmentId " + attachmentId);

String contentType = AttachmentUtil.getMediaType(attachmentId);
response.setContentType(contentType);

InputStream inputStream = AttachmentUtil.getAttachmentData(attachmentId);
response.setContentLength(inputStream.available());

byte[] buffer = new byte[10240];

OutputStream output = response.getOutputStream();
for (int length = 0; (length = inputStream.read(buffer)) > 0;)
{
output.write(buffer, 0, length);
}
}

@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
Expand Down
188 changes: 0 additions & 188 deletions src/main/java/onlyoffice/ServiceConverter.java

This file was deleted.

1 change: 0 additions & 1 deletion src/main/resources/onlyoffice-config.properties
Expand Up @@ -3,5 +3,4 @@ filesize-max=104857600
files.docservice.secret=Vskoproizvolny Salt par Chivreski
files.docservice.edited-docs=docx|xlsx|pptx

files.docservice.url.storage=FileUploader.ashx
files.docservice.url.api=web-apps/apps/api/documents/api.js

0 comments on commit ebe9d39

Please sign in to comment.