Skip to content
This repository was archived by the owner on Dec 30, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion configuration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,6 @@ resources:
# Enable/disable documents browse
browse: true
# Enable/disable HTMl rendering mode, false for image mode
htmlMode: true
htmlMode: true
# Enable/disable rewrite for uploaded file if file with the same name already exists
rewrite: true
12 changes: 12 additions & 0 deletions src/main/java/com/aliensoft/quickview/config/QuickViewConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ public class Resources{
@JsonProperty
private boolean htmlMode;

@Valid
@JsonProperty
private boolean rewrite;

public Boolean getRunAsService() {
return runAsService;
}
Expand Down Expand Up @@ -251,6 +255,14 @@ public boolean isHtmlMode() {
public void setHtmlMode(boolean htmlMode) {
this.htmlMode = htmlMode;
}

public boolean isRewrite() {
return rewrite;
}

public void setRewrite(boolean rewrite) {
this.rewrite = rewrite;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,8 @@ public Object uploadDocument(@Context HttpServletRequest request, @Context HttpS
Part filePart = request.getPart("file");
// get document URL
String documentUrl = request.getParameter("url");
// get rewrite mode
boolean rewrite = Boolean.parseBoolean(request.getParameter("rewrite"));
InputStream uploadedInputStream = null;
String fileName = "";
if(documentUrl.isEmpty() || documentUrl == null) {
Expand All @@ -395,7 +397,19 @@ public Object uploadDocument(@Context HttpServletRequest request, @Context HttpS
String documentStoragePath = quickViewConfig.getApplication().getFilesDirectory();
// save the file
File file = new File(documentStoragePath + "/" + fileName);
Files.copy(uploadedInputStream, file.toPath(), StandardCopyOption.REPLACE_EXISTING);
// check rewrite mode
if(rewrite) {
// save file with rewrite if exists
Files.copy(uploadedInputStream, file.toPath(), StandardCopyOption.REPLACE_EXISTING);
} else {
if (file.exists())
{
// get file with new name
file = getFreeFileName(documentStoragePath, fileName);
}
// save file with out rewriting
Files.copy(uploadedInputStream, file.toPath());
}
UploadedDocumentWrapper uploadedDocument = new UploadedDocumentWrapper();
uploadedDocument.setGuid(documentStoragePath + "/" + fileName);
return objectToJson(uploadedDocument);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import org.apache.commons.io.FilenameUtils;
import org.json.JSONException;
import org.json.JSONObject;

Expand All @@ -12,6 +13,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.File;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -113,4 +115,25 @@ protected boolean getJsonBoolean(String json, String key){
return value;
}

protected File getFreeFileName(String directory, String fileName){
File file = null;
try {
File folder = new File(directory);
File[] listOfFiles = folder.listFiles();
for (int i = 0; i < listOfFiles.length; i++) {
int number = i + 1;
String newFileName = FilenameUtils.removeExtension(fileName) + "-Copy(" + number + ")." + FilenameUtils.getExtension(fileName);
file = new File(directory + "/" + newFileName);
if(file.exists()) {
continue;
} else {
break;
}
}
} catch (Exception e) {
e.printStackTrace();
}
return file;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<link type="text/css" rel="stylesheet" href="assets/css/quickview.css"/>
<link type="text/css" rel="stylesheet" href="assets/css/quickview.mobile.css"/>
<link type="text/css" rel="stylesheet" href="assets/css/quickview-dark.css"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript" src="assets/js/quickview.js"></script>
</head>
<body>
Expand All @@ -26,7 +26,8 @@
print: ${config.resources.print?c},
defaultDocument: '${config.resources.defaultDocument}',
browse: ${config.resources.browse?c},
htmlMode: ${config.resources.htmlMode?c}
htmlMode: ${config.resources.htmlMode?c},
rewrite: ${config.resources.rewrite?c}
});
</script>
</body>
Expand Down