mirror of
https://github.com/coaidev/coai.git
synced 2025-05-19 13:00:14 +09:00
48 lines
951 B
TypeScript
48 lines
951 B
TypeScript
import axios from "axios";
|
|
import {Message} from "./types.ts";
|
|
|
|
export type SharingForm = {
|
|
status: boolean;
|
|
message: string;
|
|
data: string;
|
|
}
|
|
|
|
export type ViewData = {
|
|
name: string;
|
|
username: string;
|
|
time: string;
|
|
messages: Message[];
|
|
};
|
|
|
|
export type ViewForm = {
|
|
status: boolean;
|
|
message: string;
|
|
data: ViewData | null;
|
|
}
|
|
|
|
export async function shareConversation(
|
|
id: number, refs: number[] = [-1],
|
|
): Promise<SharingForm> {
|
|
try {
|
|
const resp = await axios.post("/conversation/share", { id, refs });
|
|
return resp.data;
|
|
} catch (e) {
|
|
return { status: false, message: (e as Error).message, data: "" };
|
|
}
|
|
}
|
|
|
|
export async function viewConversation(
|
|
hash: string,
|
|
): Promise<ViewForm> {
|
|
try {
|
|
const resp = await axios.get(`/conversation/view?hash=${hash}`);
|
|
return resp.data as ViewForm;
|
|
} catch (e) {
|
|
return {
|
|
status: false,
|
|
message: (e as Error).message,
|
|
data: null,
|
|
}
|
|
}
|
|
}
|