bazarr/frontend/src/apis/raw/system.ts

110 lines
2.4 KiB
TypeScript
Raw Normal View History

2021-03-25 14:22:43 +00:00
import BaseApi from "./base";
class SystemApi extends BaseApi {
constructor() {
super("/system");
}
private async performAction(action: string) {
2021-08-17 14:52:50 +00:00
await this.post("", undefined, { action });
2021-03-25 14:22:43 +00:00
}
async login(username: string, password: string) {
2021-08-17 14:52:50 +00:00
await this.post("/account", { username, password }, { action: "login" });
2021-03-25 14:22:43 +00:00
}
async logout() {
2021-08-17 14:52:50 +00:00
await this.post("/account", undefined, { action: "logout" });
2021-03-25 14:22:43 +00:00
}
async shutdown() {
return this.performAction("shutdown");
}
async restart() {
return this.performAction("restart");
}
async settings() {
2021-08-17 14:52:50 +00:00
const response = await this.get<Settings>("/settings");
return response;
2021-03-25 14:22:43 +00:00
}
async updateSettings(data: object) {
2021-08-17 14:52:50 +00:00
await this.post("/settings", data);
2021-03-25 14:22:43 +00:00
}
async languages(history = false) {
2021-08-17 14:52:50 +00:00
const response = await this.get<Language.Server[]>("/languages", {
history,
2021-03-25 14:22:43 +00:00
});
2021-08-17 14:52:50 +00:00
return response;
2021-03-25 14:22:43 +00:00
}
async languagesProfileList() {
2021-08-17 14:52:50 +00:00
const response = await this.get<Language.Profile[]>("/languages/profiles");
return response;
2021-03-25 14:22:43 +00:00
}
async status() {
2021-08-17 14:52:50 +00:00
const response = await this.get<DataWrapper<System.Status>>("/status");
return response.data;
2021-03-25 14:22:43 +00:00
}
async backups() {
const response = await this.get<DataWrapper<System.Backups[]>>("/backups");
return response.data;
}
async createBackups() {
await this.post("/backups");
}
async restoreBackups(filename: string) {
await this.patch("/backups", { filename });
}
async deleteBackups(filename: string) {
await this.delete("/backups", { filename });
}
async health() {
2021-08-17 14:52:50 +00:00
const response = await this.get<DataWrapper<System.Health[]>>("/health");
return response.data;
}
2021-03-25 14:22:43 +00:00
async logs() {
2021-08-17 14:52:50 +00:00
const response = await this.get<DataWrapper<System.Log[]>>("/logs");
return response.data;
2021-03-25 14:22:43 +00:00
}
async releases() {
2021-08-17 14:52:50 +00:00
const response = await this.get<DataWrapper<ReleaseInfo[]>>("/releases");
return response.data;
2021-03-25 14:22:43 +00:00
}
async deleteLogs() {
2021-08-17 14:52:50 +00:00
await this.delete("/logs");
2021-03-25 14:22:43 +00:00
}
async tasks() {
2021-08-17 14:52:50 +00:00
const response = await this.get<DataWrapper<System.Task[]>>("/tasks");
return response.data;
2021-03-25 14:22:43 +00:00
}
2021-08-17 14:52:50 +00:00
async runTask(taskid: string) {
await this.post("/tasks", { taskid });
2021-03-25 14:22:43 +00:00
}
2021-04-15 16:46:19 +00:00
async testNotification(url: string) {
2021-08-17 14:52:50 +00:00
await this.patch("/notifications", { url });
2021-03-25 14:22:43 +00:00
}
async search(query: string) {
2021-08-17 14:52:50 +00:00
const response = await this.get<ItemSearchResult[]>("/searches", { query });
return response;
2021-03-25 14:22:43 +00:00
}
}
export default new SystemApi();