|
|
@@ -1,24 +1,15 @@
|
|
|
-import cn.reghao.jutil.jdk.converter.ByteConverter;
|
|
|
-import cn.reghao.jutil.jdk.converter.ByteType;
|
|
|
-import cn.reghao.oss.api.dto.ServerInfo;
|
|
|
-import cn.reghao.oss.sdk.OssClient;
|
|
|
-import cn.reghao.tnb.file.app.zdisk.model.vo.FileTree;
|
|
|
-import cn.reghao.oss.api.constant.ObjectType;
|
|
|
+import cn.reghao.jutil.jdk.serializer.JsonConverter;
|
|
|
+import com.google.gson.JsonArray;
|
|
|
+import com.google.gson.JsonElement;
|
|
|
+import com.google.gson.JsonObject;
|
|
|
+import com.google.gson.JsonPrimitive;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import net.sourceforge.tess4j.Tesseract;
|
|
|
-import org.apache.tika.Tika;
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
-import org.mockito.junit.MockitoJUnitRunner;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.nio.file.*;
|
|
|
import java.nio.file.attribute.BasicFileAttributes;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.TreeMap;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
@Slf4j
|
|
|
public class DiskUnitTest {
|
|
|
@@ -34,102 +25,93 @@ public class DiskUnitTest {
|
|
|
}
|
|
|
|
|
|
private void process(File file) {
|
|
|
- String contentType = getContentType(file);
|
|
|
- log.info("{} -> {}", contentType, file.getName());
|
|
|
- }
|
|
|
-
|
|
|
- Tika tika = new Tika();
|
|
|
- private String getContentType(File file) {
|
|
|
- try {
|
|
|
- // Tika 会根据文件头字节进行深度探测
|
|
|
- return tika.detect(file);
|
|
|
- } catch (IOException e) {
|
|
|
- log.error("Tika 探测文件类型失败: {}", file.getAbsolutePath(), e);
|
|
|
- return "application/octet-stream";
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void fileWalk() throws IOException {
|
|
|
- String baseDir = "/disk/2/porn/bt";
|
|
|
- Path path = Paths.get(baseDir);
|
|
|
- walkDir(path);
|
|
|
- System.out.println();
|
|
|
+ String baseDir = "/disk/1";
|
|
|
+ //Path path = Paths.get(baseDir);
|
|
|
+ //walkDir(path);
|
|
|
+ parseTelegram();
|
|
|
}
|
|
|
|
|
|
- List<FileTree> fileTreeList = new ArrayList<>();
|
|
|
- String baseDir = "/home/reghao/Downloads/";
|
|
|
- File dir = new File(baseDir);
|
|
|
-
|
|
|
- Map<String, List<FileTree>> getTreeMap() throws IOException {
|
|
|
- Path path = Paths.get(dir.getAbsolutePath());
|
|
|
- walkDir(path);
|
|
|
-
|
|
|
- Map<String, List<FileTree>> pidGroup = fileTreeList.stream()
|
|
|
- .collect(Collectors.groupingBy(FileTree::getPid));
|
|
|
- return new TreeMap<>(pidGroup);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- public void treeTest() throws Exception {
|
|
|
- /*Map<String, List<FileTree>> pidTreeMap = getTreeMap();
|
|
|
- pidTreeMap.forEach((key, list) -> {
|
|
|
- String pid = key;
|
|
|
- for (FileTree fileTree : list) {
|
|
|
- String fileId = fileTree.getFileId();
|
|
|
+ String baseDir = "/home/reghao/Downloads/0/tg/tg_json";
|
|
|
+ private void parseTelegram() {
|
|
|
+ String path = baseDir + "/result.json";
|
|
|
+ File jsonFile = new File(path);
|
|
|
+ JsonObject jsonObject = JsonConverter.jsonFileToObject(jsonFile, JsonObject.class);
|
|
|
+
|
|
|
+ JsonArray jsonArray = jsonObject.get("chats").getAsJsonObject().get("list").getAsJsonArray();
|
|
|
+ JsonObject chat = jsonArray.get(0).getAsJsonObject();
|
|
|
+ JsonArray messages = chat.get("messages").getAsJsonArray();
|
|
|
+ for (JsonElement jsonElement : messages) {
|
|
|
+ JsonObject jsonObject1 = jsonElement.getAsJsonObject();
|
|
|
+ try {
|
|
|
+ long id = jsonObject1.get("id").getAsLong();
|
|
|
+ String date = jsonObject1.get("date").getAsString();
|
|
|
+ String type = jsonObject1.get("type").getAsString();
|
|
|
+ if ("service".equals(type)) {
|
|
|
+ System.out.printf("%s service msg type\n", date);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ String from = jsonObject1.get("from").getAsString();
|
|
|
+ String fromId = jsonObject1.get("from_id").getAsString();
|
|
|
+
|
|
|
+ String text = "";
|
|
|
+ JsonElement jsonElement1 = jsonObject1.get("text");
|
|
|
+ if (jsonElement1 == null) {
|
|
|
+ System.out.println("text is null");
|
|
|
+ } else if (jsonElement1 instanceof JsonPrimitive) {
|
|
|
+ text = jsonObject1.get("text").getAsString();
|
|
|
+ } else if (jsonElement1 instanceof JsonArray) {
|
|
|
+ text = "text JsonArray";
|
|
|
+ for (JsonElement jsonElement2 : jsonElement1.getAsJsonArray()) {
|
|
|
+ if (jsonElement2 instanceof JsonPrimitive) {
|
|
|
+ String text1 = jsonElement2.getAsString();
|
|
|
+ //System.out.printf("text is JsonPrimitive: %s\n", text1);
|
|
|
+ } else if (jsonElement2 instanceof JsonObject) {
|
|
|
+ try {
|
|
|
+ JsonObject jsonObject2 = jsonElement2.getAsJsonObject();
|
|
|
+ String type1 = jsonObject2.get("type").getAsString();
|
|
|
+ String link1 = jsonObject2.get("text").getAsString();
|
|
|
+ //System.out.printf("text is JsonArray: %s %s\n", type1, link1);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ System.out.println("text is unknown type");
|
|
|
+ }
|
|
|
+
|
|
|
+ String photoPath = "";
|
|
|
+ if (jsonObject1.get("photo") != null) {
|
|
|
+ photoPath = jsonObject1.get("photo").getAsString();
|
|
|
+ File photoFile = new File(baseDir + "/" + photoPath);
|
|
|
+ if (!photoFile.exists()) {
|
|
|
+ System.out.printf("photo message %s not exist\n", photoPath);
|
|
|
+ }
|
|
|
+ //System.out.printf("photo message: %s\n", photoPath);
|
|
|
+ } else if(jsonObject1.get("file") != null) {
|
|
|
+ try {
|
|
|
+ String filePath = jsonObject1.get("file").getAsString();
|
|
|
+ File file = new File(baseDir + "/" + filePath);
|
|
|
+ if (!file.exists()) {
|
|
|
+ System.out.printf("file message %s not exist\n", filePath);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (text.isBlank()) {
|
|
|
+ //System.out.println();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ System.out.printf("%s - %s[%s]: %s\n", date, fromId, from, text);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
- });
|
|
|
- System.out.println("main-thread goto sleep...");*/
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- public void ocrTest() throws Exception {
|
|
|
-// Tesseract tess = new Tesseract();
|
|
|
-// // 字库位置
|
|
|
-// tess.setDatapath("/home/reghao/Downloads/tess");
|
|
|
-// // 中英文混合
|
|
|
-// tess.setLanguage("eng+chi_sim");
|
|
|
- //tess.setLanguage("chi_sim");
|
|
|
-// tess.setLanguage("eng");
|
|
|
-
|
|
|
-// String imagePath = "/home/reghao/Downloads/1620438.png";
|
|
|
-// String result = tess.doOCR(new File(imagePath));
|
|
|
-// System.out.println(result);
|
|
|
-
|
|
|
- ByteConverter byteConverter = new ByteConverter();
|
|
|
- long value = 1623581261432L;
|
|
|
- value = 945039537733L;
|
|
|
-
|
|
|
- String str = byteConverter.convert(ByteType.Bytes, value);
|
|
|
- System.out.println(str);
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- public void ossTest() throws Exception {
|
|
|
- String endpoint = "http://localhost:8010";
|
|
|
- String ak = "PmvonhHI";
|
|
|
- String sk = "28aQEK7wJ6U5m7E1u7";
|
|
|
- OssClient ossClient = new OssClient(endpoint, ak, sk);
|
|
|
-
|
|
|
- int channelCode = 101;
|
|
|
- ServerInfo serverInfo = ossClient.getServerInfo(channelCode);
|
|
|
- String uploadUrl = serverInfo.getOssUrl();
|
|
|
- String uploadToken = serverInfo.getToken();
|
|
|
-
|
|
|
- String baseDir = "/home/reghao/Downloads/1";
|
|
|
- //client.startWalk(baseDir);
|
|
|
-
|
|
|
- /*uploadUrl = "http://localhost:8020";
|
|
|
- String filePath = "/home/reghao/Downloads/abc.mp4";
|
|
|
- File file = new File(filePath);
|
|
|
- if (!file.exists()) {
|
|
|
- System.out.printf("%s not exist\n", filePath);
|
|
|
- return;
|
|
|
}
|
|
|
- client.upload(uploadUrl, uploadToken, Path.of(filePath));*/
|
|
|
-
|
|
|
- /*String objectId1 = "3c0403add7ec4127bf66cfdbb4a8ddf1";
|
|
|
- String signedUrl = uploader.getSignedUrl(objectId1);
|
|
|
- System.out.printf("signed url -> %s\n", signedUrl);*/
|
|
|
}
|
|
|
}
|