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

Kai Reinhard
19.24.2021 7f78d2ed3b282c6bd6bba9dde4110cd4f3d558cf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package de.micromata.borgbutler.server.rest
 
import de.micromata.borgbutler.cache.ButlerCache
import de.micromata.borgbutler.data.Repository
import de.micromata.borgbutler.json.JsonUtils
import mu.KotlinLogging
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
 
private val log = KotlinLogging.logger {}
 
@RestController
@RequestMapping("/rest/repos")
class ReposRest {
    /**
     * @return A list of repositories of type [BorgRepository].
     * @see JsonUtils.toJson
     */
    @GetMapping("list")
    fun getList(): List<Repository> {
        return ButlerCache.getInstance().allRepositories
    }
 
    /**
     *
     * @param id id or name of repo.
     * @return [Repository] (without list of archives) as json string.
     * @see JsonUtils.toJson
     */
    @GetMapping("repo")
    fun getRepo(@RequestParam("id") id: String): Repository? {
        return ButlerCache.getInstance().getRepository(id)
    }
 
    /**
     *
     * @param id id or name of repo.
     * @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?
    ): Repository? {
        if (force == true) {
            val repo: Repository = ButlerCache.getInstance().getRepository(id)
            ButlerCache.getInstance().clearRepoCacheAccess(repo)
        }
        return ButlerCache.getInstance().getRepositoryArchives(id)
    }
}