File size: 646 Bytes
9405a81
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1d0d9b3
9405a81
 
 
34857c4
9405a81
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { base } from "$app/paths";

export async function shareConversation(id: string, title: string) {
	try {
		const res = await fetch(`${base}/conversation/${id}/share`, {
			method: "POST",
			headers: {
				"Content-Type": "application/json",
			},
		});

		if (!res.ok) {
			alert("Error while sharing conversation: " + (await res.text()));
			return;
		}

		const { url } = await res.json();

		if (navigator.share) {
			navigator.share({
				title,
				text: "Share this chat with others",
				url,
			});
		} else {
			prompt("Copy this public url to share:", url);
		}
	} catch (err) {
		console.error(err);
		alert(String(err));
	}
}