Replace document_id with relative id on the FE
This commit is contained in:
parent
47e976b0bb
commit
7d4b5eb33a
3 changed files with 14 additions and 60 deletions
|
|
@ -3,7 +3,6 @@ import { DEFAULT_SETTINGS, SyncSettings } from "./sync-settings";
|
||||||
import {
|
import {
|
||||||
RelativePath,
|
RelativePath,
|
||||||
DocumentMetadata,
|
DocumentMetadata,
|
||||||
DocumentId,
|
|
||||||
DocumentVersionId,
|
DocumentVersionId,
|
||||||
} from "./document-metadata";
|
} from "./document-metadata";
|
||||||
|
|
||||||
|
|
@ -88,17 +87,14 @@ export class Database {
|
||||||
|
|
||||||
public async setDocument({
|
public async setDocument({
|
||||||
relativePath,
|
relativePath,
|
||||||
documentId,
|
|
||||||
parentVersionId,
|
parentVersionId,
|
||||||
hash,
|
hash,
|
||||||
}: {
|
}: {
|
||||||
relativePath: RelativePath;
|
relativePath: RelativePath;
|
||||||
documentId: DocumentId;
|
|
||||||
parentVersionId: DocumentVersionId;
|
parentVersionId: DocumentVersionId;
|
||||||
hash: string;
|
hash: string;
|
||||||
}): Promise<void> {
|
}): Promise<void> {
|
||||||
this._documents.set(relativePath, {
|
this._documents.set(relativePath, {
|
||||||
documentId,
|
|
||||||
parentVersionId,
|
parentVersionId,
|
||||||
hash,
|
hash,
|
||||||
});
|
});
|
||||||
|
|
@ -108,19 +104,16 @@ export class Database {
|
||||||
public async moveDocument({
|
public async moveDocument({
|
||||||
oldRelativePath,
|
oldRelativePath,
|
||||||
relativePath,
|
relativePath,
|
||||||
documentId,
|
|
||||||
parentVersionId,
|
parentVersionId,
|
||||||
hash,
|
hash,
|
||||||
}: {
|
}: {
|
||||||
oldRelativePath: RelativePath;
|
oldRelativePath: RelativePath;
|
||||||
relativePath: RelativePath;
|
relativePath: RelativePath;
|
||||||
documentId: DocumentId;
|
|
||||||
parentVersionId: DocumentVersionId;
|
parentVersionId: DocumentVersionId;
|
||||||
hash: string;
|
hash: string;
|
||||||
}): Promise<void> {
|
}): Promise<void> {
|
||||||
this._documents.delete(oldRelativePath);
|
this._documents.delete(oldRelativePath);
|
||||||
this._documents.set(relativePath, {
|
this._documents.set(relativePath, {
|
||||||
documentId,
|
|
||||||
parentVersionId,
|
parentVersionId,
|
||||||
hash,
|
hash,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,7 @@
|
||||||
export type DocumentId = string;
|
|
||||||
export type DocumentVersionId = number;
|
export type DocumentVersionId = number;
|
||||||
export type RelativePath = string;
|
export type RelativePath = string;
|
||||||
|
|
||||||
export interface DocumentMetadata {
|
export interface DocumentMetadata {
|
||||||
documentId: DocumentId;
|
|
||||||
parentVersionId: DocumentVersionId;
|
parentVersionId: DocumentVersionId;
|
||||||
hash: string;
|
hash: string;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,8 @@ import { Logger } from "src/logger";
|
||||||
import { Database } from "src/database/database";
|
import { Database } from "src/database/database";
|
||||||
import { SyncSettings } from "src/database/sync-settings";
|
import { SyncSettings } from "src/database/sync-settings";
|
||||||
import {
|
import {
|
||||||
DocumentId,
|
|
||||||
DocumentVersionId,
|
DocumentVersionId,
|
||||||
|
RelativePath,
|
||||||
} from "src/database/document-metadata.js";
|
} from "src/database/document-metadata.js";
|
||||||
|
|
||||||
export class SyncServer {
|
export class SyncServer {
|
||||||
|
|
@ -46,61 +46,24 @@ export class SyncServer {
|
||||||
return response.data;
|
return response.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async create({
|
public async put({
|
||||||
relativePath,
|
relativePath,
|
||||||
contentBytes,
|
|
||||||
createdDate,
|
|
||||||
}: {
|
|
||||||
contentBytes: Uint8Array;
|
|
||||||
relativePath: string;
|
|
||||||
createdDate: Date;
|
|
||||||
}): Promise<components["schemas"]["DocumentVersion"]> {
|
|
||||||
let response = await this.client.POST("/vaults/{vault_id}/documents", {
|
|
||||||
params: {
|
|
||||||
path: { vault_id: SyncServer.VAULT_ID },
|
|
||||||
header: {
|
|
||||||
authorization:
|
|
||||||
"Bearer " + this.database.getSettings().token,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
body: {
|
|
||||||
contentBase64: lib.bytes_to_base64(contentBytes),
|
|
||||||
createdDate: createdDate.toISOString(),
|
|
||||||
relativePath,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!response.data) {
|
|
||||||
throw new Error(`Failed to create document: ${response.error}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
Logger.getInstance().info(
|
|
||||||
"Created document " + JSON.stringify(response.data)
|
|
||||||
);
|
|
||||||
|
|
||||||
return response.data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async update({
|
|
||||||
documentId,
|
|
||||||
parentVersionId,
|
parentVersionId,
|
||||||
relativePath,
|
|
||||||
contentBytes,
|
contentBytes,
|
||||||
createdDate,
|
createdDate,
|
||||||
}: {
|
}: {
|
||||||
documentId: DocumentId;
|
relativePath: RelativePath;
|
||||||
parentVersionId: DocumentVersionId;
|
parentVersionId: DocumentVersionId | undefined;
|
||||||
relativePath: string;
|
|
||||||
contentBytes: Uint8Array;
|
contentBytes: Uint8Array;
|
||||||
createdDate: Date;
|
createdDate: Date;
|
||||||
}): Promise<components["schemas"]["DocumentVersion"]> {
|
}): Promise<components["schemas"]["DocumentVersion"]> {
|
||||||
let response = await this.client.PUT(
|
let response = await this.client.PUT(
|
||||||
"/vaults/{vault_id}/documents/{document_id}",
|
"/vaults/{vault_id}/documents/{relative_path}",
|
||||||
{
|
{
|
||||||
params: {
|
params: {
|
||||||
path: {
|
path: {
|
||||||
vault_id: SyncServer.VAULT_ID,
|
vault_id: SyncServer.VAULT_ID,
|
||||||
document_id: documentId,
|
relative_path: encodeURIComponent(relativePath),
|
||||||
},
|
},
|
||||||
header: {
|
header: {
|
||||||
authorization:
|
authorization:
|
||||||
|
|
@ -128,19 +91,19 @@ export class SyncServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async delete({
|
public async delete({
|
||||||
documentId,
|
relativePath,
|
||||||
createdDate,
|
createdDate,
|
||||||
}: {
|
}: {
|
||||||
documentId: DocumentId;
|
relativePath: RelativePath;
|
||||||
createdDate: Date;
|
createdDate: Date;
|
||||||
}): Promise<void> {
|
}): Promise<void> {
|
||||||
const response = await this.client.DELETE(
|
const response = await this.client.DELETE(
|
||||||
"/vaults/{vault_id}/documents/{document_id}",
|
"/vaults/{vault_id}/documents/{relative_path}",
|
||||||
{
|
{
|
||||||
params: {
|
params: {
|
||||||
path: {
|
path: {
|
||||||
vault_id: SyncServer.VAULT_ID,
|
vault_id: SyncServer.VAULT_ID,
|
||||||
document_id: documentId,
|
relative_path: encodeURIComponent(relativePath),
|
||||||
},
|
},
|
||||||
header: {
|
header: {
|
||||||
authorization:
|
authorization:
|
||||||
|
|
@ -166,17 +129,17 @@ export class SyncServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async get({
|
public async get({
|
||||||
documentId,
|
relativePath,
|
||||||
}: {
|
}: {
|
||||||
documentId: DocumentId;
|
relativePath: RelativePath;
|
||||||
}): Promise<components["schemas"]["DocumentVersion"]> {
|
}): Promise<components["schemas"]["DocumentVersion"]> {
|
||||||
const response = await this.client.GET(
|
const response = await this.client.GET(
|
||||||
"/vaults/{vault_id}/documents/{document_id}",
|
"/vaults/{vault_id}/documents/{relative_path}",
|
||||||
{
|
{
|
||||||
params: {
|
params: {
|
||||||
path: {
|
path: {
|
||||||
vault_id: SyncServer.VAULT_ID,
|
vault_id: SyncServer.VAULT_ID,
|
||||||
document_id: documentId,
|
relative_path: encodeURIComponent(relativePath),
|
||||||
},
|
},
|
||||||
header: {
|
header: {
|
||||||
authorization:
|
authorization:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue