Centralized sharing disabled check in share function

Co-authored-by: thdxr <thdxr@users.noreply.github.com>
This commit is contained in:
opencode-agent[bot] 2025-07-13 20:43:32 +00:00
parent db3b16515f
commit deeccb0bd6
2 changed files with 18 additions and 5 deletions

View file

@ -93,11 +93,17 @@ export const RunCommand = cmd({
UI.empty()
const cfg = await Config.get()
if (cfg.share === "auto" || Flag.OPENCODE_AUTO_SHARE || (args.share && cfg.share !== "disabled")) {
await Session.share(session.id)
UI.println(UI.Style.TEXT_INFO_BOLD + "~ https://opencode.ai/s/" + session.id.slice(-8))
} else if (args.share && cfg.share === "disabled") {
UI.println(UI.Style.TEXT_ERROR_BOLD + "! Sharing is disabled in configuration")
if (cfg.share === "auto" || Flag.OPENCODE_AUTO_SHARE || args.share) {
try {
await Session.share(session.id)
UI.println(UI.Style.TEXT_INFO_BOLD + "~ https://opencode.ai/s/" + session.id.slice(-8))
} catch (error) {
if (error instanceof Error && error.message.includes("disabled")) {
UI.println(UI.Style.TEXT_ERROR_BOLD + "! " + error.message)
} else {
throw error
}
}
}
UI.empty()

View file

@ -150,6 +150,8 @@ export namespace Session {
update(result.id, (draft) => {
draft.share = share
})
}).catch(() => {
// Silently ignore sharing errors during session creation
})
Bus.publish(Event.Updated, {
info: result,
@ -172,6 +174,11 @@ export namespace Session {
}
export async function share(id: string) {
const cfg = await Config.get()
if (cfg.share === "disabled") {
throw new Error("Sharing is disabled in configuration")
}
const session = await get(id)
if (session.share) return session.share
const share = await Share.create(id)