summaryrefslogtreecommitdiffhomepage
path: root/js/src/share
diff options
context:
space:
mode:
authorDax Raad <[email protected]>2025-05-23 16:20:21 -0400
committerDax Raad <[email protected]>2025-05-26 12:40:17 -0400
commit5f750b7368226ce455a6848f5f744d43179198e5 (patch)
treec7b85ed5f9a71ac957cdef04368be62fe7f04745 /js/src/share
parente2dc5a8faf9d4362a99c5cd74a676e3b5436ceb4 (diff)
downloadopencode-5f750b7368226ce455a6848f5f744d43179198e5.tar.gz
opencode-5f750b7368226ce455a6848f5f744d43179198e5.zip
share
Diffstat (limited to 'js/src/share')
-rw-r--r--js/src/share/share.ts45
1 files changed, 45 insertions, 0 deletions
diff --git a/js/src/share/share.ts b/js/src/share/share.ts
new file mode 100644
index 000000000..6c0573e91
--- /dev/null
+++ b/js/src/share/share.ts
@@ -0,0 +1,45 @@
+import { App } from "../app";
+import { Bus } from "../bus";
+import { Session } from "../session/session";
+import { Storage } from "../storage/storage";
+
+export namespace Share {
+ const state = App.state("share", async () => {
+ Bus.subscribe(Storage.Event.Write, async (payload) => {
+ const [root, ...splits] = payload.properties.key.split("/");
+ if (root !== "session") return;
+ const [type, sessionID] = splits;
+ const session = await Session.get(sessionID);
+ if (!session.shareID) return;
+ console.log({
+ sessionID: sessionID,
+ shareID: session.shareID,
+ key: payload.properties.key,
+ content: payload.properties.content,
+ });
+ await fetch(`${URL}/share_sync`, {
+ method: "POST",
+ body: JSON.stringify({
+ sessionID: sessionID,
+ shareID: session.shareID,
+ key: payload.properties.key,
+ content: payload.properties.content,
+ }),
+ }).then(console.log);
+ });
+ });
+
+ export async function init() {
+ await state();
+ }
+
+ const URL = "https://api.dev.opencode.ai";
+ export async function create(sessionID: string) {
+ return fetch(`${URL}/share_create`, {
+ method: "POST",
+ body: JSON.stringify({ sessionID: sessionID }),
+ })
+ .then((x) => x.json())
+ .then((x) => x.shareID);
+ }
+}