mirror of https://github.com/micromata/borgbackup-butler.git

Kai Reinhard
18.09.2021 ea8ad4f8ce1208a08efc8557240c5499b06e4b9a
borgbutler-server/src/main/kotlin/de/micromata/borgbutler/server/rest/ReposRest.kt
@@ -4,7 +4,6 @@
import de.micromata.borgbutler.data.Repository
import de.micromata.borgbutler.json.JsonUtils
import mu.KotlinLogging
import org.apache.commons.collections4.CollectionUtils
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
@@ -16,51 +15,40 @@
@RequestMapping("/rest/repos")
class ReposRest {
    /**
     *
     * @param prettyPrinter If true then the json output will be in pretty format.
     * @return A list of repositories of type [BorgRepository].
     * @see JsonUtils.toJson
     */
    @GetMapping("list")
    fun getList(@RequestParam("prettyPrinter", required = false) prettyPrinter: Boolean?): String {
        val repositories: List<Repository?> = ButlerCache.getInstance().getAllRepositories()
        return if (CollectionUtils.isEmpty(repositories)) {
            "[]"
        } else JsonUtils.toJson(repositories, prettyPrinter)
    fun getList(): List<Repository> {
        return ButlerCache.getInstance().allRepositories
    }
    /**
     *
     * @param id id or name of repo.
     * @param prettyPrinter If true then the json output will be in pretty format.
     * @return [Repository] (without list of archives) as json string.
     * @see JsonUtils.toJson
     */
    @GetMapping("repo")
    fun getRepo(@RequestParam("id") id: String,
                @RequestParam("prettyPrinter", required = false) prettyPrinter: Boolean?): String {
        val repository: Repository = ButlerCache.getInstance().getRepository(id)
        return JsonUtils.toJson(repository, prettyPrinter)
    fun getRepo(@RequestParam("id") id: String): Repository? {
        return ButlerCache.getInstance().getRepository(id)
    }
    /**
     *
     * @param id id or name of repo.
     * @param prettyPrinter If true then the json output will be in pretty format.
     * @return [Repository] (including list of archives) as json string.
     * @see JsonUtils.toJson
     */
    @GetMapping("repoArchiveList")
    fun getRepoArchiveList(
        @RequestParam("id") id: String,
        @RequestParam("force", required = false) force: Boolean?,
        @RequestParam("prettyPrinter", required = false) prettyPrinter: Boolean?
    ): String {
        @RequestParam("force", required = false) force: Boolean?
    ): Repository? {
        if (force == true) {
            val repo: Repository = ButlerCache.getInstance().getRepository(id)
            ButlerCache.getInstance().clearRepoCacheAccess(repo)
        }
        val repository: Repository = ButlerCache.getInstance().getRepositoryArchives(id)
        return JsonUtils.toJson(repository, prettyPrinter)
        return ButlerCache.getInstance().getRepositoryArchives(id)
    }
}