mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
2.2 KiB
76 lines
2.2 KiB
/*
|
|
* Squidex Headless CMS
|
|
*
|
|
* @license
|
|
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
|
|
*/
|
|
|
|
import { HttpClient } from '@angular/common/http';
|
|
import { Injectable } from '@angular/core';
|
|
import { Observable } from 'rxjs';
|
|
|
|
import 'framework/angular/http-extensions';
|
|
|
|
import {
|
|
AnalyticsService,
|
|
ApiUrlConfig,
|
|
DateTime
|
|
} from 'framework';
|
|
|
|
export class BackupDto {
|
|
constructor(
|
|
public readonly id: string,
|
|
public readonly isFailed: string,
|
|
public readonly started: DateTime,
|
|
public readonly stopped: DateTime | null
|
|
) {
|
|
}
|
|
}
|
|
|
|
@Injectable()
|
|
export class BackupsService {
|
|
constructor(
|
|
private readonly http: HttpClient,
|
|
private readonly apiUrl: ApiUrlConfig,
|
|
private readonly analytics: AnalyticsService
|
|
) {
|
|
}
|
|
|
|
public getBackups(appName: string): Observable<BackupDto[]> {
|
|
const url = this.apiUrl.buildUrl(`api/apps/${appName}/backups`);
|
|
|
|
return this.http.get(url)
|
|
.map(response => {
|
|
const items: any[] = <any>response;
|
|
|
|
return items.map(item => {
|
|
return new BackupDto(
|
|
item.id,
|
|
item.isFailed,
|
|
DateTime.parseISO_UTC(item.stopped),
|
|
item.stopped ? DateTime.parseISO_UTC(item.stopped) : null);
|
|
});
|
|
})
|
|
.pretifyError('Failed to load backups.');
|
|
}
|
|
|
|
public postBackup(appName: string): Observable<any> {
|
|
const url = this.apiUrl.buildUrl(`api/apps/${appName}/backups`);
|
|
|
|
return this.http.post(url, {})
|
|
.do(() => {
|
|
this.analytics.trackEvent('Backup', 'Started', appName);
|
|
})
|
|
.pretifyError('Failed to start backup.');
|
|
}
|
|
|
|
public deleteBackup(appName: string, id: string): Observable<any> {
|
|
const url = this.apiUrl.buildUrl(`api/apps/${appName}/backups/${id}`);
|
|
|
|
return this.http.delete(url)
|
|
.do(() => {
|
|
this.analytics.trackEvent('Backup', 'Deleted', appName);
|
|
})
|
|
.pretifyError('Failed to delete backup.');
|
|
}
|
|
}
|