mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-29 02:46:25 +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,12 +1,8 @@
|
|||
import {
|
||||
type ClonePublicChatRequest,
|
||||
type ClonePublicChatResponse,
|
||||
type CompleteCloneRequest,
|
||||
type CompleteCloneResponse,
|
||||
clonePublicChatRequest,
|
||||
clonePublicChatResponse,
|
||||
completeCloneRequest,
|
||||
completeCloneResponse,
|
||||
type GetPublicChatRequest,
|
||||
type GetPublicChatResponse,
|
||||
getPublicChatRequest,
|
||||
|
|
@ -18,7 +14,6 @@ import { baseApiService } from "./base-api.service";
|
|||
class PublicChatApiService {
|
||||
/**
|
||||
* Get a public chat by share token.
|
||||
* No authentication required.
|
||||
*/
|
||||
getPublicChat = async (request: GetPublicChatRequest): Promise<GetPublicChatResponse> => {
|
||||
const parsed = getPublicChatRequest.safeParse(request);
|
||||
|
|
@ -33,8 +28,6 @@ class PublicChatApiService {
|
|||
|
||||
/**
|
||||
* Clone a public chat to the user's account.
|
||||
* Creates an empty thread and returns thread_id for redirect.
|
||||
* Requires authentication.
|
||||
*/
|
||||
clonePublicChat = async (request: ClonePublicChatRequest): Promise<ClonePublicChatResponse> => {
|
||||
const parsed = clonePublicChatRequest.safeParse(request);
|
||||
|
|
@ -49,25 +42,6 @@ class PublicChatApiService {
|
|||
clonePublicChatResponse
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Complete the clone by copying messages and podcasts.
|
||||
* Called from the chat page after redirect.
|
||||
* Requires authentication.
|
||||
*/
|
||||
completeClone = async (request: CompleteCloneRequest): Promise<CompleteCloneResponse> => {
|
||||
const parsed = completeCloneRequest.safeParse(request);
|
||||
|
||||
if (!parsed.success) {
|
||||
const errorMessage = parsed.error.issues.map((issue) => issue.message).join(", ");
|
||||
throw new ValidationError(`Invalid request: ${errorMessage}`);
|
||||
}
|
||||
|
||||
return baseApiService.post(
|
||||
`/api/v1/threads/${parsed.data.thread_id}/complete-clone`,
|
||||
completeCloneResponse
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
export const publicChatApiService = new PublicChatApiService();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue