月球大数据地理空间分析展示平台-【后端】-月球后台服务
13693261870
2023-07-22 6aeb1c17992bbefb3a4469cf8d70d1488baf87bd
修改代理服务、zip解压
已修改5个文件
92 ■■■■■ 文件已修改
src/main/java/com/moon/server/entity/all/StaticData.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/moon/server/helper/HttpHelper.java 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/moon/server/helper/PathHelper.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/moon/server/helper/ZipHelper.java 74 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/moon/server/service/sys/ProxyService.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/moon/server/entity/all/StaticData.java
@@ -18,6 +18,8 @@
    public final static int TWO = 2;
    public final static int THREE = 3;
    public final static int FOUR = 4;
    public final static int NINE = 9;
@@ -86,6 +88,8 @@
    public final static String AK = "?ak=";
    public final static String REST_LAYER = "/rest/layer/";
    /**
     * 单引号
     */
src/main/java/com/moon/server/helper/HttpHelper.java
@@ -300,13 +300,17 @@
            url = strs[0];
            if (!StringHelper.isEmpty(strs[1])) {
                str = str.replace("?" + strs[1], "");
                str = str.replace("?" + strs[1], "").replace("&" + strs[1], "").replace("&" + strs[1], "");
            }
        }
        if (str.contains(url)) {
            String proxyUrl = res.getProxy().replace("{token}", response.getHeader("token"));
            proxyUrl = request.getRequestURL().substring(0, request.getRequestURL().indexOf(proxyUrl) + proxyUrl.length());
            str = str.replace(res.getUrl(), proxyUrl);
            str = str.replace(url, proxyUrl);
            if (str.contains(StaticData.REST_LAYER)) {
                str = str.replace(url.replace("/wmts/layer/", StaticData.REST_LAYER), proxyUrl);
            }
        }
        return str;
src/main/java/com/moon/server/helper/PathHelper.java
@@ -23,7 +23,7 @@
    private static int uploadPath = 1;
    private final static double D80 = 80;
    private final static double D90 = 90;
    private final static Log log = LogFactory.getLog(PathHelper.class);
@@ -142,7 +142,7 @@
    public void deleteOldPath(String tempPath) {
        try {
            double ran = Math.random() * 99;
            if (ran < D80) {
            if (ran < D90) {
                return;
            }
src/main/java/com/moon/server/helper/ZipHelper.java
@@ -36,31 +36,9 @@
                dir.mkdirs();
            }
            int count;
            zipFile = new ZipFile(filePath, Charset.forName("GBK"));
            Enumeration e = zipFile.entries();
            while (e.hasMoreElements()) {
                ZipEntry entry = (ZipEntry) e.nextElement();
                if (entry.isDirectory()) {
                    File f = new File(zipDir + File.separator + entry.getName());
                    if (!f.exists()) {
                        f.mkdirs();
                    }
                    continue;
                }
                BufferedInputStream is = new BufferedInputStream(zipFile.getInputStream(entry));
                FileOutputStream fos = new FileOutputStream(zipDir + File.separator + entry.getName());
                BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER_SIZE);
                while ((count = is.read(BUFFER, 0, BUFFER_SIZE)) != -1) {
                    dest.write(BUFFER, 0, count);
                }
                dest.flush();
                dest.close();
                fos.close();
                is.close();
            }
            createDirs(zipFile, zipDir);
            writeFiles(zipFile, zipDir);
            return true;
        } catch (Exception ex) {
@@ -78,6 +56,54 @@
    }
    /**
     * 创建目录
     */
    private static void createDirs(ZipFile zipFile, String zipDir) {
        Enumeration<?> e = zipFile.entries();
        while (e.hasMoreElements()) {
            ZipEntry entry = (ZipEntry) e.nextElement();
            if (entry.isDirectory()) {
                File f = new File(zipDir + File.separator + entry.getName());
                if (!f.exists()) {
                    f.mkdirs();
                }
            }
        }
    }
    /**
     * 写文件
     */
    private static void writeFiles(ZipFile zipFile, String zipDir) throws IOException {
        Enumeration<?> e = zipFile.entries();
        while (e.hasMoreElements()) {
            ZipEntry entry = (ZipEntry) e.nextElement();
            if (!entry.isDirectory()) {
                writeFile(zipFile, entry, zipDir);
            }
        }
    }
    /**
     * 写文件
     */
    private static void writeFile(ZipFile zipFile, ZipEntry entry, String zipDir) throws IOException {
        int count;
        BufferedInputStream is = new BufferedInputStream(zipFile.getInputStream(entry));
        FileOutputStream fos = new FileOutputStream(zipDir + File.separator + entry.getName());
        BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER_SIZE);
        while ((count = is.read(BUFFER, 0, BUFFER_SIZE)) != -1) {
            dest.write(BUFFER, 0, count);
        }
        dest.flush();
        dest.close();
        fos.close();
        is.close();
    }
    /**
     * Zip压缩
     *
     * @param zipFile   zip源文件
src/main/java/com/moon/server/service/sys/ProxyService.java
@@ -56,7 +56,7 @@
        // 9.获取资源实体
        ResEntity entity = getResEntity(ue, resId);
        if (null == entity || entity.getType() != 3|| StringHelper.isNull(entity.getProxy())||StringHelper.isNull(entity.getUrl())) {
        if (null == entity || entity.getType() != StaticData.THREE || StringHelper.isNull(entity.getProxy()) || StringHelper.isNull(entity.getUrl())) {
            WebHelper.writeStr2Page(res, ILLEGAL_RESOURCE);
            return;
        }