• R/O
  • SSH
  • HTTPS

catalpa: Commit


Commit MetaInfo

Revisão126 (tree)
Hora2022-10-29 15:54:59
Autorhirukawa_ryo

Mensagem de Log

0.9.1
FirebaseConfig, FirebaseUploader 外部ファイル config.json を指定できるようにしました。

Mudança Sumário

Diff

--- catalpa/trunk/src/main/java/net/osdn/catalpa/upload/firebase/FirebaseConfig.java (revision 125)
+++ catalpa/trunk/src/main/java/net/osdn/catalpa/upload/firebase/FirebaseConfig.java (revision 126)
@@ -14,6 +14,7 @@
1414
1515 private String siteId;
1616 private Path serviceAccountKeyFilePath;
17+ private Path firebaseConfigFilePath;
1718
1819 public FirebaseConfig() {
1920 }
@@ -26,6 +27,10 @@
2627 return this.serviceAccountKeyFilePath;
2728 }
2829
30+ public Path getFirebaseConfigFilePath() {
31+ return this.firebaseConfigFilePath;
32+ }
33+
2934 private void initialize() {
3035 String s;
3136
@@ -37,17 +42,31 @@
3742
3843 s = getValueAsString("serviceAccountKey");
3944 if(s != null) {
40- String secretKey = s.replace('/', '\\');
41- if(secretKey.length() >= 3 && secretKey.substring(1, 3).equals(":\\")) {
42- this.serviceAccountKeyFilePath = Paths.get(secretKey).toAbsolutePath();
45+ String serviceAccountKey = s.replace('/', '\\');
46+ if(serviceAccountKey.length() >= 3 && serviceAccountKey.substring(1, 3).equals(":\\")) {
47+ this.serviceAccountKeyFilePath = Paths.get(serviceAccountKey).toAbsolutePath();
4348 } else {
4449 Path p = getFolderPath("serviceAccountKey");
45- this.serviceAccountKeyFilePath = p.resolve(secretKey).toAbsolutePath();
50+ this.serviceAccountKeyFilePath = p.resolve(serviceAccountKey).toAbsolutePath();
4651 }
4752 if(!Files.exists(this.serviceAccountKeyFilePath)) {
4853 throw new UncheckedIOException(new FileNotFoundException(this.serviceAccountKeyFilePath.toString()));
4954 }
5055 }
56+
57+ s = getValueAsString("config");
58+ if(s != null) {
59+ String path = s.replace('/', '\\');
60+ if(path.length() >= 3 && path.substring(1, 3).equals(":\\")) {
61+ this.firebaseConfigFilePath = Paths.get(path).toAbsolutePath();
62+ } else {
63+ Path folder = getFolderPath("config");
64+ this.firebaseConfigFilePath = folder.resolve(path).toAbsolutePath();
65+ }
66+ if(!Files.exists(this.firebaseConfigFilePath)) {
67+ throw new UncheckedIOException((new FileNotFoundException(this.firebaseConfigFilePath.toString())));
68+ }
69+ }
5170 }
5271
5372 public int upload(File dir, ProgressObserver observer) throws Exception {
--- catalpa/trunk/src/main/java/net/osdn/catalpa/upload/firebase/FirebaseUploader.java (revision 125)
+++ catalpa/trunk/src/main/java/net/osdn/catalpa/upload/firebase/FirebaseUploader.java (revision 126)
@@ -65,6 +65,23 @@
6565 throw new ToastMessage("Firebase Hosting", "serviceAccountKey が指定されていません");
6666 }
6767
68+ String firebaseConfig;
69+ Path firebaseConfigFilePath = config.getFirebaseConfigFilePath();
70+ if(firebaseConfigFilePath != null && Files.exists(firebaseConfigFilePath)) {
71+ firebaseConfig = Files.readString(firebaseConfigFilePath);
72+ } else {
73+ firebaseConfig = """
74+ {
75+ "headers": [{
76+ "glob": "**",
77+ "headers": {
78+ "Cache-Control": "max-age=1800"
79+ }
80+ }]
81+ }
82+ """;
83+ }
84+
6885 Path input = localDirectory.toPath();
6986 Path output = MainApp.createTemporaryDirectory("upload-htdocs-gzipped", true);
7087
@@ -76,7 +93,7 @@
7693 .executor(executor)
7794 .build();
7895
79- String versionId = createVersionId(client, token, siteId);
96+ String versionId = createVersionId(client, token, siteId, firebaseConfig);
8097
8198 Map<Path, String> files = new LinkedHashMap<>();
8299 int len;
@@ -157,7 +174,7 @@
157174 }
158175
159176
160- private static String createVersionId(HttpClient client, String token, String siteId) throws IOException, InterruptedException {
177+ private static String createVersionId(HttpClient client, String token, String siteId, String firebaseConfig) throws IOException, InterruptedException {
161178 String versionId = null;
162179
163180 String url = "https://firebasehosting.googleapis.com" + "/v1beta1/sites/" + siteId + "/versions";
@@ -164,18 +181,7 @@
164181 HttpRequest request = HttpRequest.newBuilder(URI.create(url))
165182 .setHeader("Authorization", "Bearer " + token)
166183 .setHeader("Content-Type", "application/json")
167- .POST(HttpRequest.BodyPublishers.ofString("""
168- {
169- "config": {
170- "headers": [{
171- "glob": "**",
172- "headers": {
173- "Cache-Control": "max-age=1800"
174- }
175- }]
176- }
177- }
178- """, StandardCharsets.UTF_8))
184+ .POST(HttpRequest.BodyPublishers.ofString("{ \"config\": " + firebaseConfig + " }", StandardCharsets.UTF_8))
179185 .build();
180186
181187 HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
Show on old repository browser