Compare commits

...

3 Commits

8 changed files with 123 additions and 1 deletions

View File

@ -10,4 +10,5 @@
<suppress checks="JavadocPackage" files="."/>
<suppress checks="JavadocVariable" files="."/>
<suppress checks="MissingJavadocMethod" files="."/>
<suppress checks="MagicNumber" files="DefaultDocumentManager.java"/>
</suppressions>

View File

@ -20,11 +20,14 @@ package com.onlyoffice.integration.documentserver.managers.document;
import com.onlyoffice.integration.documentserver.storage.FileStorageMutator;
import com.onlyoffice.integration.documentserver.storage.FileStoragePathBuilder;
import com.onlyoffice.integration.documentserver.util.Constants;
import com.onlyoffice.integration.documentserver.util.file.FileUtility;
import com.onlyoffice.integration.documentserver.util.service.ServiceConverter;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Primary;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;
import java.io.File;
@ -243,4 +246,58 @@ public class DefaultDocumentManager implements DocumentManager {
return fileName;
}
@SneakyThrows
public Boolean isExtendedPDFFile(final String fileName) {
Resource resource = storageMutator.loadFileAsResource(fileName);
byte[] bytes;
try (InputStream inputStream = resource.getInputStream()) {
bytes = inputStream.readNBytes(110);
} catch (Exception e) {
return false;
}
String pBuffer = new String(bytes, "Windows-1252");
int indexFirst = pBuffer.indexOf("%\315\312\322\251\015");
if (indexFirst == -1) {
return false;
}
String pFirst = pBuffer.substring(indexFirst + 6);
if (!pFirst.startsWith("1 0 obj\012<<\012")) {
return false;
}
pFirst = pFirst.substring(11);
int indexStream = pFirst.indexOf("stream\015\012");
int indexMeta = pFirst.indexOf(Constants.G_FORMAT_OFORM_PDF_META_TAG);
if (indexStream == -1 || indexMeta == -1 || indexStream < indexMeta) {
return false;
}
String pMeta = pFirst.substring(indexMeta);
pMeta = pMeta.substring(Constants.G_FORMAT_OFORM_PDF_META_TAG.length() + 3);
int indexMetaLast = pMeta.indexOf(" ");
if (indexMetaLast == -1) {
return false;
}
pMeta = pMeta.substring(indexMetaLast + 1);
indexMetaLast = pMeta.indexOf(" ");
if (indexMetaLast == -1) {
return false;
}
return true;
}
}

View File

@ -39,4 +39,5 @@ public interface DocumentManager {
// create demo document
String createDemo(String fileExt, Boolean sample, String uid, String uname) throws Exception;
String getCreateUrl(String fileName, Boolean sample); // get URL to the created file
Boolean isExtendedPDFFile(String fileName);
}

View File

@ -27,6 +27,7 @@ public final class Constants {
public static final Integer MAX_KEY_LENGTH = 20;
public static final Integer ANONYMOUS_USER_ID = 4;
public static final Integer KILOBYTE_SIZE = 1024;
public static final String G_FORMAT_OFORM_PDF_META_TAG = "ONLYOFFICEFORM";
private Constants() { }
}

View File

@ -998,6 +998,12 @@ app.get('/editor', (req, res) => { // define a handler for editing document
mode = 'view';
}
const ext = fileUtility.getFileExtension(fileName, true);
let isForm = 'null';
if (req.query.checkform !== 'false' && ext === 'pdf') {
isForm = req.DocManager.isExtendedPDFFile(fileName);
}
let submitForm = false;
if (mode === 'fillForms') {
submitForm = userid === 'uid-1';
@ -1008,12 +1014,13 @@ app.get('/editor', (req, res) => { // define a handler for editing document
apiUrl: siteUrl + configServer.get('apiUrl'),
file: {
name: fileName,
ext: fileUtility.getFileExtension(fileName, true),
ext: ext,
uri: url,
directUrl: !userDirectUrl ? null : directUrl,
uriUser: directUrl,
created: new Date().toDateString(),
favorite: user.favorite != null ? user.favorite : 'null',
isForm: isForm,
},
editor: {
type,

View File

@ -26,6 +26,7 @@
"storagePath": "/files",
"maxFileSize": 1073741824,
"maxNameLength": 50,
"gFormatOformPdfMetaTag": "ONLYOFFICEFORM",
"mobileRegEx": "android|avantgo|playbook|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od|ad)|iris|kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\\/|plucker|pocket|psp|symbian|treo|up\\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino",
"token": {
"enable": false,

View File

@ -610,6 +610,59 @@ DocManager.prototype.getFilesInfo = function getFilesInfo(fileId) {
} return responseArray;
};
DocManager.prototype.isExtendedPDFFile = function isExtendedPDFFile(fileName) {
let filePath = this.forcesavePath(fileName, null, false);
if (filePath === '') {
filePath = this.storagePath(fileName);
}
const bufferSize = 110;
const buffer = Buffer.alloc(bufferSize);
const fd = fileSystem.openSync(filePath, 'r');
fileSystem.readSync(fd, buffer, 0, bufferSize);
fileSystem.closeSync(fd);
const pBuffer = buffer.toString('latin1');
const indexFirst = pBuffer.indexOf('%\xCD\xCA\xD2\xA9\x0D');
if (indexFirst === -1) {
return false;
}
let pFirst = pBuffer.substring(indexFirst + 6);
if (!pFirst.startsWith('1 0 obj\x0A<<\x0A')) {
return false;
}
pFirst = pFirst.substring(11);
const indexStream = pFirst.indexOf('stream\x0D\x0A');
const indexMeta = pFirst.indexOf(configServer.get('gFormatOformPdfMetaTag'));
if (indexStream === -1 || indexMeta === -1 || indexStream < indexMeta) {
return false;
}
let pMeta = pFirst.substring(indexMeta);
pMeta = pMeta.substring(configServer.get('gFormatOformPdfMetaTag').length + 3);
let indexMetaLast = pMeta.indexOf(' ');
if (indexMetaLast === -1) {
return false;
}
pMeta = pMeta.substring(indexMetaLast + 1);
indexMetaLast = pMeta.indexOf(' ');
if (indexMetaLast === -1) {
return false;
}
return true;
};
DocManager.prototype.getInstanceId = function getInstanceId() {
return this.getServerUrl();
};

View File

@ -6,6 +6,7 @@
"uploaded": "<%- file.created %>",
"favorite": <%- file.favorite %>
},
"isForm": <%- file.isForm %>,
"key": "<%- editor.key %>",
"permissions": {
"chat": <%- editor.chat %>,