diff options
| author | Dax Raad <[email protected]> | 2025-05-30 20:47:56 -0400 |
|---|---|---|
| committer | Dax Raad <[email protected]> | 2025-05-30 20:48:36 -0400 |
| commit | f3da73553c45f17e04b1e77cb13eb0fca714d1bd (patch) | |
| tree | a24317a19e1ab2a89da50db669dc6894f15d00d1 /js/src/share | |
| parent | 9a26b3058ffc1023e5c7e54b6d571c903d15888e (diff) | |
| download | opencode-f3da73553c45f17e04b1e77cb13eb0fca714d1bd.tar.gz opencode-f3da73553c45f17e04b1e77cb13eb0fca714d1bd.zip | |
sync
Diffstat (limited to 'js/src/share')
| -rw-r--r-- | js/src/share/share.ts | 67 |
1 files changed, 0 insertions, 67 deletions
diff --git a/js/src/share/share.ts b/js/src/share/share.ts deleted file mode 100644 index 8d4af8795..000000000 --- a/js/src/share/share.ts +++ /dev/null @@ -1,67 +0,0 @@ -import { App } from "../app/app"; -import { Bus } from "../bus"; -import { Session } from "../session/session"; -import { Storage } from "../storage/storage"; -import { Log } from "../util/log"; - -export namespace Share { - const log = Log.create({ service: "share" }); - - let queue: Promise<void> = Promise.resolve(); - const pending = new Map<string, any>(); - - 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 [, sessionID] = splits; - const session = await Session.get(sessionID); - if (!session.share) return; - const { secret } = session.share; - - const key = payload.properties.key; - pending.set(key, payload.properties.content); - - queue = queue - .then(async () => { - const content = pending.get(key); - if (content === undefined) return; - pending.delete(key); - - return fetch(`${URL}/share_sync`, { - method: "POST", - body: JSON.stringify({ - sessionID: sessionID, - secret, - key: key, - content, - }), - }); - }) - .then((x) => { - if (x) { - log.info("synced", { - key: key, - status: x.status, - }); - } - }); - }); - }); - - export async function init() { - await state(); - } - - export const URL = - process.env["OPENCODE_API"] ?? "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 as { url: string; secret: string }); - } -} |
