mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-25 16:56:22 +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
33
surfsense_web/lib/apis/chat-threads-api.service.ts
Normal file
33
surfsense_web/lib/apis/chat-threads-api.service.ts
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import {
|
||||
type TogglePublicShareRequest,
|
||||
type TogglePublicShareResponse,
|
||||
togglePublicShareRequest,
|
||||
togglePublicShareResponse,
|
||||
} 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.
|
||||
*/
|
||||
togglePublicShare = async (
|
||||
request: TogglePublicShareRequest
|
||||
): Promise<TogglePublicShareResponse> => {
|
||||
const parsed = togglePublicShareRequest.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 } }
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
export const chatThreadsApiService = new ChatThreadsApiService();
|
||||
Loading…
Add table
Add a link
Reference in a new issue