Parcourir la source

1.删除 SysFileController
2.停止记录 AccessLog 和 RuntimeLog

reghao il y a 3 mois
Parent
commit
9f2e50b73a

+ 0 - 103
web/src/main/java/cn/reghao/bnt/web/admin/controller/SysFileController.java

@@ -1,103 +0,0 @@
-package cn.reghao.bnt.web.admin.controller;
-
-import cn.reghao.bnt.web.admin.model.vo.DiskFileInfo;
-import cn.reghao.bnt.web.admin.model.vo.UploadFile;
-import cn.reghao.bnt.web.admin.service.FileService;
-import cn.reghao.bnt.web.admin.model.vo.FileInfo;
-import cn.reghao.jutil.web.WebResult;
-import cn.reghao.jutil.web.ServletUtil;
-import cn.reghao.bnt.web.admin.model.po.DiskFile;
-import io.swagger.v3.oas.annotations.tags.Tag;
-import io.swagger.v3.oas.annotations.Operation;
-import org.springframework.data.domain.Page;
-import org.springframework.http.MediaType;
-import org.springframework.stereotype.Controller;
-import org.springframework.ui.ModelMap;
-import org.springframework.web.bind.annotation.*;
-import org.springframework.web.multipart.MultipartFile;
-
-import jakarta.servlet.http.HttpServletRequest;
-import jakarta.validation.constraints.NotNull;
-import java.io.IOException;
-import java.net.URLDecoder;
-import java.nio.charset.StandardCharsets;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * @author reghao
- * @date 2024-01-20 17:24:58
- */
-@Tag(name = "文件接口")
-@Controller
-@RequestMapping("/bg/file")
-public class SysFileController {
-    private final FileService fileService;
-
-    public SysFileController(FileService fileService) {
-        this.fileService = fileService;
-    }
-
-    @Operation(summary = "文件列表页面", description = "N")
-    @GetMapping("/list")
-    public String fileList(ModelMap model) {
-        int pageNumber = Integer.parseInt(ServletUtil.getRequestParam("pageNo", "1"));
-        Page<FileInfo> page = fileService.getDiskFiles(pageNumber);
-
-        int showTitle = 2;
-        String uploadPage = String.format("/bg/file/upload?channelCode=%s", showTitle);
-
-        model.addAttribute("parentDirs", Collections.emptyList());
-        model.put("page", page);
-        model.addAttribute("uploadPage", uploadPage);
-        model.addAttribute("showTitle", 2);
-        return "/admin/console/object/objectlist";
-    }
-
-    @Operation(summary = "图片列表页面", description = "N")
-    @GetMapping("/image")
-    public String imageList(ModelMap model) {
-        int pageNumber = Integer.parseInt(ServletUtil.getRequestParam("pageNo", "1"));
-        Page<DiskFileInfo> page = fileService.getImageFiles(pageNumber);
-        model.put("page", page);
-        return "/admin/file/imglist";
-    }
-
-    @Operation(summary = "文件上传页面", description = "N")
-    @GetMapping("/upload")
-    public String uploadPage(ModelMap model, @NotNull Integer channelCode) {
-        String ossUrl = "/bg/file/upload";
-        String path = "/";
-        model.addAttribute("ossUrl", ossUrl);
-        model.addAttribute("path", path);
-        return "/admin/file/fileupload";
-    }
-
-    @Operation(summary = "文件上传接口", description = "N")
-    @PostMapping(value = "/upload", produces = MediaType.APPLICATION_JSON_VALUE)
-    @ResponseBody
-    public String uploadFile(UploadFile uploadFile) throws Exception {
-        MultipartFile file = uploadFile.getFile();
-        DiskFile diskFile = fileService.putDiskFile(file);
-        String url = String.format("/%s", diskFile.getObjectName());
-        Map<String, String> map = new HashMap<>();
-        map.put("name", file.getOriginalFilename());
-        map.put("url", url);
-        return WebResult.success(map);
-    }
-
-    @Operation(summary = "文件预览接口", description = "N")
-    @GetMapping(value = "/preview", produces = MediaType.APPLICATION_JSON_VALUE)
-    @ResponseBody
-    public String previewFile(@RequestParam("objectId") String objectId) {
-        DiskFile diskFile = fileService.getDiskFile(objectId);
-        String objectName = diskFile.getObjectName();
-
-        Map<String, Object> map = new HashMap<>();
-        map.put("filename", diskFile.getFilename());
-        map.put("fileType", diskFile.getFileType());
-        map.put("url", "/"+objectName);
-        return WebResult.success(map);
-    }
-}

+ 0 - 20
web/src/main/java/cn/reghao/bnt/web/admin/db/repository/DiskFileRepository.java

@@ -1,20 +0,0 @@
-package cn.reghao.bnt.web.admin.db.repository;
-
-import cn.reghao.bnt.web.admin.model.po.DiskFile;
-import org.springframework.data.domain.Page;
-import org.springframework.data.domain.Pageable;
-import org.springframework.data.jpa.repository.JpaRepository;
-
-import java.util.List;
-
-/**
- * @author reghao
- * @date 2024-01-29 09:24:29
- */
-public interface DiskFileRepository extends JpaRepository<DiskFile, Integer> {
-    DiskFile findByObjectName(String objectName);
-    DiskFile findByObjectId(String objectId);
-    Page<DiskFile> findByOwner(int owner, Pageable pageable);
-    Page<DiskFile> findByFileTypeAndOwner(int fileType, int owner, Pageable pageable);
-    List<DiskFile> findBySha256sum(String sha256sum);
-}

+ 1 - 1
web/src/main/java/cn/reghao/bnt/web/admin/model/po/AccessLog.java

@@ -19,7 +19,7 @@ import jakarta.persistence.Table;
 @Setter
 @Getter
 @Entity
-@Table(name = "sys_access_log")
+@Table(name = "sys1_access_log")
 public class AccessLog extends BaseEntity {
     private String requestId;
     private String requestMethod;

+ 0 - 66
web/src/main/java/cn/reghao/bnt/web/admin/model/po/DiskFile.java

@@ -1,66 +0,0 @@
-package cn.reghao.bnt.web.admin.model.po;
-
-import cn.reghao.bnt.web.admin.service.UserContext;
-import cn.reghao.bnt.web.util.BaseEntity;
-import lombok.AllArgsConstructor;
-import lombok.Getter;
-import lombok.NoArgsConstructor;
-import lombok.Setter;
-
-import jakarta.persistence.Column;
-import jakarta.persistence.Entity;
-import jakarta.persistence.Table;
-
-/**
- * @author reghao
- * @date 2023-11-11 00:06:21
- */
-@NoArgsConstructor
-@AllArgsConstructor
-@Setter
-@Getter
-@Entity
-@Table(name = "sys1_disk_file")
-public class DiskFile extends BaseEntity {
-    @Column(nullable = false, unique = true)
-    private String objectName;
-    @Column(nullable = false, unique = true)
-    private String objectId;
-    @Column(nullable = false)
-    private String absolutePath;
-    @Column(nullable = false)
-    private String sha256sum;
-    @Column(nullable = false)
-    private String filename;
-    @Column(nullable = false)
-    private String contentType;
-    private Integer fileType;
-    @Column(nullable = false)
-    private Long size;
-    private Integer owner;
-
-    public DiskFile(String objectName, String objectId, DiskFile diskFile, String filename) {
-        this.objectName = objectName;
-        this.objectId = objectId;
-        this.absolutePath = diskFile.getAbsolutePath();
-        this.sha256sum = diskFile.getSha256sum();
-        this.filename = filename;
-        this.contentType = diskFile.getContentType();
-        this.fileType = diskFile.getFileType();
-        this.size = diskFile.getSize();
-        this.owner = UserContext.getUserId();
-    }
-
-    public DiskFile(String objectName, String objectId, String absolutePath, String sha256sum,
-                    String filename, String contentType, int fileType, long size) {
-        this.objectName = objectName;
-        this.objectId = objectId;
-        this.absolutePath = absolutePath;
-        this.sha256sum = sha256sum;
-        this.filename = filename;
-        this.contentType = contentType;
-        this.fileType = fileType;
-        this.size = size;
-        this.owner = UserContext.getUserId();
-    }
-}

+ 1 - 1
web/src/main/java/cn/reghao/bnt/web/admin/model/po/RuntimeLog.java

@@ -18,7 +18,7 @@ import jakarta.persistence.Table;
 @Setter
 @Getter
 @Entity
-@Table(name = "sys_runtime_log")
+@Table(name = "sys1_runtime_log")
 public class RuntimeLog extends BaseEntity {
     private String requestId;
     private String app;

+ 1 - 1
web/src/main/java/cn/reghao/bnt/web/admin/model/po/UserMessage.java

@@ -15,7 +15,7 @@ import jakarta.persistence.Table;
 @NoArgsConstructor
 @Setter
 @Getter
-@Table(name = "sys1_user_message")
+@Table(name = "sys_user_message")
 @Entity
 public class UserMessage extends BaseEntity {
     private String title;

+ 1 - 1
web/src/main/java/cn/reghao/bnt/web/admin/model/po/Webhook.java

@@ -16,7 +16,7 @@ import jakarta.validation.constraints.NotBlank;
 @Setter
 @Getter
 @Entity
-@Table(name = "sys1_notify_webhook")
+@Table(name = "sys_notify_webhook")
 public class Webhook extends BaseEntity {
     @Column(nullable = false, unique = true)
     private String name;

+ 0 - 20
web/src/main/java/cn/reghao/bnt/web/admin/model/vo/DiskFileInfo.java

@@ -1,20 +0,0 @@
-package cn.reghao.bnt.web.admin.model.vo;
-
-import lombok.AllArgsConstructor;
-import lombok.Getter;
-
-/**
- * @author reghao
- * @date 2024-10-30 17:37:17
- */
-@AllArgsConstructor
-@Getter
-public class DiskFileInfo {
-    private String fileId;
-    private String filename;
-    private String url;
-
-    public void setUrl(String url) {
-        this.url = url;
-    }
-}

+ 0 - 30
web/src/main/java/cn/reghao/bnt/web/admin/model/vo/FileInfo.java

@@ -1,30 +0,0 @@
-package cn.reghao.bnt.web.admin.model.vo;
-
-import cn.reghao.bnt.web.admin.model.po.DiskFile;
-import cn.reghao.jutil.jdk.converter.DateTimeConverter;
-import lombok.AllArgsConstructor;
-import lombok.Getter;
-
-/**
- * @author reghao
- * @date 2024-10-30 10:24:28
- */
-@AllArgsConstructor
-@Getter
-public class FileInfo {
-    private String fileId;
-    private String filename;
-    private String updateTime;
-    private String size;
-    private int fileType;
-    private String fileTypeStr;
-
-    public FileInfo(DiskFile diskFile, String size) {
-        this.fileId = diskFile.getObjectId();
-        this.filename = diskFile.getFilename();
-        this.updateTime = DateTimeConverter.format(diskFile.getUpdateTime());
-        this.size = size;
-        this.fileType = diskFile.getFileType();
-        this.fileTypeStr = "";
-    }
-}

+ 0 - 233
web/src/main/java/cn/reghao/bnt/web/admin/service/FileService.java

@@ -1,233 +0,0 @@
-package cn.reghao.bnt.web.admin.service;
-
-import cn.reghao.bnt.web.admin.model.vo.DiskFileInfo;
-import cn.reghao.bnt.web.admin.model.vo.FileInfo;
-import cn.reghao.jutil.jdk.converter.ByteConverter;
-import cn.reghao.jutil.jdk.converter.ByteType;
-import cn.reghao.jutil.jdk.security.DigestUtil;
-import cn.reghao.jutil.web.ServletUtil;
-import cn.reghao.bnt.web.admin.db.repository.DiskFileRepository;
-import cn.reghao.bnt.web.admin.model.po.DiskFile;
-import cn.reghao.bnt.web.config.AppProperties;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.io.FileUtils;
-import org.springframework.cache.annotation.Cacheable;
-import org.springframework.data.domain.Page;
-import org.springframework.data.domain.PageImpl;
-import org.springframework.data.domain.PageRequest;
-import org.springframework.data.domain.Sort;
-import org.springframework.stereotype.Service;
-import org.springframework.web.multipart.MultipartFile;
-
-import jakarta.annotation.PostConstruct;
-import jakarta.servlet.http.HttpServletResponse;
-import java.io.*;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.StandardCopyOption;
-import java.util.List;
-import java.util.UUID;
-import java.util.stream.Collectors;
-
-/**
- * @author reghao
- * @date 2024-01-19 21:29:24
- */
-@Slf4j
-@Service
-public class FileService {
-    // 8MiB
-    private final int bufSize = 1024*1024*8;
-    private final AppProperties appProperties;
-    private final DiskFileRepository diskFileRepository;
-    private final ByteConverter byteConverter;
-
-    public FileService(DiskFileRepository diskFileRepository, AppProperties appProperties, ByteConverter byteConverter) {
-        this.diskFileRepository = diskFileRepository;
-        this.appProperties = appProperties;
-        this.byteConverter = byteConverter;
-    }
-
-    @PostConstruct
-    public void initLuceneDir() throws IOException {
-        String luceneDir = appProperties.getLuceneDir();
-        File dir2 = new File(luceneDir);
-        if (!dir2.exists()) {
-            log.info("创建索引目录...");
-            FileUtils.forceMkdir(dir2);
-        }
-    }
-
-    public void getFile(String objectName) throws IOException {
-        DiskFile diskFile = getByObjectName(objectName);
-        if (diskFile == null) {
-            log.error("DiskFile {} not exist", objectName);
-            writeResponse(HttpServletResponse.SC_NOT_FOUND);
-            return;
-        }
-
-        String absolutePath = diskFile.getAbsolutePath();
-        File file = new File(absolutePath);
-        if (!file.exists() || file.isDirectory()) {
-            log.error("file {} not exist", absolutePath);
-            writeResponse(HttpServletResponse.SC_NOT_FOUND);
-            return;
-        }
-
-        String contentType = diskFile.getContentType();
-        long size = diskFile.getSize();
-        HttpServletResponse response = ServletUtil.getResponse();
-        response.setStatus(HttpServletResponse.SC_OK);
-        response.setContentType(contentType);
-        response.setContentLengthLong(size);
-
-        OutputStream outputStream = response.getOutputStream();
-        writeResponse(outputStream, absolutePath, 0, size);
-    }
-
-    @Cacheable(cacheNames = "filePaths", key = "#objectName", unless = "#result == null")
-    public DiskFile getByObjectName(String objectName) {
-        DiskFile diskFile = diskFileRepository.findByObjectName(objectName);
-        return diskFile;
-    }
-
-    private void writeResponse(int statusCode) throws IOException {
-        HttpServletResponse response = ServletUtil.getResponse();
-        response.setStatus(statusCode);
-        OutputStream outputStream = response.getOutputStream();
-        outputStream.flush();
-        outputStream.close();
-    }
-
-    private void writeResponse(OutputStream outputStream, String absolutePath, long start, long end) throws IOException {
-        RandomAccessFile raf = new RandomAccessFile(absolutePath, "r");
-        raf.seek(start);
-
-        long len = end-start+1;
-        if (len < bufSize) {
-            int len1 = (int) len;
-            byte[] buf1 = new byte[len1];
-            int readLen1 = raf.read(buf1, 0, len1);
-            outputStream.write(buf1, 0, readLen1);
-        } else {
-            byte[] buf = new byte[bufSize];
-            long totalRead = 0;
-            int readLen;
-            while ((readLen = raf.read(buf, 0, bufSize)) != -1) {
-                outputStream.write(buf, 0, readLen);
-                totalRead += readLen;
-
-                long left = len - totalRead;
-                if (left < bufSize) {
-                    int left1 = (int) left;
-                    byte[] buf1 = new byte[left1];
-                    int readLen1 = raf.read(buf1, 0, left1);
-                    outputStream.write(buf1, 0, readLen1);
-                    break;
-                }
-            }
-        }
-
-        outputStream.flush();
-        outputStream.close();
-        raf.close();
-    }
-
-    public DiskFile putDiskFile(MultipartFile file) throws Exception {
-        long size = file.getSize();
-        String filename = file.getOriginalFilename();
-        String suffix = getSuffix(filename);
-
-        String objectId = UUID.randomUUID().toString().replace("-", "");;
-        String objectName;
-        if (suffix.isBlank()) {
-            objectName = String.format("file/%s", objectId);
-        } else {
-            objectName = String.format("file/%s%s", objectId, suffix);
-        }
-
-        String contentId = UUID.randomUUID().toString().replace("-", "");
-        String fileDir = appProperties.getFileDir();
-        String destPath = String.format("%s/%s", fileDir, contentId);
-        File savedFile = saveFile(file.getInputStream(), destPath);
-        String contentType = "image/jpeg";
-        int fileType = 1001;
-        String sha256sum = DigestUtil.sha256sum(savedFile.getAbsolutePath());
-
-        List<DiskFile> diskFiles = diskFileRepository.findBySha256sum(sha256sum);
-        DiskFile diskFile;
-        if (!diskFiles.isEmpty()) {
-            DiskFile existFile = diskFiles.get(0);
-            diskFile = new DiskFile(objectName, objectId, existFile, filename);
-            FileUtils.deleteQuietly(savedFile);
-        } else {
-            diskFile = new DiskFile(objectName, objectId, savedFile.getAbsolutePath(), sha256sum, filename, contentType, fileType, size);
-        }
-
-        diskFileRepository.save(diskFile);
-        return diskFile;
-    }
-
-    private File saveFile(InputStream inputStream, String absolutePath) throws IOException {
-        File file = new File(absolutePath);
-        if (file.exists()) {
-            throw new IOException(absolutePath + " exist");
-        }
-
-        Files.copy(inputStream, Path.of(absolutePath), StandardCopyOption.REPLACE_EXISTING);
-        return file;
-    }
-
-    private String getSuffix(String filename) {
-        if (filename == null) {
-            return "";
-        }
-
-        int idx = filename.lastIndexOf(".");
-        return idx == -1 ? "" : filename.substring(idx);
-    }
-
-    public Page<FileInfo> getDiskFiles(int pageNumber) {
-        int owner = UserContext.getUserId();
-        Sort sort = Sort.by(Sort.Direction.DESC, "createTime");
-        int pageSize = 12;
-        PageRequest pageRequest = PageRequest.of(pageNumber-1, pageSize, sort);
-        Page<DiskFile> page = diskFileRepository.findByOwner(owner, pageRequest);
-        List<FileInfo> list = page.getContent().stream().map(diskFile -> {
-            String size = byteConverter.convert(ByteType.Bytes, diskFile.getSize());
-            return new FileInfo(diskFile, size);
-        }).collect(Collectors.toList());
-
-        return new PageImpl<>(list, pageRequest, page.getTotalElements());
-    }
-
-    public Page<DiskFileInfo> getImageFiles(int pageNumber) {
-        int owner = UserContext.getUserId();
-        Sort sort = Sort.by(Sort.Direction.DESC, "createTime");
-        int pageSize = 12;
-        PageRequest pageRequest = PageRequest.of(pageNumber-1, pageSize, sort);
-        int fileType = 1001;
-        Page<DiskFile> page = diskFileRepository.findByFileTypeAndOwner(fileType, owner, pageRequest);
-        List<DiskFileInfo> list = page.getContent().stream().map(diskFile -> {
-            String fileId = diskFile.getObjectId();
-            String filename = diskFile.getFilename();
-            String objectName = diskFile.getObjectName();
-            String url = String.format("/%s", objectName);
-            return new DiskFileInfo(fileId, filename, url);
-        }).collect(Collectors.toList());
-        return new PageImpl<>(list, pageRequest, page.getTotalElements());
-    }
-
-    public DiskFile getDiskFile(String objectId) {
-        return diskFileRepository.findByObjectId(objectId);
-    }
-
-    public String getObjectName(String path) {
-        String objectName = "";
-        if (!path.equals("/")) {
-            objectName = path.substring(1) + "/";
-        }
-
-        return objectName;
-    }
-}

+ 1 - 1
web/src/main/java/cn/reghao/bnt/web/config/AccessInterceptor.java

@@ -40,7 +40,7 @@ public class AccessInterceptor implements HandlerInterceptor {
     @Override
     public void postHandle(HttpServletRequest request, HttpServletResponse response,
                            Object handler, @Nullable ModelAndView modelAndView) throws Exception {
-        logService.saveAccessLog();
+        //logService.saveAccessLog();
     }
 
     @Override

+ 0 - 3
web/src/main/java/cn/reghao/bnt/web/config/AppProperties.java

@@ -19,7 +19,4 @@ import java.util.Map;
 public class AppProperties {
     private String baseDir;
     private String devopsDir;
-    private String luceneDir;
-    private String fileDir;
-    private Map<String, String> options = new HashMap<>();
 }

+ 1 - 1
web/src/main/java/cn/reghao/bnt/web/config/log/MyLogbackAppender.java

@@ -92,7 +92,7 @@ public class MyLogbackAppender extends UnsynchronizedAppenderBase<ILoggingEvent>
 
         AppLog appLog = getAppLog(event);
         if (logService != null) {
-            logService.consumeAppLog(appLog);
+            //logService.consumeAppLog(appLog);
         } else {
             // 此处自定义实现输出
             // 获取输出值:event.getFormattedMessage()

+ 0 - 6
web/src/main/java/cn/reghao/bnt/web/config/spring/BeanConfig.java

@@ -1,7 +1,6 @@
 package cn.reghao.bnt.web.config.spring;
 
 import cn.reghao.bnt.common.machine.*;
-import cn.reghao.bnt.web.util.JarFileResources;
 import cn.reghao.jutil.jdk.converter.ByteConverter;
 import cn.reghao.jutil.jdk.http.WebClient;
 import cn.reghao.jutil.jdk.http.WebRequest;
@@ -72,9 +71,4 @@ public class BeanConfig {
     public OS os() {
         return new OS(systemInfo(), byteConverter());
     }
-
-    @Bean
-    public JarFileResources jarFileResources() {
-        return new JarFileResources();
-    }
 }

+ 1 - 19
web/src/main/java/cn/reghao/bnt/web/config/spring/SpringLifecycle.java

@@ -21,11 +21,8 @@ import org.springframework.context.event.EventListener;
 import org.springframework.core.annotation.Order;
 import org.springframework.core.env.Environment;
 import org.springframework.stereotype.Component;
-import org.springframework.web.context.ServletContextAware;
 
-import jakarta.servlet.ServletContext;
 import java.io.IOException;
-import java.util.Map;
 
 /**
  * @author reghao
@@ -34,10 +31,8 @@ import java.util.Map;
 @Slf4j
 @Order(2)
 @Component
-public class SpringLifecycle implements ApplicationRunner, DisposableBean, ServletContextAware {
-    private ServletContext servletContext;
+public class SpringLifecycle implements ApplicationRunner, DisposableBean {
     private final MachineService machineService;
-    private final AppProperties appProperties;
     private final LogService logService;
     private final Environment environment;
     private final BuilderInit builderInit;
@@ -45,20 +40,13 @@ public class SpringLifecycle implements ApplicationRunner, DisposableBean, Servl
     public SpringLifecycle(MachineService machineService, AppProperties appProperties,
                            LogService logService, Environment environment, BuilderInit builderInit) {
         this.machineService = machineService;
-        this.appProperties = appProperties;
         this.logService = logService;
         this.environment = environment;
         this.builderInit = builderInit;
     }
 
-    @Override
-    public void setServletContext(ServletContext servletContext) {
-        this.servletContext = servletContext;
-    }
-
     @Override
     public void run(ApplicationArguments args) throws IOException {
-        loadOptions();
         initSys();
         log.info("bnt started");
     }
@@ -69,12 +57,6 @@ public class SpringLifecycle implements ApplicationRunner, DisposableBean, Servl
         log.info("bnt shutdown...");
     }
 
-    public void loadOptions() {
-        Map<String, String> options = appProperties.getOptions();
-        servletContext.setAttribute("options", options);
-        servletContext.setAttribute("site", appProperties);
-    }
-
     private void initSys() {
         builderInit.init();
     }

+ 0 - 102
web/src/main/java/cn/reghao/bnt/web/util/JarFileResources.java

@@ -1,102 +0,0 @@
-package cn.reghao.bnt.web.util;
-
-import java.io.*;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.net.URLDecoder;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.FileSystem;
-import java.nio.file.FileSystems;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.Collections;
-import java.util.List;
-import java.util.stream.Collectors;
-
-/**
- * 获取 jar 包内的文件资源
- * 
- * @author reghao
- * @date 2025-11-03 16:05:43
- */
-public class JarFileResources {
-    /**
-     * get a file from the resources folder
-     * works everywhere, IDEA, unit test and jar file.
-     * 
-     * @param
-     * @return
-     * @date 2025-11-03 16:07:27
-     */
-    public InputStream getFileFromResourceAsStream(String resourcePath) {
-        // The class loader that loaded the class
-        ClassLoader classLoader = getClass().getClassLoader();
-        InputStream inputStream = classLoader.getResourceAsStream(resourcePath);
-        // the stream holding the file content
-        if (inputStream == null) {
-            throw new IllegalArgumentException("file not found! " + resourcePath);
-        } else {
-            return inputStream;
-        }
-    }
-
-    /**
-     * The resource URL is not working in the JAR
-     * If we try to access a file that is inside a JAR,
-     * It throws NoSuchFileException (linux), InvalidPathException (Windows)
-     * Resource URL Sample: file:java-io.jar!/json/file1.json
-     *
-     * @param
-     * @return
-     * @date 2025-11-03 16:16:48
-     */
-    public File getFileFromResource(String resourcePath) throws URISyntaxException{
-        ClassLoader classLoader = getClass().getClassLoader();
-        URL resource = classLoader.getResource(resourcePath);
-        if (resource == null) {
-            throw new IllegalArgumentException("file not found! " + resourcePath);
-        } else {
-            // failed if files have whitespaces or special characters
-            //return new File(resource.getFile());
-            return new File(resource.toURI());
-        }
-    }
-
-    /**
-     * Get all paths from a folder that inside the jar file
-     * 
-     * @param
-     * @return
-     * @date 2025-11-03 16:07:52
-     */
-    public List<Path> getPathsFromResourceJar(String folder) throws URISyntaxException, IOException {
-        // get path of the current running jar
-        String jarPath = getClass().getProtectionDomain()
-                .getCodeSource()
-                .getLocation()
-                .toURI()
-                .getPath();
-        System.out.println("jar Path :" + jarPath);
-        // file walks jar
-        URI uri = URI.create("jar:file:" + jarPath);
-        List<Path> result;
-        try (FileSystem fs = FileSystems.newFileSystem(uri, Collections.emptyMap())) {
-            result = Files.walk(fs.getPath(folder))
-                    .filter(Files::isRegularFile)
-                    .collect(Collectors.toList());
-        }
-        return result;
-    }
-
-    public String getRunningJarPath() {
-        URL url = getClass().getProtectionDomain().getCodeSource().getLocation();
-        String jarFilePath = URLDecoder.decode(url.getPath(), StandardCharsets.UTF_8);
-        if (jarFilePath.endsWith(".jar")) {
-            jarFilePath = jarFilePath.substring(0, jarFilePath.lastIndexOf("/") + 1);
-        }
-
-        File file = new File(jarFilePath);
-        return file.getAbsolutePath();
-    }
-}

+ 0 - 5
web/src/main/resources/application.yml

@@ -80,11 +80,6 @@ spring:
 app:
   baseDir: /opt/data/bntdata
   devopsDir: ${app.basedir}/devops
-  luceneDir: ${app.basedir}/lucene
-  fileDir: ${app.basedir}/file
-  options:
-    site_logo: /dist/images/logo.png
-    site_favicon: /dist/images/favicon.png
 management:
   endpoints:
     web:

+ 0 - 69
web/src/test/java/DateTest.java

@@ -1,13 +1,6 @@
-import cn.reghao.bnt.web.util.JarFileResources;
 import lombok.extern.slf4j.Slf4j;
 import org.junit.jupiter.api.Test;
-import org.springframework.core.io.ClassPathResource;
 
-import java.io.*;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Path;
 import java.time.DayOfWeek;
 import java.time.Duration;
 import java.time.LocalDateTime;
@@ -48,66 +41,4 @@ public class DateTest {
         Duration duration = Duration.between(localDateTime, localDateTime1);
         System.out.println();
     }
-
-
-    // print input stream
-    private static void printInputStream(InputStream is) {
-        try (InputStreamReader streamReader = new InputStreamReader(is, StandardCharsets.UTF_8);
-             BufferedReader reader = new BufferedReader(streamReader)) {
-            String line;
-            while ((line = reader.readLine()) != null) {
-                System.out.println(line);
-            }
-        } catch (IOException e) {
-            e.printStackTrace();
-        }
-    }
-
-    @Test
-    public void getFileFromJar() throws IOException, URISyntaxException {
-        ClassLoader classLoader = this.getClass().getClassLoader();
-        ClassLoader classLoader1 = Thread.currentThread().getContextClassLoader();
-        ClassLoader classLoader2 = DateTest.class.getClassLoader();
-
-        String resourcePath = "templates/index.html";
-        URL resource = classLoader.getResource(resourcePath);
-        File file = new File(resource.toURI());
-        InputStream inputStream = classLoader.getResourceAsStream(resourcePath);
-
-        URL resource1 = classLoader1.getResource(resourcePath);
-        URL resource2 = classLoader2.getResource(resourcePath);
-
-        InputStream resourceAsStream = new ClassPathResource(resourcePath).getInputStream();
-
-        
-        /*URL resource = Thread.currentThread().getContextClassLoader().getResource(avatarResource);
-        String avatarPath = resource.getPath();
-        System.out.println(avatarPath);
-        File file = new File(avatarPath);
-        byte[] imageBytes = Files.readAllBytes(file.toPath());*/
-        
-        JarFileResources app = new JarFileResources();
-        // Sample 3 - read all files from a resources folder (jar version)
-        try {
-            // get paths from src/main/resources/json
-            List<Path> result = app.getPathsFromResourceJar("json");
-            for (Path path : result) {
-                System.out.println("Path : " + path);
-
-                String filePathInJar = path.toString();
-                // Windows will returns /json/file1.json, cut the first /
-                // the correct path should be json/file1.json
-                if (filePathInJar.startsWith("/")) {
-                    filePathInJar = filePathInJar.substring(1, filePathInJar.length());
-                }
-
-                System.out.println("filePathInJar : " + filePathInJar);
-                // read a file from resource folder
-                InputStream is = app.getFileFromResourceAsStream(filePathInJar);
-                printInputStream(is);
-            }
-        } catch (URISyntaxException | IOException e) {
-            e.printStackTrace();
-        }
-    }
 }