Allow multiple MIME types per extension
This commit is contained in:
parent
ba6b33a83f
commit
ffeb8c3acb
@ -109,5 +109,7 @@ libraryDependencies ++= Seq(
|
|||||||
"org.postgresql" % "postgresql" % "42.4.3",
|
"org.postgresql" % "postgresql" % "42.4.3",
|
||||||
"org.hibernate" % "hibernate-core" % "5.6.1.Final",
|
"org.hibernate" % "hibernate-core" % "5.6.1.Final",
|
||||||
"org.flywaydb" % "flyway-core" % "7.8.2",
|
"org.flywaydb" % "flyway-core" % "7.8.2",
|
||||||
"com.zaxxer" % "HikariCP" % "4.0.3"
|
"com.zaxxer" % "HikariCP" % "4.0.3",
|
||||||
|
"org.apache.tika" % "tika-core" % "2.8.0",
|
||||||
|
"org.apache.tika" % "tika-parsers-standard-package" % "2.8.0"
|
||||||
)
|
)
|
||||||
|
@ -23,6 +23,7 @@ object Dependencies {
|
|||||||
// Office and document conversion
|
// Office and document conversion
|
||||||
val apachePoi = "5.1.0"
|
val apachePoi = "5.1.0"
|
||||||
val nuProcess = "2.0.6"
|
val nuProcess = "2.0.6"
|
||||||
|
val tika = "2.8.0"
|
||||||
|
|
||||||
// Server
|
// Server
|
||||||
val servlet = "4.0.1"
|
val servlet = "4.0.1"
|
||||||
@ -56,6 +57,7 @@ object Dependencies {
|
|||||||
|
|
||||||
val poiXml = "org.apache.poi" % "poi-ooxml" % Versions.apachePoi
|
val poiXml = "org.apache.poi" % "poi-ooxml" % Versions.apachePoi
|
||||||
val nuProcess = "com.zaxxer" % "nuprocess" % Versions.nuProcess
|
val nuProcess = "com.zaxxer" % "nuprocess" % Versions.nuProcess
|
||||||
|
val tika = "org.apache.tika" % "tika-core" % Versions.tika
|
||||||
|
|
||||||
val servletApi = "javax.servlet" % "javax.servlet-api" % Versions.servlet
|
val servletApi = "javax.servlet" % "javax.servlet-api" % Versions.servlet
|
||||||
|
|
||||||
@ -93,6 +95,7 @@ object Dependencies {
|
|||||||
Compile.apacheHttpAsync,
|
Compile.apacheHttpAsync,
|
||||||
Compile.poiXml,
|
Compile.poiXml,
|
||||||
Compile.nuProcess,
|
Compile.nuProcess,
|
||||||
|
Compile.tika,
|
||||||
Compile.servletApi,
|
Compile.servletApi,
|
||||||
Compile.apacheLang,
|
Compile.apacheLang,
|
||||||
Compile.apacheIo,
|
Compile.apacheIo,
|
||||||
|
@ -11,6 +11,7 @@ public class MimeTypeUtils {
|
|||||||
private static final String DOCX = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
|
private static final String DOCX = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
|
||||||
private static final String PPT = "application/vnd.ms-powerpoint";
|
private static final String PPT = "application/vnd.ms-powerpoint";
|
||||||
private static final String PPTX = "application/vnd.openxmlformats-officedocument.presentationml.presentation";
|
private static final String PPTX = "application/vnd.openxmlformats-officedocument.presentationml.presentation";
|
||||||
|
private static final String TIKA_MSOFFICE = "application/x-tika-msoffice";
|
||||||
private static final String ODT = "application/vnd.oasis.opendocument.text";
|
private static final String ODT = "application/vnd.oasis.opendocument.text";
|
||||||
private static final String RTF = "application/rtf";
|
private static final String RTF = "application/rtf";
|
||||||
private static final String TXT = "text/plain";
|
private static final String TXT = "text/plain";
|
||||||
@ -21,38 +22,37 @@ public class MimeTypeUtils {
|
|||||||
private static final String PNG = "image/png";
|
private static final String PNG = "image/png";
|
||||||
private static final String SVG = "image/svg+xml";
|
private static final String SVG = "image/svg+xml";
|
||||||
|
|
||||||
private static final HashMap<String,String> EXTENSIONS_MIME = new HashMap<String,String>(16) {
|
private static final HashMap<String, List<String>> EXTENSIONS_MIME = new HashMap<String, List<String>>(16) {
|
||||||
{
|
{
|
||||||
// Add all the supported files
|
put(FileTypeConstants.DOC, Arrays.asList(DOC, DOCX, TIKA_MSOFFICE));
|
||||||
put(FileTypeConstants.XLS, XLS);
|
put(FileTypeConstants.XLS, Arrays.asList(XLS, XLSX, TIKA_MSOFFICE));
|
||||||
put(FileTypeConstants.XLSX, XLSX);
|
put(FileTypeConstants.PPT, Arrays.asList(PPT, PPTX, TIKA_MSOFFICE));
|
||||||
put(FileTypeConstants.DOC, DOC);
|
put(FileTypeConstants.DOCX, Arrays.asList(DOCX));
|
||||||
put(FileTypeConstants.DOCX, DOCX);
|
put(FileTypeConstants.PPTX, Arrays.asList(PPTX));
|
||||||
put(FileTypeConstants.PPT, PPT);
|
put(FileTypeConstants.XLSX, Arrays.asList(XLSX));
|
||||||
put(FileTypeConstants.PPTX, PPTX);
|
put(FileTypeConstants.ODT, Arrays.asList(ODT));
|
||||||
put(FileTypeConstants.ODT, ODT);
|
put(FileTypeConstants.RTF, Arrays.asList(RTF));
|
||||||
put(FileTypeConstants.RTF, RTF);
|
put(FileTypeConstants.TXT, Arrays.asList(TXT));
|
||||||
put(FileTypeConstants.TXT, TXT);
|
put(FileTypeConstants.ODS, Arrays.asList(ODS));
|
||||||
put(FileTypeConstants.ODS, ODS);
|
put(FileTypeConstants.ODP, Arrays.asList(ODP));
|
||||||
put(FileTypeConstants.ODP, ODP);
|
put(FileTypeConstants.PDF, Arrays.asList(PDF));
|
||||||
put(FileTypeConstants.PDF, PDF);
|
put(FileTypeConstants.JPG, Arrays.asList(JPEG));
|
||||||
put(FileTypeConstants.JPG, JPEG);
|
put(FileTypeConstants.JPEG, Arrays.asList(JPEG));
|
||||||
put(FileTypeConstants.JPEG, JPEG);
|
put(FileTypeConstants.PNG, Arrays.asList(PNG));
|
||||||
put(FileTypeConstants.PNG, PNG);
|
put(FileTypeConstants.SVG, Arrays.asList(SVG));
|
||||||
put(FileTypeConstants.SVG, SVG);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public Boolean extensionMatchMimeType(String mimeType, String finalExtension) {
|
public Boolean extensionMatchMimeType(String mimeType, String finalExtension) {
|
||||||
if(EXTENSIONS_MIME.containsKey(finalExtension.toLowerCase()) &&
|
finalExtension = finalExtension.toLowerCase();
|
||||||
EXTENSIONS_MIME.get(finalExtension.toLowerCase()).equalsIgnoreCase(mimeType)) {
|
|
||||||
return true;
|
if (EXTENSIONS_MIME.containsKey(finalExtension)) {
|
||||||
} else if(EXTENSIONS_MIME.containsKey(finalExtension.toLowerCase() + 'x') &&
|
for (String validMimeType : EXTENSIONS_MIME.get(finalExtension)) {
|
||||||
EXTENSIONS_MIME.get(finalExtension.toLowerCase() + 'x').equalsIgnoreCase(mimeType)) {
|
if (validMimeType.equalsIgnoreCase(mimeType)) {
|
||||||
//Exception for MS Office files named with old extension but using internally the new mime type
|
|
||||||
//e.g. a file named with extension `ppt` but has the content of a `pptx`
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -60,7 +60,7 @@ public class MimeTypeUtils {
|
|||||||
public List<String> getValidMimeTypes() {
|
public List<String> getValidMimeTypes() {
|
||||||
List<String> validMimeTypes = Arrays.asList(XLS, XLSX,
|
List<String> validMimeTypes = Arrays.asList(XLS, XLSX,
|
||||||
DOC, DOCX, PPT, PPTX, ODT, RTF, TXT, ODS, ODP,
|
DOC, DOCX, PPT, PPTX, ODT, RTF, TXT, ODS, ODP,
|
||||||
PDF, JPEG, PNG, SVG
|
PDF, JPEG, PNG, SVG, TIKA_MSOFFICE
|
||||||
);
|
);
|
||||||
return validMimeTypes;
|
return validMimeTypes;
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ public class SlidesGenerationProgressNotifier {
|
|||||||
pres.getTemporaryPresentationId(),
|
pres.getTemporaryPresentationId(),
|
||||||
pres.getName(),
|
pres.getName(),
|
||||||
pres.getAuthzToken(),
|
pres.getAuthzToken(),
|
||||||
"IVALID_MIME_TYPE",
|
"INVALID_MIME_TYPE",
|
||||||
fileMime,
|
fileMime,
|
||||||
fileExtension
|
fileExtension
|
||||||
);
|
);
|
||||||
|
@ -12,8 +12,8 @@ const PAGE_COUNT_EXCEEDED_KEY = 'PAGE_COUNT_EXCEEDED';
|
|||||||
const PDF_HAS_BIG_PAGE_KEY = 'PDF_HAS_BIG_PAGE';
|
const PDF_HAS_BIG_PAGE_KEY = 'PDF_HAS_BIG_PAGE';
|
||||||
const GENERATED_SLIDE_KEY = 'GENERATED_SLIDE';
|
const GENERATED_SLIDE_KEY = 'GENERATED_SLIDE';
|
||||||
const FILE_TOO_LARGE_KEY = 'FILE_TOO_LARGE';
|
const FILE_TOO_LARGE_KEY = 'FILE_TOO_LARGE';
|
||||||
const CONVERSION_TIMEOUT_KEY = "CONVERSION_TIMEOUT";
|
const CONVERSION_TIMEOUT_KEY = 'CONVERSION_TIMEOUT';
|
||||||
const IVALID_MIME_TYPE_KEY = "IVALID_MIME_TYPE";
|
const INVALID_MIME_TYPE_KEY = 'INVALID_MIME_TYPE';
|
||||||
const NO_CONTENT = '204';
|
const NO_CONTENT = '204';
|
||||||
// const GENERATING_THUMBNAIL_KEY = 'GENERATING_THUMBNAIL';
|
// const GENERATING_THUMBNAIL_KEY = 'GENERATING_THUMBNAIL';
|
||||||
// const GENERATED_THUMBNAIL_KEY = 'GENERATED_THUMBNAIL';
|
// const GENERATED_THUMBNAIL_KEY = 'GENERATED_THUMBNAIL';
|
||||||
@ -52,7 +52,7 @@ export default async function handlePresentationConversionUpdate({ body }, meeti
|
|||||||
statusModifier['conversion.maxFileSize'] = body.maxFileSize;
|
statusModifier['conversion.maxFileSize'] = body.maxFileSize;
|
||||||
case UNSUPPORTED_DOCUMENT_KEY:
|
case UNSUPPORTED_DOCUMENT_KEY:
|
||||||
case OFFICE_DOC_CONVERSION_FAILED_KEY:
|
case OFFICE_DOC_CONVERSION_FAILED_KEY:
|
||||||
case IVALID_MIME_TYPE_KEY:
|
case INVALID_MIME_TYPE_KEY:
|
||||||
statusModifier['conversion.error'] = true;
|
statusModifier['conversion.error'] = true;
|
||||||
statusModifier['conversion.fileMime'] = body.fileMime;
|
statusModifier['conversion.fileMime'] = body.fileMime;
|
||||||
statusModifier['conversion.fileExtension'] = body.fileExtension;
|
statusModifier['conversion.fileExtension'] = body.fileExtension;
|
||||||
|
@ -54,7 +54,7 @@ const intlMessages = defineMessages({
|
|||||||
id: 'app.presentationUploder.upload.413',
|
id: 'app.presentationUploder.upload.413',
|
||||||
description: 'error that file exceed the size limit',
|
description: 'error that file exceed the size limit',
|
||||||
},
|
},
|
||||||
IVALID_MIME_TYPE: {
|
INVALID_MIME_TYPE: {
|
||||||
id: 'app.presentationUploder.conversion.invalidMimeType',
|
id: 'app.presentationUploder.conversion.invalidMimeType',
|
||||||
description: 'warns user that the file\'s mime type is not supported or it doesn\'t match the extension',
|
description: 'warns user that the file\'s mime type is not supported or it doesn\'t match the extension',
|
||||||
},
|
},
|
||||||
@ -151,7 +151,7 @@ function renderPresentationItemStatus(item, intl) {
|
|||||||
case 'PDF_HAS_BIG_PAGE':
|
case 'PDF_HAS_BIG_PAGE':
|
||||||
constraint['0'] = (item.conversion.bigPageSize / 1000 / 1000).toFixed(2);
|
constraint['0'] = (item.conversion.bigPageSize / 1000 / 1000).toFixed(2);
|
||||||
break;
|
break;
|
||||||
case 'IVALID_MIME_TYPE':
|
case 'INVALID_MIME_TYPE':
|
||||||
constraint['0'] = item.conversion.fileExtension;
|
constraint['0'] = item.conversion.fileExtension;
|
||||||
constraint['1'] = item.conversion.fileMime;
|
constraint['1'] = item.conversion.fileMime;
|
||||||
break;
|
break;
|
||||||
|
@ -108,7 +108,7 @@ const observePresentationConversion = (
|
|||||||
if (doc.temporaryPresentationId !== temporaryPresentationId && doc.id !== tokenId) return;
|
if (doc.temporaryPresentationId !== temporaryPresentationId && doc.id !== tokenId) return;
|
||||||
|
|
||||||
if (doc.conversion.status === 'FILE_TOO_LARGE' || doc.conversion.status === 'UNSUPPORTED_DOCUMENT'
|
if (doc.conversion.status === 'FILE_TOO_LARGE' || doc.conversion.status === 'UNSUPPORTED_DOCUMENT'
|
||||||
|| doc.conversion.status === 'CONVERSION_TIMEOUT' || doc.conversion.status === 'IVALID_MIME_TYPE') {
|
|| doc.conversion.status === 'CONVERSION_TIMEOUT' || doc.conversion.status === 'INVALID_MIME_TYPE') {
|
||||||
Presentations.update(
|
Presentations.update(
|
||||||
{ id: tokenId }, { $set: { temporaryPresentationId, renderedInToast: false } },
|
{ id: tokenId }, { $set: { temporaryPresentationId, renderedInToast: false } },
|
||||||
);
|
);
|
||||||
|
@ -54,8 +54,6 @@ repositories {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
runtimeOnly "com.bertramlabs.plugins:asset-pipeline-grails:4.0.0"
|
runtimeOnly "com.bertramlabs.plugins:asset-pipeline-grails:4.0.0"
|
||||||
runtimeOnly 'org.apache.tika:tika-core:2.8.0'
|
|
||||||
runtimeOnly 'org.apache.tika:tika-parsers-standard-package:2.8.0'
|
|
||||||
|
|
||||||
implementation "org.springframework:spring-core:5.3.21"
|
implementation "org.springframework:spring-core:5.3.21"
|
||||||
implementation "org.springframework:spring-context:5.3.27"
|
implementation "org.springframework:spring-context:5.3.27"
|
||||||
|
Loading…
Reference in New Issue
Block a user