refactoring and improve page
This commit is contained in:
parent
3de57084ed
commit
23253b50c7
4 changed files with 80 additions and 43 deletions
|
@ -73,31 +73,25 @@ public class AdminStorageAction extends FessAdminAction {
|
|||
if (form.uploadFile == null) {
|
||||
throwValidationError(messages -> messages.addErrorsStorageNoUploadFile(GLOBAL), () -> asListHtml(form.path));
|
||||
}
|
||||
logger.debug("form.path = {}", form.path);
|
||||
verifyToken(() -> asListHtml(form.path));
|
||||
final String objectName = getObjectName(form.path, form.uploadFile.getFileName());
|
||||
try (final InputStream in = form.uploadFile.getInputStream()) {
|
||||
final MinioClient minioClient = createClient(fessConfig);
|
||||
minioClient.putObject(fessConfig.getStorageBucket(), objectName, in, (long) form.uploadFile.getFileSize(),
|
||||
null, null, "application/octet-stream");
|
||||
minioClient.putObject(fessConfig.getStorageBucket(), objectName, in, (long) form.uploadFile.getFileSize(), null, null,
|
||||
"application/octet-stream");
|
||||
} catch (final Exception e) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Failed to upload {}", objectName, e);
|
||||
}
|
||||
throwValidationError(messages -> messages.addErrorsStorageFileUploadFailure(GLOBAL, e.getLocalizedMessage()), () -> asListHtml(form.path));
|
||||
throwValidationError(messages -> messages.addErrorsStorageFileUploadFailure(GLOBAL, e.getLocalizedMessage()),
|
||||
() -> asListHtml(form.path));
|
||||
}
|
||||
saveInfo(messages -> messages.addSuccessUploadFileToStorage(GLOBAL, form.uploadFile.getFileName()));
|
||||
if (StringUtil.isEmpty(form.path)) {
|
||||
return redirect(getClass());
|
||||
}
|
||||
return redirectWith(getClass(), moreUrl( "list/" + URLEncoder.encode(form.path, Constants.UTF_8_CHARSET)));
|
||||
}
|
||||
|
||||
protected String getObjectName(final String path, final String name) {
|
||||
return URLEncoder.encode((StringUtil.isEmpty(path) ? StringUtil.EMPTY : path + "/") + name, Constants.UTF_8_CHARSET);
|
||||
}
|
||||
|
||||
protected String getId(final String objectName) {
|
||||
return URLEncoder.encode(objectName, Constants.UTF_8_CHARSET);
|
||||
return redirectWith(getClass(), moreUrl("list/" + encodeId(form.path)));
|
||||
}
|
||||
|
||||
@Execute
|
||||
|
@ -110,7 +104,7 @@ public class AdminStorageAction extends FessAdminAction {
|
|||
public ActionResponse download(final String id) {
|
||||
final String[] values = decodeId(id);
|
||||
if (StringUtil.isEmpty(values[1])) {
|
||||
throwValidationError(messages -> messages.addErrorsStorageFileNotFound(GLOBAL), () -> asListHtml(values[0]));
|
||||
throwValidationError(messages -> messages.addErrorsStorageFileNotFound(GLOBAL), () -> asListHtml(encodeId(values[0])));
|
||||
}
|
||||
return asStream(values[1]).contentTypeOctetStream().stream(
|
||||
out -> {
|
||||
|
@ -121,7 +115,7 @@ public class AdminStorageAction extends FessAdminAction {
|
|||
logger.debug("Failed to access {}", fessConfig.getStorageEndpoint(), e);
|
||||
}
|
||||
throwValidationError(messages -> messages.addErrorsStorageAccessError(GLOBAL, e.getLocalizedMessage()),
|
||||
() -> asListHtml(values[0]));
|
||||
() -> asListHtml(encodeId(values[0])));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -130,26 +124,32 @@ public class AdminStorageAction extends FessAdminAction {
|
|||
public HtmlResponse delete(final String id) {
|
||||
final String[] values = decodeId(id);
|
||||
if (StringUtil.isEmpty(values[1])) {
|
||||
throwValidationError(messages -> messages.addErrorsStorageFileNotFound(GLOBAL), () -> asListHtml(values[0]));
|
||||
throwValidationError(messages -> messages.addErrorsStorageFileNotFound(GLOBAL), () -> asListHtml(encodeId(values[0])));
|
||||
}
|
||||
logger.debug("values[0] = {}, values[1] = {}", values[0], values[1]);
|
||||
final String objectName = getObjectName(values[0], values[1]);
|
||||
try {
|
||||
final MinioClient minioClient = createClient(fessConfig);
|
||||
minioClient.removeObject(fessConfig.getStorageBucket(), values[0] + "/" + values[1]);
|
||||
minioClient.removeObject(fessConfig.getStorageBucket(), objectName);
|
||||
} catch (final Exception e) {
|
||||
logger.debug("Failed to delete {}", values[0] + "/" + values[1], e);
|
||||
throwValidationError(messages -> messages.addErrorsFailedToDeleteFile(GLOBAL, e.getLocalizedMessage()), () -> asListHtml(values[0]));
|
||||
logger.debug("Failed to delete {}", values[1], e);
|
||||
throwValidationError(messages -> messages.addErrorsFailedToDeleteFile(GLOBAL, e.getLocalizedMessage()),
|
||||
() -> asListHtml(encodeId(values[0])));
|
||||
}
|
||||
saveInfo(messages -> messages.addSuccessDeleteFile(GLOBAL, values[0] + "/" + values[1]));
|
||||
return redirectWith(getClass(), moreUrl("list/" + URLEncoder.encode(getObjectName(null, values[0]), Constants.UTF_8_CHARSET)));
|
||||
saveInfo(messages -> messages.addSuccessDeleteFile(GLOBAL, values[1]));
|
||||
if (StringUtil.isEmpty(values[0])) {
|
||||
return redirect(getClass());
|
||||
}
|
||||
return redirectWith(getClass(), moreUrl("list/" + encodeId(values[0])));
|
||||
}
|
||||
|
||||
@Execute
|
||||
public HtmlResponse createDir(final ItemForm form) {
|
||||
validate(form, messages -> {}, () -> asListHtml(form.path));
|
||||
if (StringUtil.isBlank(form.name)) {
|
||||
//TODO throwValidationError(messages -> messages.addErrorsStorageCreateDirNameBlank(GLOBAL), () -> asListHtml(form.path));
|
||||
throwValidationError(messages -> messages.addErrorsStorageDirectoryNameIsInvalid(GLOBAL), () -> asListHtml(form.path));
|
||||
}
|
||||
return redirectWith(getClass(), moreUrl("list/" + URLEncoder.encode(getObjectName(form.path, form.name), Constants.UTF_8_CHARSET)));
|
||||
return redirectWith(getClass(), moreUrl("list/" + encodeId(getObjectName(form.path, form.name))));
|
||||
}
|
||||
|
||||
public static List<Map<String, Object>> getFileItems(final String prefix) {
|
||||
|
@ -164,7 +164,8 @@ public class AdminStorageAction extends FessAdminAction {
|
|||
final String objectName = item.objectName();
|
||||
map.put("id", URLEncoder.encode(objectName, Constants.UTF_8_CHARSET));
|
||||
map.put("name", getName(objectName));
|
||||
map.put("size", item.size());
|
||||
map.put("hashCode", item.hashCode());
|
||||
map.put("size", item.objectSize());
|
||||
map.put("directory", item.isDir());
|
||||
if (!item.isDir()) {
|
||||
map.put("lastModified", item.lastModified());
|
||||
|
@ -241,7 +242,7 @@ public class AdminStorageAction extends FessAdminAction {
|
|||
}
|
||||
buf.append(values[i]);
|
||||
}
|
||||
return URLEncoder.encode(buf.toString(), Constants.UTF_8_CHARSET);
|
||||
return urlEncode(buf.toString());
|
||||
}
|
||||
return StringUtil.EMPTY;
|
||||
}
|
||||
|
@ -255,13 +256,32 @@ public class AdminStorageAction extends FessAdminAction {
|
|||
}
|
||||
buf.append(s);
|
||||
final Map<String, String> map = new HashMap<>();
|
||||
map.put("id", URLEncoder.encode(buf.toString(), Constants.UTF_8_CHARSET));
|
||||
map.put("id", urlEncode(buf.toString()));
|
||||
map.put("name", s);
|
||||
list.add(map);
|
||||
}));
|
||||
return list;
|
||||
}
|
||||
|
||||
protected static String getPathPrefix(final String path) {
|
||||
return StringUtil.isEmpty(path) ? StringUtil.EMPTY : path + "/";
|
||||
}
|
||||
|
||||
protected static String getObjectName(final String path, final String name) {
|
||||
return getPathPrefix(path) + name;
|
||||
}
|
||||
|
||||
protected static String urlEncode(final String str) {
|
||||
if (str == null) {
|
||||
return null;
|
||||
}
|
||||
return URLEncoder.encode(str, Constants.UTF_8_CHARSET);
|
||||
}
|
||||
|
||||
protected static String encodeId(final String str) {
|
||||
return urlEncode(urlEncode(str));
|
||||
}
|
||||
|
||||
private HtmlResponse asListHtml(final String prefix) {
|
||||
return asHtml(path_AdminStorage_AdminStorageJsp).useForm(ItemForm.class).renderWith(data -> {
|
||||
RenderDataUtil.register(data, "endpoint", fessConfig.getStorageEndpoint());
|
||||
|
|
|
@ -419,6 +419,9 @@ public class FessMessages extends FessLabels {
|
|||
/** The key of the message: Upload file is required. */
|
||||
public static final String ERRORS_storage_no_upload_file = "{errors.storage_no_upload_file}";
|
||||
|
||||
/** The key of the message: Directory name is invalid. */
|
||||
public static final String ERRORS_storage_directory_name_is_invalid = "{errors.storage_directory_name_is_invalid}";
|
||||
|
||||
/** The key of the message: Updated parameters. */
|
||||
public static final String SUCCESS_update_crawler_params = "{success.update_crawler_params}";
|
||||
|
||||
|
@ -2414,6 +2417,20 @@ public class FessMessages extends FessLabels {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the created action message for the key 'errors.storage_directory_name_is_invalid' with parameters.
|
||||
* <pre>
|
||||
* message: Directory name is invalid.
|
||||
* </pre>
|
||||
* @param property The property name for the message. (NotNull)
|
||||
* @return this. (NotNull)
|
||||
*/
|
||||
public FessMessages addErrorsStorageDirectoryNameIsInvalid(String property) {
|
||||
assertPropertyNotNull(property);
|
||||
add(property, new UserMessage(ERRORS_storage_directory_name_is_invalid));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the created action message for the key 'success.update_crawler_params' with parameters.
|
||||
* <pre>
|
||||
|
|
|
@ -165,6 +165,7 @@ errors.storage_file_not_found=The target file is not found in Storage.
|
|||
errors.storage_file_download_failure=Failed to download {0}.
|
||||
errors.storage_access_error=Storage access error: {0}
|
||||
errors.storage_no_upload_file=Upload file is required.
|
||||
errors.storage_directory_name_is_invalid=Directory name is invalid.
|
||||
|
||||
success.update_crawler_params=Updated parameters.
|
||||
success.delete_doc_from_index=Started a process to delete the document from index.
|
||||
|
|
|
@ -42,16 +42,17 @@
|
|||
<div class="data-wrapper">
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<a class="fa fa-home" aria-hidden="true" href="${contextPath}/admin/storage/">(Path: ${f:h(endpoint)}/${f:h(bucket)})</a>
|
||||
<a class="fa fa-home" aria-hidden="true" href="${contextPath}/admin/storage/">(Bucket: ${f:h(endpoint)}/${f:h(bucket)})</a>
|
||||
<c:forEach var="item" varStatus="s" items="${pathItems}">
|
||||
<i class="fa fa-chevron-right" aria-hidden="true"></i>
|
||||
<a href="${contextPath}/admin/storage/list/${f:u(item.id)}/">${f:h(item.name)}</a>
|
||||
<span><a href="${contextPath}/admin/storage/list/${f:u(item.id)}/">${f:h(item.name)}</a></span>
|
||||
</c:forEach>
|
||||
<i class="fa fa-chevron-right" aria-hidden="true"></i>
|
||||
<button type="button" class="btn btn-success btn-xs" name="upload" data-toggle="modal"
|
||||
|
||||
<div type="button" class="btn btn-success btn-xs" name="createDir" data-toggle="modal"
|
||||
data-target="#createDir">
|
||||
<i class="fa fa-plus-square" aria-hidden="true"></i>
|
||||
</button>
|
||||
<i class="fa fa-plus" aria-hidden="true"></i>
|
||||
</div>
|
||||
|
||||
<div class="modal modal-primary" id="createDir"
|
||||
tabindex="-1" role="dialog"
|
||||
|
@ -87,16 +88,17 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<a href="${contextPath}/admin/storage/list/${f:u(item.id)}/">${f:h(item.name)}</a>
|
||||
|
||||
<button type="button" class="btn btn-success pull-right" name="upload" data-toggle="modal"
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<div type="button" class="btn btn-success pull-right" name="upload" data-toggle="modal"
|
||||
data-target="#uploadeFile"
|
||||
value="<la:message key="labels.storage_button_upload" />"
|
||||
>
|
||||
<em class="fa fa-upload"></em>
|
||||
<la:message key="labels.storage_button_upload" />
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal modal-primary" id="uploadeFile"
|
||||
tabindex="-1" role="dialog"
|
||||
>
|
||||
|
@ -107,15 +109,12 @@
|
|||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
<h4 class="modal-title">
|
||||
<!-- la:message key="labels.crud_title_delete" / -->
|
||||
Upload
|
||||
<la:message key="labels.storage_upload_file" />
|
||||
</h4>
|
||||
</div>
|
||||
<div class="modal-body col-sm-12">
|
||||
<la:form action="/admin/storage/upload/" enctype="multipart/form-data" styleClass="form-inline">
|
||||
<div class="form-group">
|
||||
<label for="uploadFile"> <la:message key="labels.storage_upload_file" />
|
||||
</label>
|
||||
<input type="file" name="uploadFile" class="form-control" />
|
||||
</div>
|
||||
<input type="hidden" name="path" value="${path}" />
|
||||
|
@ -134,8 +133,9 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<table class="table table-bordered table-striped dataTable">
|
||||
<tbody>
|
||||
|
@ -167,7 +167,7 @@
|
|||
${f:h(data.name)}
|
||||
</td>
|
||||
<td>${f:h(data.size)}</td>
|
||||
<td>${f:h(data.lastModifed)}</td>
|
||||
<td>${f:h(data.lastModified)}</td>
|
||||
</c:if>
|
||||
<c:if test="${data.directory.booleanValue()}">
|
||||
<tr
|
||||
|
@ -189,13 +189,13 @@
|
|||
<la:message key="labels.design_download_button" />
|
||||
</a>
|
||||
<button type="button" class="btn btn-danger btn-xs" name="delete" data-toggle="modal"
|
||||
data-target='#confirmToDelete-${f:h(data.name).replace(".", "\\.")}'
|
||||
data-target="#confirmToDelete-${f:h(data.hashCode)}"
|
||||
value="<la:message key="labels.design_delete_button" />"
|
||||
>
|
||||
<em class="fa fa-times"></em>
|
||||
<la:message key="labels.design_delete_button" />
|
||||
</button>
|
||||
<div class="modal modal-danger fade" id='confirmToDelete-${f:h(data.name)}'
|
||||
<div class="modal modal-danger fade" id="confirmToDelete-${f:h(data.hashCode)}"
|
||||
tabindex="-1" role="dialog"
|
||||
>
|
||||
<div class="modal-dialog">
|
||||
|
@ -252,4 +252,3 @@
|
|||
<jsp:include page="/WEB-INF/view/common/admin/foot.jsp"></jsp:include>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue