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,27 +53,29 @@ 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 ?? {})
|
||||||
const result = await Database.transaction(async (tx) => {
|
if (accounts.length) {
|
||||||
return await tx
|
const result = await Database.transaction(async (tx) => {
|
||||||
.select({
|
return await tx
|
||||||
user: UserTable,
|
.select({
|
||||||
})
|
user: UserTable,
|
||||||
.from(AccountTable)
|
})
|
||||||
.innerJoin(UserTable, and(eq(UserTable.email, AccountTable.email)))
|
.from(AccountTable)
|
||||||
.innerJoin(WorkspaceTable, eq(WorkspaceTable.id, UserTable.workspaceID))
|
.innerJoin(UserTable, and(eq(UserTable.email, AccountTable.email)))
|
||||||
.where(and(inArray(AccountTable.id, accounts), eq(WorkspaceTable.id, workspaceHint)))
|
.innerJoin(WorkspaceTable, eq(WorkspaceTable.id, UserTable.workspaceID))
|
||||||
.limit(1)
|
.where(and(inArray(AccountTable.id, accounts), eq(WorkspaceTable.id, workspaceHint)))
|
||||||
.execute()
|
.limit(1)
|
||||||
.then((x) => x[0])
|
.execute()
|
||||||
})
|
.then((x) => x[0])
|
||||||
if (result) {
|
})
|
||||||
return {
|
if (result) {
|
||||||
type: "user",
|
return {
|
||||||
properties: {
|
type: "user",
|
||||||
userID: result.user.id,
|
properties: {
|
||||||
workspaceID: result.user.workspaceID,
|
userID: result.user.id,
|
||||||
},
|
workspaceID: result.user.workspaceID,
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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