✨Feat: 获取文件内容
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user