Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions zipencrypt_fdddf/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.DS_Store
.idea
target/
52 changes: 52 additions & 0 deletions zipencrypt_fdddf/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# zip包加密依赖库
文件zip包加密依赖库

## 逻辑详情

### compressFiles

压缩文件
入参:
* 密码
* 压缩包名称
* 待压缩文件列表,可包含路径,支持http/https URL
* 是否分割压缩

出参:
* FileUploadResponse 同文件上传响应,但多2个参数filePaths和results,表示分割的多个文件路径列表和URL


### asyncCompressFiles

异步压缩文件

入参:
* 密码
* 压缩包名称
* 待压缩文件列表,可包含路径,支持http/https URL
* 是否分割压缩
* 压缩完成回调, 参数为FileUploadResponse

出参:
* Boolean 无实际意义

## 使用步骤说明

1. 应用引用依赖库
2. 配置应用配置参数

全局配置:
* 应用地址,https://
* 默认加密密码
* 加密方式, 默认AES 0:ZipStandard,1:AES
* 压缩级别,默认压缩级别为5, 1-9, 0 为不压缩
* 分割大小,分割大小, 默认为10M
* 压缩方式,默认为DEFLATE, 0:DEFLATE,1:STORE

3. 逻辑调用示例截图
![](Snipaste_2024-09-06_23-45-15.jpg)

## 应用演示链接

[使用了本依赖库的制品应用链接]
https://dev-testdiff-qa.app.codewave.163.com/dashboard/ziptest
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mvn install:install-file -Dfile="nasl-metadata-maven-plugin-1.3.0.jar" -DpomFile="pom.xml"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mvn install:install-file -Dfile="nasl-metadata-maven-plugin-1.3.0.jar" -DpomFile="pom.xml"
Binary file not shown.
74 changes: 74 additions & 0 deletions zipencrypt_fdddf/jar/nasl-metadata-maven-plugin-1.3.0/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.netease.lowcode</groupId>
<artifactId>nasl-metadata-maven-plugin</artifactId>
<version>1.3.0</version>
<packaging>maven-plugin</packaging>

<name>Nasl Metadata Maven Plugin</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>2.0.10</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-manager</artifactId>
<version>2.8.4</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>3.0.8</version>
</dependency>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-common-artifact-filters</artifactId>
<version>3.0.1</version>
</dependency>

<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-aether-provider</artifactId>
<version>3.3.9</version>
</dependency>

<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-api</artifactId>
<version>1.1.0</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.2</version>
<configuration>
<goalPrefix>nasl-metadata-maven-plugin</goalPrefix>
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
</configuration>
</plugin>
</plugins>
</build>
</project>
84 changes: 84 additions & 0 deletions zipencrypt_fdddf/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.9.RELEASE</version><!--与当前制品应用默认版本统一-->
<relativePath/> <!-- lookup parent from repository -->
</parent>

<groupId>fdddf</groupId>
<artifactId>zipencrypt</artifactId>
<version>1.1.1</version>
<name>ZipEncrypt</name>
<description>支持将文件压缩为zip,并可设置压缩包密码,没有设置的时候自动设置</description>

<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<nasl.ide.version>3.3</nasl.ide.version>
</properties>
<dependencies>
<!--本案例是本地系统引入nasl-metadata-collector-0.8.0.jar的方式。
若把nasl-metadata-collector-0.8.0.jar安装到自己的maven仓库,
注意修改artifactId和groupId的情况下,不要使用<scope>system</scope>,会在发布时造成依赖中断。
不修改artifactId和groupId的情况下,nasl-metadata-maven-plugin会做特殊处理-->
<dependency>
<artifactId>nasl-metadata-collector</artifactId>
<groupId>com.netease.lowcode</groupId>
<version>0.8.0</version>
<optional>true</optional>
<scope>system</scope>
<systemPath>${project.basedir}/jar/nasl-metadata-collector-0.8.0.jar</systemPath>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>provided</scope>
<version>1.7.30</version>
</dependency>
<dependency>
<groupId>net.lingala.zip4j</groupId>
<artifactId>zip4j</artifactId>
<version>2.11.5</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.netease.lowcode</groupId>
<artifactId>nasl-metadata-maven-plugin</artifactId>
<version>1.3.0</version>
<configuration>
<jarWithDependencies>false</jarWithDependencies>
</configuration>
<executions>
<execution>
<goals>
<goal>archive</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.fdddf.zipencrypt;

import com.netease.lowcode.core.annotation.NaslStructure;

import java.util.ArrayList;
import java.util.List;

@NaslStructure
public class FileUploadResponse {
public Integer code;

public Boolean success;

public String msg;

public String result;

public String filePath;

/**
* 分割文件时,路径列表
*/
public List<String> filePaths = new ArrayList<>();

/**
* 分割文件时,文件URL列表
*/
public List<String> results = new ArrayList<>();

@Override
public String toString() {
return "FileUploadResponse{" +
"code=" + code +
", success=" + success +
", msg='" + msg + '\'' +
", result='" + result + '\'' +
", filePath='" + filePath + '\'' +
'}';
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.fdddf.zipencrypt;

import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;

public class FileUploader {

public static FileUploadResponse doUpload(String url, String filePath) throws IOException {
// 创建URL对象
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();

// 设置请求方法为POST
con.setRequestMethod("POST");

// 设置允许输出
con.setDoOutput(true);

// 设置请求头
String boundary = "------" + System.currentTimeMillis();
String contentType = "multipart/form-data; boundary=" + boundary;
con.setRequestProperty("Content-Type", contentType);
con.setRequestProperty("Charset", "UTF-8");

// 写入请求体
DataOutputStream wr = new DataOutputStream(con.getOutputStream());

// encode the filename to utf8
String filename = new File(filePath).getName();
String header = "Content-Disposition: form-data; name=\"file\"; filename=\"" + filename + "\"\r\n"
+ "Content-Type: application/octet-stream\r\n\r\n";
wr.writeBytes("--" + boundary + "\r\n");
wr.write(header.getBytes(StandardCharsets.UTF_8));

// 读取文件并写入请求体
FileInputStream fileInputStream = new FileInputStream(filePath);
byte[] buffer = new byte[4096];
int bytesRead = -1;
while ((bytesRead = fileInputStream.read(buffer)) != -1) {
wr.write(buffer, 0, bytesRead);
}
fileInputStream.close();

// 结束部分
wr.writeBytes("\r\n--" + boundary + "--\r\n");
wr.flush();
wr.close();

// 获取响应
int responseCode = con.getResponseCode();
System.out.println("Response Code : " + responseCode);

// 读取响应并解析为JSON
BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuilder response = new StringBuilder();

while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();

// 解析JSON响应
ObjectMapper objectMapper = new ObjectMapper();
// 假设服务器返回的是一个简单的JSON对象
FileUploadResponse resp = objectMapper.readValue(response.toString(), FileUploadResponse.class);

System.out.println("Response: " + resp.filePath);

return resp;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.fdddf.zipencrypt;

/**
* 依赖库自动扫描类
* @author system
*/
public class LibraryAutoScan {
}
Loading