ignore: share page stuff

This commit is contained in:
Dax Raad
2025-06-18 16:13:09 -04:00
parent ac777b77cf
commit 658067186a
4 changed files with 21 additions and 11 deletions

View File

@@ -9,10 +9,7 @@
"dev": "bun run ./src/index.ts" "dev": "bun run ./src/index.ts"
}, },
"exports": { "exports": {
"./*": [ "./*": "./src/*.ts"
"./src/*.ts",
"./src/*/index.ts"
]
}, },
"devDependencies": { "devDependencies": {
"@tsconfig/bun": "1.0.7", "@tsconfig/bun": "1.0.7",

View File

@@ -42,7 +42,6 @@ export namespace Session {
parentID: Identifier.schema("session").optional(), parentID: Identifier.schema("session").optional(),
share: z share: z
.object({ .object({
secret: z.string(),
url: z.string(), url: z.string(),
}) })
.optional(), .optional(),
@@ -58,6 +57,12 @@ export namespace Session {
}) })
export type Info = z.output<typeof Info> export type Info = z.output<typeof Info>
export const ShareInfo = z.object({
secret: z.string(),
url: z.string(),
})
export type ShareInfo = z.output<typeof ShareInfo>
export const Event = { export const Event = {
Updated: Bus.event( Updated: Bus.event(
"session.updated", "session.updated",
@@ -132,13 +137,20 @@ export namespace Session {
return read as Info return read as Info
} }
export async function getShare(id: string) {
return Storage.readJSON<ShareInfo>("session/share/" + id)
}
export async function share(id: string) { export async function share(id: string) {
const session = await get(id) const session = await get(id)
if (session.share) return session.share if (session.share) return session.share
const share = await Share.create(id) const share = await Share.create(id)
await update(id, (draft) => { await update(id, (draft) => {
draft.share = share draft.share = {
url: share.url,
}
}) })
await Storage.writeJSON<ShareInfo>("session/share/" + id, share)
for (const msg of await messages(id)) { for (const msg of await messages(id)) {
await Share.sync("session/message/" + id + "/" + msg.id, msg) await Share.sync("session/message/" + id + "/" + msg.id, msg)
} }

View File

@@ -19,10 +19,11 @@ export namespace Share {
export async function sync(key: string, content: any) { export async function sync(key: string, content: any) {
const [root, ...splits] = key.split("/") const [root, ...splits] = key.split("/")
if (root !== "session") return if (root !== "session") return
const [, sessionID] = splits const [sub, sessionID] = splits
const session = await Session.get(sessionID) if (sub === "share") return
if (!session.share) return const share = await Session.getShare(sessionID).catch(() => {})
const { secret } = session.share if (!share) return
const { secret } = share
pending.set(key, content) pending.set(key, content)
queue = queue queue = queue
.then(async () => { .then(async () => {

View File

@@ -37,7 +37,7 @@ import CodeBlock from "./CodeBlock"
import MarkdownView from "./MarkdownView" import MarkdownView from "./MarkdownView"
import styles from "./share.module.css" import styles from "./share.module.css"
import { type Message } from "opencode/session/message" import { type Message } from "opencode/session/message"
import { type Session } from "opencode/session" import { type Session } from "opencode/session/index"
const MIN_DURATION = 2 const MIN_DURATION = 2