coai/app/src/conversation/sharing.ts
2023-10-18 23:29:17 +08:00

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,
}
}
}