Merge branch 'master' into docker_package

This commit is contained in:
wangliwen 2022-11-08 15:39:00 +08:00
commit 78c11c3671
1 changed files with 36 additions and 0 deletions

View File

@ -9,6 +9,10 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.FileSystemResource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
@ -16,7 +20,10 @@ import org.springframework.web.bind.annotation.RestController;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
@Api(tags = "管理员后台") @Api(tags = "管理员后台")
@RestController @RestController
@ -44,12 +51,41 @@ public class AdminController {
return new Result<String>().ok(String.valueOf(success)); return new Result<String>().ok(String.valueOf(success));
} }
/**
* 列出所有日志文件
*
* @return
*/
@GetMapping(value = "logFiles") @GetMapping(value = "logFiles")
public Result<List<String>> logFiles() { public Result<List<String>> logFiles() {
List<String> result = new ArrayList<>(); List<String> result = new ArrayList<>();
File file = new File(pwd + File.separator + "logs"); File file = new File(pwd + File.separator + "logs");
File[] tempFile = file.listFiles(); File[] tempFile = file.listFiles();
result = Arrays.asList(tempFile).stream().filter(index -> index.isFile()).map(index -> index.getName()).collect(Collectors.toList());
return new Result<List<String>>().ok(result); return new Result<List<String>>().ok(result);
} }
/**
* 下载日志文件
*
* @param file
* @return
*/
@GetMapping(value = "downloadLog")
public ResponseEntity<FileSystemResource> downloadLogFile(String file) {
File file_ = new File(pwd + File.separator + "logs" + File.separator + file);
if (!file_.exists()) {
return null;
}
HttpHeaders headers = new HttpHeaders();
headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
headers.add("Content-Disposition", "attachment; filename=" + file_.getName());
headers.add("Pragma", "no-cache");
headers.add("Expires", "0");
headers.add("Last-Modified", new Date().toString());
headers.add("ETag", String.valueOf(System.currentTimeMillis()));
return ResponseEntity.ok().headers(headers).contentLength(file.length()).contentType(MediaType.parseMediaType("application/octet-stream")).body(new FileSystemResource(file_));
}
} }