mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-27 09:46:25 +02:00
feat(web): add public chat and thread API types and services
This commit is contained in:
parent
aeb0deb21e
commit
9d7259aab9
5 changed files with 170 additions and 2 deletions
49
surfsense_web/lib/apis/public-chat-api.service.ts
Normal file
49
surfsense_web/lib/apis/public-chat-api.service.ts
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
import {
|
||||
type ClonePublicChatRequest,
|
||||
type ClonePublicChatResponse,
|
||||
clonePublicChatRequest,
|
||||
clonePublicChatResponse,
|
||||
type GetPublicChatRequest,
|
||||
type GetPublicChatResponse,
|
||||
getPublicChatRequest,
|
||||
getPublicChatResponse,
|
||||
} from "@/contracts/types/public-chat.types";
|
||||
import { ValidationError } from "../error";
|
||||
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);
|
||||
|
||||
if (!parsed.success) {
|
||||
const errorMessage = parsed.error.issues.map((issue) => issue.message).join(", ");
|
||||
throw new ValidationError(`Invalid request: ${errorMessage}`);
|
||||
}
|
||||
|
||||
return baseApiService.get(`/api/v1/public/${parsed.data.share_token}`, getPublicChatResponse);
|
||||
};
|
||||
|
||||
/**
|
||||
* Clone a public chat to the user's account.
|
||||
* Requires authentication.
|
||||
*/
|
||||
clonePublicChat = async (request: ClonePublicChatRequest): Promise<ClonePublicChatResponse> => {
|
||||
const parsed = clonePublicChatRequest.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/public/${parsed.data.share_token}/clone`,
|
||||
clonePublicChatResponse
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
export const publicChatApiService = new PublicChatApiService();
|
||||
Loading…
Add table
Add a link
Reference in a new issue