Add API for propagating cursor locations #61
2 changed files with 20 additions and 21 deletions
|
|
@ -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/http-api"; // generated by openapi-typescript
|
||||
import type {
|
||||
DocumentId,
|
||||
RelativePath,
|
||||
|
|
@ -44,19 +44,6 @@ export class SyncService {
|
|||
});
|
||||
}
|
||||
|
||||
private get deviceIdHeader(): string {
|
||||
// @ts-expect-error, injected by webpack
|
||||
const packageVersion = __CURRENT_VERSION__; // eslint-disable-line
|
||||
|
||||
const platform =
|
||||
typeof navigator !== "undefined"
|
||||
? navigator.platform // eslint-disable-line @typescript-eslint/no-deprecated
|
||||
: typeof process !== "undefined"
|
||||
? process.platform
|
||||
: "unknown";
|
||||
return `vault-link/${packageVersion} (${this.deviceId}; ${platform})`;
|
||||
}
|
||||
|
||||
private static formatError(
|
||||
error: components["schemas"]["SerializedError"]
|
||||
): string {
|
||||
|
|
@ -86,7 +73,6 @@ export class SyncService {
|
|||
formData.append("document_id", documentId);
|
||||
}
|
||||
formData.append("relative_path", relativePath);
|
||||
formData.append("device_id", this.deviceId);
|
||||
formData.append("content", new Blob([contentBytes]));
|
||||
|
||||
const response = await this.client.POST(
|
||||
|
|
@ -97,7 +83,7 @@ export class SyncService {
|
|||
vault_id: vaultName
|
||||
},
|
||||
header: {
|
||||
"device-id": this.deviceIdHeader
|
||||
"device-id": this.deviceId
|
||||
}
|
||||
},
|
||||
// eslint-disable-next-line
|
||||
|
|
@ -141,7 +127,6 @@ export class SyncService {
|
|||
const formData = new FormData();
|
||||
formData.append("parent_version_id", parentVersionId.toString());
|
||||
formData.append("relative_path", relativePath);
|
||||
formData.append("device_id", this.deviceId);
|
||||
formData.append("content", new Blob([contentBytes]));
|
||||
|
||||
const response = await this.client.PUT(
|
||||
|
|
@ -153,7 +138,7 @@ export class SyncService {
|
|||
document_id: documentId
|
||||
},
|
||||
header: {
|
||||
"device-id": this.deviceIdHeader
|
||||
"device-id": this.deviceId
|
||||
}
|
||||
},
|
||||
// eslint-disable-next-line
|
||||
|
|
@ -196,13 +181,12 @@ export class SyncService {
|
|||
document_id: documentId
|
||||
},
|
||||
header: {
|
||||
"device-id": this.deviceIdHeader
|
||||
"device-id": this.deviceId
|
||||
}
|
||||
},
|
||||
|
||||
body: {
|
||||
relativePath,
|
||||
deviceId: this.deviceId
|
||||
relativePath
|
||||
}
|
||||
}
|
||||
);
|
||||
|
|
|
|||
15
frontend/sync-client/src/utils/create-client-id.ts
Normal file
15
frontend/sync-client/src/utils/create-client-id.ts
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import { v4 as uuidv4 } from "uuid";
|
||||
|
||||
export function createClientId(): string {
|
||||
// @ts-expect-error, injected by webpack
|
||||
const packageVersion = __CURRENT_VERSION__; // eslint-disable-line
|
||||
|
||||
const platform =
|
||||
typeof navigator !== "undefined"
|
||||
? navigator.platform // eslint-disable-line @typescript-eslint/no-deprecated
|
||||
: typeof process !== "undefined"
|
||||
? process.platform
|
||||
: "unknown";
|
||||
|
||||
return `vault-link/${packageVersion} (${uuidv4()}; ${platform})`;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue