Extract device id generation

This commit is contained in:
Andras Schmelczer 2025-06-01 09:59:37 +01:00
parent 4657314b72
commit eeff9f7aa1
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
2 changed files with 20 additions and 21 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/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
}
}
);

View 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})`;
}