Skip to content

Commit 9d87ef7

Browse files
committed
add geyser docs download
1 parent fbf9d73 commit 9d87ef7

File tree

14 files changed

+148
-47
lines changed

14 files changed

+148
-47
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ ext {
2323
}
2424

2525
dependencies {
26-
implementation 'org.springframework.cloud:spring-cloud-starter-openfeign'
26+
implementation 'org.springframework.boot:spring-boot-starter-json:2.5.4'
2727
implementation 'com.dropbox.core:dropbox-core-sdk:4.0.0'
2828
compileOnly 'org.projectlombok:lombok'
2929
annotationProcessor 'org.projectlombok:lombok'

src/main/java/pl/nullpointersoftware/mudlet/mudletdocs/PagesUrls.java renamed to src/main/java/pl/nullpointersoftware/mudlet/mudletdocs/AppConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
import java.util.List;
88

99
@Component
10-
@ConfigurationProperties(prefix = "")
10+
@ConfigurationProperties(prefix = "mudlet-docs")
1111
@Data
12-
public class PagesUrls {
12+
public class AppConfig {
1313

1414
private List<String> pages;
1515

src/main/java/pl/nullpointersoftware/mudlet/mudletdocs/MudletDocsApplication.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22

33
import org.springframework.boot.SpringApplication;
44
import org.springframework.boot.autoconfigure.SpringBootApplication;
5-
import org.springframework.cloud.openfeign.EnableFeignClients;
65
import org.springframework.context.annotation.Bean;
76
import org.springframework.web.client.RestTemplate;
87

9-
@EnableFeignClients(basePackages = "pl.nullpointersoftware")
108
@SpringBootApplication
119
public class MudletDocsApplication {
1210

src/main/java/pl/nullpointersoftware/mudlet/mudletdocs/PagesRunner.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,38 +8,38 @@
88
import pl.nullpointersoftware.mudlet.mudletdocs.model.LuaDescriptor;
99
import pl.nullpointersoftware.mudlet.mudletdocs.service.LuaWriter;
1010
import pl.nullpointersoftware.mudlet.mudletdocs.service.PageAnalyzer;
11+
import pl.nullpointersoftware.mudlet.mudletdocs.service.api.GithubRestClient;
1112
import pl.nullpointersoftware.mudlet.mudletdocs.service.api.WikiRestClient;
1213
import pl.nullpointersoftware.mudlet.mudletdocs.service.dropbox.DropBoxUploader;
1314
import pl.nullpointersoftware.mudlet.mudletdocs.service.dropbox.DropBoxUploaderFactory;
15+
import pl.nullpointersoftware.mudlet.mudletdocs.service.github.GithubDownloader;
1416

1517
import java.io.IOException;
1618
import java.net.URISyntaxException;
1719
import java.nio.file.Files;
1820
import java.nio.file.Path;
19-
import java.util.List;
2021
import java.util.Set;
21-
import java.util.concurrent.Callable;
2222
import java.util.concurrent.ExecutorService;
2323
import java.util.concurrent.Executors;
2424
import java.util.concurrent.TimeUnit;
25-
import java.util.stream.Collectors;
2625

2726
@Component
2827
@Data
2928
@Slf4j
3029
public class PagesRunner implements ApplicationRunner {
3130

32-
private final PagesUrls pagesUrls;
31+
private final AppConfig appConfig;
3332
private final PageAnalyzer pageAnalyzer;
3433
private final LuaWriter luaWriter;
3534
private final WikiRestClient wikiRestClient;
35+
private final GithubDownloader githubDownloader;
3636
private final DropBoxUploaderFactory dropBoxUploaderFactory;
3737

3838
@Override
3939
public void run(ApplicationArguments args) throws InterruptedException, URISyntaxException, IOException {
4040
DropBoxUploader dropBoxUploader = dropBoxUploaderFactory.getClient();
41-
ExecutorService executor = Executors.newFixedThreadPool(pagesUrls.getPages().size());
42-
pagesUrls.getPages().forEach( pageName -> {
41+
ExecutorService executor = Executors.newFixedThreadPool(appConfig.getPages().size());
42+
appConfig.getPages().forEach(pageName -> {
4343
executor.submit(() -> {
4444
log.info("Processing {}", pageName);
4545
Set<LuaDescriptor> descriptors = pageAnalyzer.analyze(wikiRestClient.getPage(pageName).getParse().getWikitext());
@@ -50,6 +50,8 @@ public void run(ApplicationArguments args) throws InterruptedException, URISynta
5050
executor.shutdown();
5151
executor.awaitTermination(1, TimeUnit.MINUTES);
5252

53+
githubDownloader.downloadAll(dropBoxUploader);
54+
5355
dropBoxUploader.addFile(luaWriter.generateFile("lfs.lua", LfsDoc.DESCRIPTORS));
5456
dropBoxUploader.addFile(luaWriter.generateFile("rex.lua", RexDoc.DESCRIPTORS));
5557

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package pl.nullpointersoftware.mudlet.mudletdocs.model;
2+
3+
import lombok.Data;
4+
5+
@Data
6+
public class GithubBlobResponse {
7+
8+
private String content;
9+
10+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package pl.nullpointersoftware.mudlet.mudletdocs.model;
2+
3+
import lombok.Data;
4+
5+
import java.util.List;
6+
7+
@Data
8+
public class GithubTreeResponse {
9+
10+
private String sha;
11+
private String url;
12+
private List<TreeItem> tree;
13+
14+
@Data
15+
public static class TreeItem {
16+
private String path;
17+
private String url;
18+
private String sha;
19+
}
20+
21+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package pl.nullpointersoftware.mudlet.mudletdocs.service.api;
2+
3+
import lombok.RequiredArgsConstructor;
4+
import org.springframework.http.HttpEntity;
5+
import org.springframework.http.HttpMethod;
6+
import org.springframework.stereotype.Component;
7+
import org.springframework.util.LinkedMultiValueMap;
8+
import org.springframework.util.MultiValueMap;
9+
import org.springframework.web.client.RestTemplate;
10+
import pl.nullpointersoftware.mudlet.mudletdocs.model.GithubBlobResponse;
11+
import pl.nullpointersoftware.mudlet.mudletdocs.model.GithubTreeResponse;
12+
13+
@Component
14+
@RequiredArgsConstructor
15+
public class GithubRestClient {
16+
17+
public static final String TREE_URL = "https://api.github.com/repos/Mudlet/Mudlet/git/trees/development?recursive=1";
18+
public static final String BLOB_URL = "https://api.github.com/repos/Mudlet/Mudlet/git/blobs/";
19+
private final RestTemplate restTemplate;
20+
21+
public GithubTreeResponse getTree() {
22+
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
23+
headers.add("User-Agent", "Dargoth parser");
24+
25+
HttpEntity<String> entity = new HttpEntity<>("body", headers);
26+
27+
return restTemplate.exchange(TREE_URL, HttpMethod.GET, entity, GithubTreeResponse.class).getBody();
28+
}
29+
30+
public GithubBlobResponse getBlob(String sha) {
31+
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
32+
headers.add("User-Agent", "Dargoth parser");
33+
34+
HttpEntity<String> entity = new HttpEntity<>("body", headers);
35+
36+
return restTemplate.exchange(BLOB_URL + sha, HttpMethod.GET, entity, GithubBlobResponse.class).getBody();
37+
}
38+
39+
40+
41+
}

src/main/java/pl/nullpointersoftware/mudlet/mudletdocs/service/api/WikiApiClient.java

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/main/java/pl/nullpointersoftware/mudlet/mudletdocs/service/api/WikiRestClient.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,6 @@ public WikiResponse getPage(String page) {
2525
return restTemplate.exchange(String.format(URL, page), HttpMethod.GET, entity, WikiResponse.class).getBody();
2626
}
2727

28+
29+
2830
}

src/main/java/pl/nullpointersoftware/mudlet/mudletdocs/service/dropbox/DropBoxUploader.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
import java.nio.file.Path;
66

77
public interface DropBoxUploader {
8-
void addFile(Path path);
8+
default void addFile(Path path) {
9+
addFile(path, "");
10+
}
11+
void addFile(Path path, String dir);
912

1013
@SneakyThrows
1114
void finish();

0 commit comments

Comments
 (0)