summaryrefslogtreecommitdiffhomepage
path: root/frontend/src/apis/system.ts
blob: d21200c288033add05b905245641359f2c764953 (plain)
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import BaseApi from "./base";

class SystemApi extends BaseApi {
  constructor() {
    super("/system");
  }

  private async performAction(action: string) {
    await this.post("", undefined, { action });
  }

  async login(username: string, password: string) {
    await this.post("/account", { username, password }, { action: "login" });
  }

  async logout() {
    await this.post("/account", undefined, { action: "logout" });
  }

  async shutdown() {
    return this.performAction("shutdown");
  }

  async restart() {
    return this.performAction("restart");
  }

  async settings() {
    const response = await this.get<Settings>("/settings");
    return response;
  }

  async setSettings(data: object) {
    await this.post("/settings", data);
  }

  async languages(history: boolean = false) {
    const response = await this.get<Language.Server[]>("/languages", {
      history,
    });
    return response;
  }

  async languagesProfileList() {
    const response = await this.get<Language.Profile[]>("/languages/profiles");
    return response;
  }

  async status() {
    const response = await this.get<DataWrapper<System.Status>>("/status");
    return response.data;
  }

  async health() {
    const response = await this.get<DataWrapper<System.Health[]>>("/health");
    return response.data;
  }

  async logs() {
    const response = await this.get<DataWrapper<System.Log[]>>("/logs");
    return response.data;
  }

  async releases() {
    const response = await this.get<DataWrapper<ReleaseInfo[]>>("/releases");
    return response.data;
  }

  async deleteLogs() {
    await this.delete("/logs");
  }

  async tasks() {
    const response = await this.get<DataWrapper<System.Task[]>>("/tasks");
    return response.data;
  }

  async runTask(taskid: string) {
    await this.post("/tasks", { taskid });
  }

  async testNotification(url: string) {
    await this.patch("/notifications", { url });
  }

  async search(query: string) {
    const response = await this.get<ItemSearchResult[]>("/searches", { query });
    return response;
  }
}

export default new SystemApi();