|
@@ -11,9 +11,11 @@ import type * as SDK from "@opencode-ai/sdk/v2"
|
|
|
export namespace ShareNext {
|
|
export namespace ShareNext {
|
|
|
const log = Log.create({ service: "share-next" })
|
|
const log = Log.create({ service: "share-next" })
|
|
|
|
|
|
|
|
|
|
+ async function url() {
|
|
|
|
|
+ return Config.get().then((x) => x.enterprise?.url ?? "https://opncd.ai")
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
export async function init() {
|
|
export async function init() {
|
|
|
- const config = await Config.get()
|
|
|
|
|
- if (!config.enterprise) return
|
|
|
|
|
Bus.subscribe(Session.Event.Updated, async (evt) => {
|
|
Bus.subscribe(Session.Event.Updated, async (evt) => {
|
|
|
await sync(evt.properties.info.id, [
|
|
await sync(evt.properties.info.id, [
|
|
|
{
|
|
{
|
|
@@ -62,8 +64,7 @@ export namespace ShareNext {
|
|
|
|
|
|
|
|
export async function create(sessionID: string) {
|
|
export async function create(sessionID: string) {
|
|
|
log.info("creating share", { sessionID })
|
|
log.info("creating share", { sessionID })
|
|
|
- const url = await Config.get().then((x) => x.enterprise!.url)
|
|
|
|
|
- const result = await fetch(`${url}/api/share`, {
|
|
|
|
|
|
|
+ const result = await fetch(`${await url()}/api/share`, {
|
|
|
method: "POST",
|
|
method: "POST",
|
|
|
headers: {
|
|
headers: {
|
|
|
"Content-Type": "application/json",
|
|
"Content-Type": "application/json",
|
|
@@ -126,11 +127,10 @@ export namespace ShareNext {
|
|
|
const queued = queue.get(sessionID)
|
|
const queued = queue.get(sessionID)
|
|
|
if (!queued) return
|
|
if (!queued) return
|
|
|
queue.delete(sessionID)
|
|
queue.delete(sessionID)
|
|
|
- const url = await Config.get().then((x) => x.enterprise!.url)
|
|
|
|
|
const share = await get(sessionID)
|
|
const share = await get(sessionID)
|
|
|
if (!share) return
|
|
if (!share) return
|
|
|
|
|
|
|
|
- await fetch(`${url}/api/share/${share.id}/sync`, {
|
|
|
|
|
|
|
+ await fetch(`${await url()}/api/share/${share.id}/sync`, {
|
|
|
method: "POST",
|
|
method: "POST",
|
|
|
headers: {
|
|
headers: {
|
|
|
"Content-Type": "application/json",
|
|
"Content-Type": "application/json",
|
|
@@ -146,10 +146,9 @@ export namespace ShareNext {
|
|
|
|
|
|
|
|
export async function remove(sessionID: string) {
|
|
export async function remove(sessionID: string) {
|
|
|
log.info("removing share", { sessionID })
|
|
log.info("removing share", { sessionID })
|
|
|
- const url = await Config.get().then((x) => x.enterprise!.url)
|
|
|
|
|
const share = await get(sessionID)
|
|
const share = await get(sessionID)
|
|
|
if (!share) return
|
|
if (!share) return
|
|
|
- await fetch(`${url}/api/share/${share.id}`, {
|
|
|
|
|
|
|
+ await fetch(`${await url()}/api/share/${share.id}`, {
|
|
|
method: "DELETE",
|
|
method: "DELETE",
|
|
|
headers: {
|
|
headers: {
|
|
|
"Content-Type": "application/json",
|
|
"Content-Type": "application/json",
|