diff --git a/src/main/kotlin/fr/jais/scraper/utils/API.kt b/src/main/kotlin/fr/jais/scraper/utils/API.kt index bcb2ed8..211cdd9 100644 --- a/src/main/kotlin/fr/jais/scraper/utils/API.kt +++ b/src/main/kotlin/fr/jais/scraper/utils/API.kt @@ -20,10 +20,15 @@ object API { } private fun post(url: String, json: String): HttpResponse { - val request = HttpRequest.newBuilder() + val requestBuilder = HttpRequest.newBuilder() .uri(URI.create(url)) .header("Content-Type", "application/json") - .POST(HttpRequest.BodyPublishers.ofString(json)) + + if (!Const.secureKey.isNullOrBlank()) { + requestBuilder.header("Authorization", Const.secureKey) + } + + val request = requestBuilder.POST(HttpRequest.BodyPublishers.ofString(json)) .build() return Const.httpClient.send(request, HttpResponse.BodyHandlers.ofString()) } diff --git a/src/main/kotlin/fr/jais/scraper/utils/Const.kt b/src/main/kotlin/fr/jais/scraper/utils/Const.kt index 3f62e62..5ffd206 100644 --- a/src/main/kotlin/fr/jais/scraper/utils/Const.kt +++ b/src/main/kotlin/fr/jais/scraper/utils/Const.kt @@ -18,4 +18,5 @@ object Const { val multipleSpaceRegex = "\\s+".toRegex() const val calendarBaseUrl = "https://anime.icotaku.com" val apiUrl = System.getenv("API_URL") ?: "http://localhost:8080/" + val secureKey: String? = System.getenv("SECURE_KEY") }