Simplify API

This commit is contained in:
Andras Schmelczer 2025-02-20 22:22:20 +00:00
commit eb1ad9921a
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
5 changed files with 203 additions and 53 deletions

View file

@ -1,6 +1,6 @@
import type { Client } from "openapi-fetch";
import createClient from "openapi-fetch";
import type { components, paths } from "./types"; // Generated by openapi-typescript
import type { components, paths } from "./types"; // generated by openapi-typescript
import type {
DocumentId,
RelativePath,
@ -16,8 +16,8 @@ export interface CheckConnectionResult {
message: string;
}
export class SyncService {
private client: Client<paths>;
private clientWithoutRetries: Client<paths>;
private client!: Client<paths>;
private clientWithoutRetries!: Client<paths>;
public constructor(private readonly settings: Settings) {
this.createClient(settings.getSettings());
@ -39,28 +39,6 @@ export class SyncService {
return result;
}
public async ping(): Promise<components["schemas"]["PingResponse"]> {
const response = await this.clientWithoutRetries.GET("/ping", {
params: {
header: {
authorization: `Bearer ${this.settings.getSettings().token}`
}
}
});
Logger.getInstance().debug(
`Ping response: ${JSON.stringify(response.data)}`
);
if (!response.data) {
throw new Error(
`Failed to ping server: ${SyncService.formatError(response.error)}`
);
}
return response.data;
}
public async create({
relativePath,
contentBytes,
@ -282,6 +260,28 @@ export class SyncService {
}
}
private async ping(): Promise<components["schemas"]["PingResponse"]> {
const response = await this.clientWithoutRetries.GET("/ping", {
params: {
header: {
authorization: `Bearer ${this.settings.getSettings().token}`
}
}
});
Logger.getInstance().debug(
`Ping response: ${JSON.stringify(response.data)}`
);
if (!response.data) {
throw new Error(
`Failed to ping server: ${SyncService.formatError(response.error)}`
);
}
return response.data;
}
private createClient(settings: SyncSettings): void {
this.client = createClient<paths>({
baseUrl: settings.remoteUri,