mirror of
https://github.com/sst/opencode.git
synced 2025-12-23 10:11:41 +00:00
Centralized sharing disabled check in share function
Co-authored-by: thdxr <thdxr@users.noreply.github.com>
This commit is contained in:
parent
db3b16515f
commit
deeccb0bd6
2 changed files with 18 additions and 5 deletions
|
|
@ -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()
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue