-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
224 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 39 additions & 29 deletions
68
dms-infrastructure/src/main/kotlin/team/aliens/dms/thirdparty/notification/FCMConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,41 @@ | ||
package team.aliens.dms.thirdparty.notification | ||
|
||
// @Configuration | ||
// class FCMConfig( | ||
// @Value("\${fcm.file-url}") | ||
// private val url: String | ||
// ) { | ||
// | ||
// @PostConstruct | ||
// fun initialize() { | ||
// try { | ||
// URL(url).openStream().use { inputStream -> | ||
// Files.copy(inputStream, Paths.get(PATH)) | ||
// val file = File(PATH) | ||
// if (FirebaseApp.getApps().isEmpty()) { | ||
// val options = FirebaseOptions.builder() | ||
// .setCredentials(GoogleCredentials.fromStream(file.inputStream())) | ||
// .build() | ||
// FirebaseApp.initializeApp(options) | ||
// } | ||
// file.delete() | ||
// } | ||
// } catch (e: IOException) { | ||
// e.printStackTrace() | ||
// } | ||
// } | ||
// | ||
// companion object { | ||
// private const val PATH = "./credentials.json" | ||
// } | ||
// } | ||
import com.google.auth.oauth2.GoogleCredentials | ||
import com.google.firebase.FirebaseApp | ||
import com.google.firebase.FirebaseOptions | ||
import jakarta.annotation.PostConstruct | ||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.context.annotation.Configuration | ||
import java.io.File | ||
import java.io.IOException | ||
import java.net.URL | ||
import java.nio.file.Files | ||
import java.nio.file.Paths | ||
|
||
@Configuration | ||
class FCMConfig( | ||
@Value("\${fcm.file-url}") | ||
private val url: String | ||
) { | ||
@PostConstruct | ||
fun initialize() { | ||
try { | ||
URL(url).openStream().use { inputStream -> | ||
Files.copy(inputStream, Paths.get(PATH)) | ||
val file = File(PATH) | ||
if (FirebaseApp.getApps().isEmpty()) { | ||
val options = FirebaseOptions.builder() | ||
.setCredentials(GoogleCredentials.fromStream(file.inputStream())) | ||
.build() | ||
FirebaseApp.initializeApp(options) | ||
} | ||
file.delete() | ||
} | ||
} catch (e: IOException) { | ||
e.printStackTrace() | ||
} | ||
} | ||
companion object { | ||
private const val PATH = "./credentials.json" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.