mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-20 09:14:22 +01:00
wip: zen
This commit is contained in:
@@ -2,7 +2,7 @@ import { getRequestEvent } from "solid-js/web"
|
|||||||
import { and, Database, eq, inArray } from "@opencode/cloud-core/drizzle/index.js"
|
import { and, Database, eq, inArray } from "@opencode/cloud-core/drizzle/index.js"
|
||||||
import { WorkspaceTable } from "@opencode/cloud-core/schema/workspace.sql.js"
|
import { WorkspaceTable } from "@opencode/cloud-core/schema/workspace.sql.js"
|
||||||
import { UserTable } from "@opencode/cloud-core/schema/user.sql.js"
|
import { UserTable } from "@opencode/cloud-core/schema/user.sql.js"
|
||||||
import { query, redirect } from "@solidjs/router"
|
import { redirect } from "@solidjs/router"
|
||||||
import { AccountTable } from "@opencode/cloud-core/schema/account.sql.js"
|
import { AccountTable } from "@opencode/cloud-core/schema/account.sql.js"
|
||||||
import { Actor } from "@opencode/cloud-core/actor.js"
|
import { Actor } from "@opencode/cloud-core/actor.js"
|
||||||
|
|
||||||
@@ -14,7 +14,7 @@ export const AuthClient = createClient({
|
|||||||
issuer: import.meta.env.VITE_AUTH_URL,
|
issuer: import.meta.env.VITE_AUTH_URL,
|
||||||
})
|
})
|
||||||
|
|
||||||
export const getActor = query(async (): Promise<Actor.Info> => {
|
export const getActor = async (): Promise<Actor.Info> => {
|
||||||
"use server"
|
"use server"
|
||||||
const evt = getRequestEvent()
|
const evt = getRequestEvent()
|
||||||
if (!evt) throw new Error("No request event")
|
if (!evt) throw new Error("No request event")
|
||||||
@@ -53,6 +53,7 @@ export const getActor = query(async (): Promise<Actor.Info> => {
|
|||||||
}
|
}
|
||||||
const workspaceHint = splits[1]
|
const workspaceHint = splits[1]
|
||||||
const accounts = Object.keys(auth.data.account ?? {})
|
const accounts = Object.keys(auth.data.account ?? {})
|
||||||
|
if (accounts.length) {
|
||||||
const result = await Database.transaction(async (tx) => {
|
const result = await Database.transaction(async (tx) => {
|
||||||
return await tx
|
return await tx
|
||||||
.select({
|
.select({
|
||||||
@@ -75,5 +76,6 @@ export const getActor = query(async (): Promise<Actor.Info> => {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
throw redirect("/auth/authorize")
|
throw redirect("/auth/authorize")
|
||||||
}, "actor")
|
}
|
||||||
|
|||||||
@@ -1,16 +1,7 @@
|
|||||||
import { Actor } from "@opencode/cloud-core/actor.js"
|
import { Actor } from "@opencode/cloud-core/actor.js"
|
||||||
import { getActor } from "./auth"
|
import { getActor } from "./auth"
|
||||||
import { query } from "@solidjs/router"
|
|
||||||
|
|
||||||
export async function withActor<T>(fn: () => T) {
|
export async function withActor<T>(fn: () => T) {
|
||||||
const actor = await getActor()
|
const actor = await getActor()
|
||||||
return Actor.provide(actor.type, actor.properties, fn)
|
return Actor.provide(actor.type, actor.properties, fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function actorQuery<T>(cb: () => T, name: string) {
|
|
||||||
"use server"
|
|
||||||
return query(async () => {
|
|
||||||
const actor = await getActor()
|
|
||||||
return withActor(cb)
|
|
||||||
}, name)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { spawn } from "node:child_process"
|
import { spawn } from "node:child_process"
|
||||||
import { Config } from "./gen/types.gen.js"
|
import { type Config } from "./gen/types.gen.js"
|
||||||
|
|
||||||
export type ServerOptions = {
|
export type ServerOptions = {
|
||||||
hostname?: string
|
hostname?: string
|
||||||
|
|||||||
Reference in New Issue
Block a user