mirror of
https://github.com/sismics/docs.git
synced 2024-12-22 19:33:47 +01:00
Closes #116: Allow all file types
This commit is contained in:
parent
c99b1a1867
commit
b36d08db8e
@ -64,7 +64,7 @@ public class PdfUtil {
|
||||
PDFTextStripper stripper = new PDFTextStripper();
|
||||
pdfDocument = PDDocument.load(inputStream);
|
||||
content = stripper.getText(pdfDocument);
|
||||
} catch (IOException e) {
|
||||
} catch (Exception e) {
|
||||
log.error("Error while extracting text from the PDF", e);
|
||||
} finally {
|
||||
if (pdfDocument != null) {
|
||||
|
@ -19,4 +19,6 @@ public class MimeType {
|
||||
public static final String OPEN_DOCUMENT_TEXT = "application/vnd.oasis.opendocument.text";
|
||||
|
||||
public static final String OFFICE_DOCUMENT = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
|
||||
|
||||
public static final String DEFAULT = "application/octet-stream";
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ public class MimeTypeUtil {
|
||||
return MimeType.APPLICATION_PDF;
|
||||
}
|
||||
|
||||
return null;
|
||||
return MimeType.DEFAULT;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -41,6 +41,7 @@ import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.text.MessageFormat;
|
||||
@ -129,10 +130,7 @@ public class FileResource extends BaseResource {
|
||||
} catch (IOException e) {
|
||||
throw new ServerException("ErrorGuessMime", "Error guessing mime type", e);
|
||||
}
|
||||
if (mimeType == null) {
|
||||
throw new ClientException("InvalidFileType", "File type not recognized");
|
||||
}
|
||||
|
||||
|
||||
// Validate quota
|
||||
if (user.getStorageCurrent() + fileData.length > user.getStorageQuota()) {
|
||||
throw new ClientException("QuotaReached", "Quota limit reached");
|
||||
@ -535,7 +533,11 @@ public class FileResource extends BaseResource {
|
||||
mimeType = MimeType.IMAGE_JPEG; // Thumbnails are JPEG
|
||||
decrypt = true; // Thumbnails are encrypted
|
||||
if (!Files.exists(storedFile)) {
|
||||
storedFile = Paths.get(getClass().getResource("/image/file.png").getFile());
|
||||
try {
|
||||
storedFile = Paths.get(getClass().getResource("/image/file.png").toURI());
|
||||
} catch (URISyntaxException e) {
|
||||
// Ignore
|
||||
}
|
||||
mimeType = MimeType.IMAGE_PNG;
|
||||
decrypt = false;
|
||||
}
|
||||
|
@ -39,7 +39,7 @@
|
||||
</dl>
|
||||
|
||||
<div ng-file-drop drag-over-class="bg-success" ng-multiple="true" allow-dir="false" ng-model="dropFiles"
|
||||
accept="image/*,application/pdf,application/zip" ng-file-change="fileDropped($files, $event, $rejectedFiles)">
|
||||
ng-file-change="fileDropped($files, $event, $rejectedFiles)">
|
||||
<div class="row upload-zone" ui-sortable="fileSortableOptions" ng-model="files">
|
||||
<div class="col-xs-6 col-sm-4 col-md-4 col-lg-3 text-center" ng-repeat="file in files">
|
||||
<div class="thumbnail" ng-if="file.id">
|
||||
|
@ -36,7 +36,7 @@ public class TestFileResource extends BaseJerseyTest {
|
||||
/**
|
||||
* Test the file resource.
|
||||
*
|
||||
* @throws Exception
|
||||
* @throws Exception e
|
||||
*/
|
||||
@Test
|
||||
public void testFileResource() throws Exception {
|
||||
@ -197,11 +197,51 @@ public class TestFileResource extends BaseJerseyTest {
|
||||
files = json.getJsonArray("files");
|
||||
Assert.assertEquals(1, files.size());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test using a ZIP file.
|
||||
*
|
||||
* @throws Exception e
|
||||
*/
|
||||
@Test
|
||||
public void testZipFile() throws Exception {
|
||||
// Login file1
|
||||
clientUtil.createUser("file2");
|
||||
String file2Token = clientUtil.login("file2");
|
||||
|
||||
// Create a document
|
||||
long create1Date = new Date().getTime();
|
||||
JsonObject json = target().path("/document").request()
|
||||
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, file2Token)
|
||||
.put(Entity.form(new Form()
|
||||
.param("title", "File test document 1")
|
||||
.param("language", "eng")
|
||||
.param("create_date", Long.toString(create1Date))), JsonObject.class);
|
||||
String document1Id = json.getString("id");
|
||||
Assert.assertNotNull(document1Id);
|
||||
|
||||
// Add a file
|
||||
String file1Id;
|
||||
try (InputStream is = Resources.getResource("file/wikipedia.zip").openStream()) {
|
||||
StreamDataBodyPart streamDataBodyPart = new StreamDataBodyPart("file", is, "wikipedia.zip");
|
||||
try (FormDataMultiPart multiPart = new FormDataMultiPart()) {
|
||||
json = target()
|
||||
.register(MultiPartFeature.class)
|
||||
.path("/file").request()
|
||||
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, file2Token)
|
||||
.put(Entity.entity(multiPart.field("id", document1Id).bodyPart(streamDataBodyPart),
|
||||
MediaType.MULTIPART_FORM_DATA_TYPE), JsonObject.class);
|
||||
file1Id = json.getString("id");
|
||||
Assert.assertNotNull(file1Id);
|
||||
Assert.assertEquals(525069L, json.getJsonNumber("size").longValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test orphan files (without linked document).
|
||||
*
|
||||
* @throws Exception
|
||||
* @throws Exception e
|
||||
*/
|
||||
@Test
|
||||
public void testOrphanFile() throws Exception {
|
||||
@ -291,7 +331,7 @@ public class TestFileResource extends BaseJerseyTest {
|
||||
/**
|
||||
* Test user quota.
|
||||
*
|
||||
* @throws Exception
|
||||
* @throws Exception e
|
||||
*/
|
||||
@Test
|
||||
public void testQuota() throws Exception {
|
||||
|
BIN
docs-web/src/test/resources/file/wikipedia.zip
Normal file
BIN
docs-web/src/test/resources/file/wikipedia.zip
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user