goldenChat base source add

This commit is contained in:
aidev
2026-05-23 15:11:48 +09:00
commit a4ea7762b5
2081 changed files with 1155760 additions and 0 deletions
@@ -0,0 +1,58 @@
package com.goldenchart.config;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;
import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import java.io.FileInputStream;
import java.io.InputStream;
@Configuration
@Slf4j
public class FirebaseConfig {
@Value("${firebase.service-account-file:firebase-service-account.json}")
private String serviceAccountFile;
@Value("${firebase.enabled:false}")
private boolean firebaseEnabled;
@PostConstruct
public void initialize() {
if (!firebaseEnabled) {
log.info("[Firebase] disabled (firebase.enabled=false)");
return;
}
if (!FirebaseApp.getApps().isEmpty()) return;
try (InputStream in = openServiceAccount()) {
if (in == null) {
log.warn("[Firebase] service account not found — FCM disabled");
return;
}
FirebaseOptions options = FirebaseOptions.builder()
.setCredentials(GoogleCredentials.fromStream(in))
.build();
FirebaseApp.initializeApp(options);
log.info("[Firebase] Admin SDK initialized — FCM enabled");
} catch (Exception e) {
log.warn("[Firebase] init failed: {}", e.getMessage());
}
}
private InputStream openServiceAccount() {
try {
var res = new ClassPathResource(serviceAccountFile);
if (res.exists()) return res.getInputStream();
} catch (Exception ignored) { }
try {
return new FileInputStream(serviceAccountFile);
} catch (Exception ignored) { }
return null;
}
}