✨Feat: 获取文件内容

This commit is contained in:
2025-10-13 15:36:03 +08:00
parent 7866db7cbb
commit ff2494dcf2
2 changed files with 40 additions and 0 deletions
@@ -0,0 +1,33 @@
package cn.hezhaohui.webhook.service;
import cn.hutool.http.HttpUtil;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class FileService {
// repo: http://47.121.181.112:3000/wonder/lark-webhook-sender
// prefix: /raw/branch/main/
// raw: gitea-webhook/src/main/java/cn/hezhaohui/webhook/controller/HookController.java
// parse: http://47.121.181.112:3000/wonder/lark-webhook-sender/raw/branch/main/gitea-webhook/src/main/java/cn/hezhaohui/webhook/controller/HookController.java
public String getRawUrl(String repo, String raw) {
return repo +"/raw/branch/main/" +raw;
}
public String getRawContents(String repo, String raw) {
String url = getRawUrl(repo, raw);
String fileName = raw.substring(raw.lastIndexOf("/")+1);
String fileContent = HttpUtil.get(url);
return "[FileName]" + fileName + "\n" + "[FileContent]" + fileContent + "\n";
}
public String getAllFiles(String repo, List<String> files) {
StringBuilder sb = new StringBuilder();
for (String file : files) {
sb.append(getRawContents(repo, file));
}
return sb.toString();
}
}