Backup Server APIs
Co-authored-by: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com>
This commit is contained in:
parent
5db1768ac5
commit
ac26b0010f
14 changed files with 991 additions and 201 deletions
72
ts/services/backups/api.ts
Normal file
72
ts/services/backups/api.ts
Normal file
|
@ -0,0 +1,72 @@
|
|||
// Copyright 2024 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { strictAssert } from '../../util/assert';
|
||||
import type {
|
||||
WebAPIType,
|
||||
GetBackupInfoResponseType,
|
||||
GetBackupUploadFormResponseType,
|
||||
BackupMediaItemType,
|
||||
BackupMediaBatchResponseType,
|
||||
BackupListMediaResponseType,
|
||||
} from '../../textsecure/WebAPI';
|
||||
import type { BackupCredentials } from './credentials';
|
||||
|
||||
export class BackupAPI {
|
||||
constructor(private credentials: BackupCredentials) {}
|
||||
|
||||
public async refresh(): Promise<void> {
|
||||
// TODO: DESKTOP-6979
|
||||
await this.server.refreshBackup(
|
||||
await this.credentials.getHeadersForToday()
|
||||
);
|
||||
}
|
||||
|
||||
public async getInfo(): Promise<GetBackupInfoResponseType> {
|
||||
return this.server.getBackupInfo(
|
||||
await this.credentials.getHeadersForToday()
|
||||
);
|
||||
}
|
||||
|
||||
public async getUploadForm(): Promise<GetBackupUploadFormResponseType> {
|
||||
return this.server.getBackupUploadForm(
|
||||
await this.credentials.getHeadersForToday()
|
||||
);
|
||||
}
|
||||
|
||||
public async getMediaUploadForm(): Promise<GetBackupUploadFormResponseType> {
|
||||
return this.server.getBackupMediaUploadForm(
|
||||
await this.credentials.getHeadersForToday()
|
||||
);
|
||||
}
|
||||
|
||||
public async backupMediaBatch(
|
||||
items: ReadonlyArray<BackupMediaItemType>
|
||||
): Promise<BackupMediaBatchResponseType> {
|
||||
return this.server.backupMediaBatch({
|
||||
headers: await this.credentials.getHeadersForToday(),
|
||||
items,
|
||||
});
|
||||
}
|
||||
|
||||
public async listMedia({
|
||||
cursor,
|
||||
limit,
|
||||
}: {
|
||||
cursor?: string;
|
||||
limit: number;
|
||||
}): Promise<BackupListMediaResponseType> {
|
||||
return this.server.backupListMedia({
|
||||
headers: await this.credentials.getHeadersForToday(),
|
||||
cursor,
|
||||
limit,
|
||||
});
|
||||
}
|
||||
|
||||
private get server(): WebAPIType {
|
||||
const { server } = window.textsecure;
|
||||
strictAssert(server, 'server not available');
|
||||
|
||||
return server;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue