add #976 Admin API: /api/admin/log
This commit is contained in:
parent
87901a305b
commit
c2220909fb
3 changed files with 92 additions and 1 deletions
|
@ -32,6 +32,8 @@ import java.util.stream.Stream;
|
|||
import org.codelibs.core.lang.StringUtil;
|
||||
import org.codelibs.fess.app.web.base.FessAdminAction;
|
||||
import org.codelibs.fess.exception.FessSystemException;
|
||||
import org.codelibs.fess.helper.SystemHelper;
|
||||
import org.codelibs.fess.util.ComponentUtil;
|
||||
import org.codelibs.fess.util.RenderDataUtil;
|
||||
import org.lastaflute.di.exception.IORuntimeException;
|
||||
import org.lastaflute.web.Execute;
|
||||
|
@ -74,7 +76,8 @@ public class AdminLogAction extends FessAdminAction {
|
|||
return redirect(getClass()); // no-op
|
||||
}
|
||||
|
||||
private List<Map<String, Object>> getLogFileItems() {
|
||||
public static List<Map<String, Object>> getLogFileItems() {
|
||||
final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
|
||||
final List<Map<String, Object>> logFileItems = new ArrayList<>();
|
||||
final String logFilePath = systemHelper.getLogFilePath();
|
||||
if (StringUtil.isNotBlank(logFilePath)) {
|
||||
|
|
|
@ -17,6 +17,7 @@ package org.codelibs.fess.app.web.api;
|
|||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.codelibs.fess.Constants;
|
||||
|
@ -148,6 +149,26 @@ public class ApiResult {
|
|||
}
|
||||
}
|
||||
|
||||
public static class ApiLogFilesResponse extends ApiResponse {
|
||||
protected List<Map<String, Object>> logfiles;
|
||||
protected long total = 0;
|
||||
|
||||
public ApiLogFilesResponse logfiles(final List<Map<String, Object>> logfiles) {
|
||||
this.logfiles = logfiles;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ApiLogFilesResponse total(final long total) {
|
||||
this.total = total;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiResult result() {
|
||||
return new ApiResult(this);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ApiErrorResponse extends ApiResponse {
|
||||
protected String message;
|
||||
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* Copyright 2012-2017 CodeLibs Project and the Others.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific language
|
||||
* governing permissions and limitations under the License.
|
||||
*/
|
||||
package org.codelibs.fess.app.web.api.admin.log;
|
||||
|
||||
import static org.codelibs.fess.app.web.admin.log.AdminLogAction.getLogFileItems;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.codelibs.core.lang.StringUtil;
|
||||
import org.codelibs.fess.app.web.api.ApiResult;
|
||||
import org.codelibs.fess.app.web.api.admin.FessApiAdminAction;
|
||||
import org.lastaflute.web.Execute;
|
||||
import org.lastaflute.web.response.JsonResponse;
|
||||
import org.lastaflute.web.response.StreamResponse;
|
||||
|
||||
/**
|
||||
* @author Keiichi Watanabe
|
||||
*/
|
||||
public class ApiAdminLogAction extends FessApiAdminAction {
|
||||
|
||||
// ===================================================================================
|
||||
// Search Execute
|
||||
// ==============
|
||||
|
||||
// GET /api/admin/log/logfiles
|
||||
@Execute
|
||||
public JsonResponse<ApiResult> logfiles() {
|
||||
List<Map<String, Object>> list = getLogFileItems();
|
||||
return asJson(new ApiResult.ApiLogFilesResponse().logfiles(list).total(list.size()).status(ApiResult.Status.OK).result());
|
||||
}
|
||||
|
||||
// GET /api/admin/log/logfile/{id}
|
||||
@Execute
|
||||
public StreamResponse get$logfile(final String id) {
|
||||
final String filename = new String(Base64.getDecoder().decode(id), StandardCharsets.UTF_8).replace("..", "").replaceAll("\\s", "");
|
||||
final String logFilePath = systemHelper.getLogFilePath();
|
||||
if (StringUtil.isNotBlank(logFilePath)) {
|
||||
final Path path = Paths.get(logFilePath, filename);
|
||||
return asStream(filename).contentTypeOctetStream().stream(out -> {
|
||||
try (InputStream in = Files.newInputStream(path)) {
|
||||
out.write(in);
|
||||
}
|
||||
});
|
||||
}
|
||||
return StreamResponse.asEmptyBody();
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue