mirror of
https://github.com/aljazceru/opencode.git
synced 2026-02-23 16:54:27 +01:00
wip: zen
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { getRequestEvent } from "solid-js/web"
|
import { getRequestEvent } from "solid-js/web"
|
||||||
import { and, Database, eq, inArray, sql } from "@opencode-ai/console-core/drizzle/index.js"
|
import { and, Database, eq, inArray, isNull, sql } from "@opencode-ai/console-core/drizzle/index.js"
|
||||||
import { UserTable } from "@opencode-ai/console-core/schema/user.sql.js"
|
import { UserTable } from "@opencode-ai/console-core/schema/user.sql.js"
|
||||||
import { redirect } from "@solidjs/router"
|
import { redirect } from "@solidjs/router"
|
||||||
import { Actor } from "@opencode-ai/console-core/actor.js"
|
import { Actor } from "@opencode-ai/console-core/actor.js"
|
||||||
@@ -56,7 +56,13 @@ export const getActor = async (workspace?: string): Promise<Actor.Info> => {
|
|||||||
tx
|
tx
|
||||||
.select()
|
.select()
|
||||||
.from(UserTable)
|
.from(UserTable)
|
||||||
.where(and(eq(UserTable.workspaceID, workspace), inArray(UserTable.accountID, accounts)))
|
.where(
|
||||||
|
and(
|
||||||
|
eq(UserTable.workspaceID, workspace),
|
||||||
|
isNull(UserTable.timeDeleted),
|
||||||
|
inArray(UserTable.accountID, accounts),
|
||||||
|
),
|
||||||
|
)
|
||||||
.limit(1)
|
.limit(1)
|
||||||
.execute()
|
.execute()
|
||||||
.then((x) => x[0]),
|
.then((x) => x[0]),
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Actor } from "@opencode-ai/console-core/actor.js"
|
import { Actor } from "@opencode-ai/console-core/actor.js"
|
||||||
import { and, Database, eq, isNull } from "@opencode-ai/console-core/drizzle/index.js"
|
import { and, Database, desc, eq, isNull } from "@opencode-ai/console-core/drizzle/index.js"
|
||||||
import { UserTable } from "@opencode-ai/console-core/schema/user.sql.js"
|
import { UserTable } from "@opencode-ai/console-core/schema/user.sql.js"
|
||||||
import { WorkspaceTable } from "@opencode-ai/console-core/schema/workspace.sql.js"
|
import { WorkspaceTable } from "@opencode-ai/console-core/schema/workspace.sql.js"
|
||||||
import { redirect } from "@solidjs/router"
|
import { redirect } from "@solidjs/router"
|
||||||
@@ -8,7 +8,7 @@ import { withActor } from "~/context/auth.withActor"
|
|||||||
|
|
||||||
export async function GET(input: APIEvent) {
|
export async function GET(input: APIEvent) {
|
||||||
try {
|
try {
|
||||||
const workspaces = await withActor(async () => {
|
const workspaceID = await withActor(async () => {
|
||||||
const actor = Actor.assert("account")
|
const actor = Actor.assert("account")
|
||||||
return Database.transaction(async (tx) =>
|
return Database.transaction(async (tx) =>
|
||||||
tx
|
tx
|
||||||
@@ -21,10 +21,13 @@ export async function GET(input: APIEvent) {
|
|||||||
isNull(UserTable.timeDeleted),
|
isNull(UserTable.timeDeleted),
|
||||||
isNull(WorkspaceTable.timeDeleted),
|
isNull(WorkspaceTable.timeDeleted),
|
||||||
),
|
),
|
||||||
),
|
)
|
||||||
|
.orderBy(desc(UserTable.timeSeen))
|
||||||
|
.limit(1)
|
||||||
|
.then((x) => x[0]?.id),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
return redirect(`/workspace/${workspaces[0].id}`)
|
return redirect(`/workspace/${workspaceID}`)
|
||||||
} catch {
|
} catch {
|
||||||
return redirect("/auth/authorize")
|
return redirect("/auth/authorize")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,13 @@ const getWorkspaces = query(async () => {
|
|||||||
})
|
})
|
||||||
.from(UserTable)
|
.from(UserTable)
|
||||||
.innerJoin(WorkspaceTable, eq(UserTable.workspaceID, WorkspaceTable.id))
|
.innerJoin(WorkspaceTable, eq(UserTable.workspaceID, WorkspaceTable.id))
|
||||||
.where(and(eq(UserTable.accountID, Actor.account()), isNull(WorkspaceTable.timeDeleted))),
|
.where(
|
||||||
|
and(
|
||||||
|
eq(UserTable.accountID, Actor.account()),
|
||||||
|
isNull(WorkspaceTable.timeDeleted),
|
||||||
|
isNull(UserTable.timeDeleted),
|
||||||
|
),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
}, "workspaces")
|
}, "workspaces")
|
||||||
|
|||||||
Reference in New Issue
Block a user