-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
27 changed files
with
1,421 additions
and
1,141 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
10 changes: 10 additions & 0 deletions
10
api/src/main/kotlin/nebulosa/api/system/GitHubLatestRelease.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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package nebulosa.api.system | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty | ||
|
||
data class GitHubLatestRelease( | ||
@JvmField @field:JsonProperty("tag_name") val version: String = "", | ||
@JvmField @field:JsonProperty("name") val name: String = "", | ||
@JvmField @field:JsonProperty("draft") val draft: Boolean = false, | ||
@JvmField @field:JsonProperty("prerelease") val preRelease: Boolean = false, | ||
) |
13 changes: 13 additions & 0 deletions
13
api/src/main/kotlin/nebulosa/api/system/SystemController.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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package nebulosa.api.system | ||
|
||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
|
||
@RestController | ||
@RequestMapping("system") | ||
class SystemController(private val systemService: SystemService) { | ||
|
||
@GetMapping("latest-release") | ||
fun latestRelease() = systemService.latestRelease() | ||
} |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package nebulosa.api.system | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import okhttp3.OkHttpClient | ||
import okhttp3.Request | ||
import org.springframework.http.HttpHeaders | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class SystemService( | ||
private val httpClient: OkHttpClient, | ||
private val objectMapper: ObjectMapper, | ||
) { | ||
|
||
fun latestRelease(): GitHubLatestRelease? { | ||
val request = Request.Builder() | ||
.get() | ||
.url(GITHUB_LATEST_RELEASE_URL) | ||
.header(HttpHeaders.ACCEPT, "application/vnd.github+json") | ||
.header(GITHUB_API_VERSION_HEADER_KEY, GITHUB_API_VERSION_HEADER_VALUE) | ||
.build() | ||
|
||
val response = httpClient.newCall(request).execute() | ||
|
||
return response.body?.byteStream() | ||
?.use { objectMapper.readValue(it, GitHubLatestRelease::class.java) } | ||
} | ||
|
||
companion object { | ||
|
||
const val GITHUB_LATEST_RELEASE_URL = "https://api.github.com/repos/tiagohm/nebulosa/releases/latest" | ||
const val GITHUB_API_VERSION_HEADER_KEY = "X-GitHub-Api-Version" | ||
const val GITHUB_API_VERSION_HEADER_VALUE = "2022-11-28" | ||
} | ||
} |
Oops, something went wrong.