Add push operations to plugin

This commit is contained in:
Andras Schmelczer 2024-12-12 22:17:59 +00:00
parent a2066cfc1c
commit 9ce8245abc
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
7 changed files with 78 additions and 53 deletions

View file

@ -1,4 +1,4 @@
import * as plugin from "../../../backend/sync_lib/pkg/sync_lib.js";
import * as lib from "../../../backend/sync_lib/pkg/sync_lib.js";
import createClient, { Client } from "openapi-fetch";
import type { components, paths } from "./types"; // generated by openapi-typescript
@ -48,14 +48,13 @@ export class SyncServer {
public async create({
relativePath,
content,
contentBytes,
createdDate,
}: {
content: ArrayBuffer;
contentBytes: Uint8Array;
relativePath: string;
createdDate: Date;
}): Promise<components["schemas"]["DocumentVersion"]> {
let contentBytes = new Uint8Array(content);
let response = await this.client.POST("/vaults/{vault_id}/documents", {
params: {
path: { vault_id: SyncServer.VAULT_ID },
@ -65,9 +64,8 @@ export class SyncServer {
},
},
body: {
contentBase64: plugin.bytes_to_base64(contentBytes),
contentBase64: lib.bytes_to_base64(contentBytes),
createdDate: createdDate.toISOString(),
isBinary: plugin.is_binary(contentBytes),
relativePath,
},
});
@ -87,17 +85,15 @@ export class SyncServer {
documentId,
parentVersionId,
relativePath,
content,
contentBytes,
createdDate,
}: {
documentId: DocumentId;
parentVersionId: DocumentVersionId;
relativePath: string;
content: ArrayBuffer;
contentBytes: Uint8Array;
createdDate: Date;
}): Promise<components["schemas"]["DocumentVersion"]> {
let contentBytes = new Uint8Array(content);
let response = await this.client.PUT(
"/vaults/{vault_id}/documents/{document_id}",
{
@ -113,9 +109,8 @@ export class SyncServer {
},
body: {
parentVersionId,
contentBase64: plugin.bytes_to_base64(contentBytes),
contentBase64: lib.bytes_to_base64(contentBytes),
createdDate: createdDate.toISOString(),
isBinary: plugin.is_binary(contentBytes),
relativePath,
},
}