mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-25 08:46:22 +02:00
feat: add snapshot types and API services
This commit is contained in:
parent
fb73a2e69f
commit
6aff69f4ec
4 changed files with 92 additions and 66 deletions
|
|
@ -1,31 +1,66 @@
|
|||
import {
|
||||
type TogglePublicShareRequest,
|
||||
type TogglePublicShareResponse,
|
||||
togglePublicShareRequest,
|
||||
togglePublicShareResponse,
|
||||
type CreateSnapshotRequest,
|
||||
type CreateSnapshotResponse,
|
||||
createSnapshotRequest,
|
||||
createSnapshotResponse,
|
||||
type DeleteSnapshotRequest,
|
||||
deleteSnapshotRequest,
|
||||
type ListSnapshotsRequest,
|
||||
type ListSnapshotsResponse,
|
||||
listSnapshotsRequest,
|
||||
listSnapshotsResponse,
|
||||
} from "@/contracts/types/chat-threads.types";
|
||||
import { ValidationError } from "../error";
|
||||
import { baseApiService } from "./base-api.service";
|
||||
|
||||
class ChatThreadsApiService {
|
||||
/**
|
||||
* Toggle public sharing for a thread.
|
||||
* Requires authentication.
|
||||
* Create a public snapshot for a thread.
|
||||
*/
|
||||
togglePublicShare = async (
|
||||
request: TogglePublicShareRequest
|
||||
): Promise<TogglePublicShareResponse> => {
|
||||
const parsed = togglePublicShareRequest.safeParse(request);
|
||||
createSnapshot = async (request: CreateSnapshotRequest): Promise<CreateSnapshotResponse> => {
|
||||
const parsed = createSnapshotRequest.safeParse(request);
|
||||
|
||||
if (!parsed.success) {
|
||||
const errorMessage = parsed.error.issues.map((issue) => issue.message).join(", ");
|
||||
throw new ValidationError(`Invalid request: ${errorMessage}`);
|
||||
}
|
||||
|
||||
return baseApiService.patch(
|
||||
`/api/v1/threads/${parsed.data.thread_id}/public-share`,
|
||||
togglePublicShareResponse,
|
||||
{ body: { enabled: parsed.data.enabled } }
|
||||
return baseApiService.post(
|
||||
`/api/v1/threads/${parsed.data.thread_id}/snapshots`,
|
||||
createSnapshotResponse
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* List all snapshots for a thread.
|
||||
*/
|
||||
listSnapshots = async (request: ListSnapshotsRequest): Promise<ListSnapshotsResponse> => {
|
||||
const parsed = listSnapshotsRequest.safeParse(request);
|
||||
|
||||
if (!parsed.success) {
|
||||
const errorMessage = parsed.error.issues.map((issue) => issue.message).join(", ");
|
||||
throw new ValidationError(`Invalid request: ${errorMessage}`);
|
||||
}
|
||||
|
||||
return baseApiService.get(
|
||||
`/api/v1/threads/${parsed.data.thread_id}/snapshots`,
|
||||
listSnapshotsResponse
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Delete a specific snapshot.
|
||||
*/
|
||||
deleteSnapshot = async (request: DeleteSnapshotRequest): Promise<void> => {
|
||||
const parsed = deleteSnapshotRequest.safeParse(request);
|
||||
|
||||
if (!parsed.success) {
|
||||
const errorMessage = parsed.error.issues.map((issue) => issue.message).join(", ");
|
||||
throw new ValidationError(`Invalid request: ${errorMessage}`);
|
||||
}
|
||||
|
||||
await baseApiService.delete(
|
||||
`/api/v1/threads/${parsed.data.thread_id}/snapshots/${parsed.data.snapshot_id}`
|
||||
);
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue