wip: cloud
This commit is contained in:
@@ -18,12 +18,15 @@ 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")
|
||||||
|
if (evt.locals.actor) return evt.locals.actor
|
||||||
|
evt.locals.actor = (async () => {
|
||||||
|
console.log("getActor")
|
||||||
const url = new URL(evt.request.headers.has("x-server-id") ? evt.request.headers.get("referer")! : evt.request.url)
|
const url = new URL(evt.request.headers.has("x-server-id") ? evt.request.headers.get("referer")! : evt.request.url)
|
||||||
const auth = await useAuthSession()
|
const auth = await useAuthSession()
|
||||||
auth.data.account = auth.data.account ?? {}
|
|
||||||
const splits = url.pathname.split("/").filter(Boolean)
|
const splits = url.pathname.split("/").filter(Boolean)
|
||||||
if (splits[0] !== "workspace") {
|
if (splits[0] !== "workspace") {
|
||||||
const current = auth.data.account[auth.data.current ?? ""]
|
const account = auth.data.account ?? {}
|
||||||
|
const current = account[auth.data.current ?? ""]
|
||||||
if (current) {
|
if (current) {
|
||||||
return {
|
return {
|
||||||
type: "account",
|
type: "account",
|
||||||
@@ -33,8 +36,8 @@ export const getActor = async (): Promise<Actor.Info> => {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Object.keys(auth.data.account ?? {}).length > 0) {
|
if (Object.keys(account).length > 0) {
|
||||||
const current = Object.values(auth.data.account)[0]
|
const current = Object.values(account)[0]
|
||||||
await auth.update((val) => ({
|
await auth.update((val) => ({
|
||||||
...val,
|
...val,
|
||||||
current: current.id,
|
current: current.id,
|
||||||
@@ -79,4 +82,6 @@ export const getActor = async (): Promise<Actor.Info> => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw redirect("/auth/authorize")
|
throw redirect("/auth/authorize")
|
||||||
|
})()
|
||||||
|
return evt.locals.actor
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
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 { getRequestEvent } from "solid-js/web"
|
||||||
|
|
||||||
export async function withActor<T>(fn: () => T) {
|
export async function withActor<T>(fn: () => T) {
|
||||||
const actor = await getActor()
|
const actor = await getActor()
|
||||||
|
|||||||
@@ -42,12 +42,14 @@ const getBillingInfo = query(async () => {
|
|||||||
"use server"
|
"use server"
|
||||||
return withActor(async () => {
|
return withActor(async () => {
|
||||||
const actor = Actor.assert("user")
|
const actor = Actor.assert("user")
|
||||||
|
const now = Date.now()
|
||||||
const [user, billing, payments, usage] = await Promise.all([
|
const [user, billing, payments, usage] = await Promise.all([
|
||||||
User.fromID(actor.properties.userID),
|
User.fromID(actor.properties.userID),
|
||||||
Billing.get(),
|
Billing.get(),
|
||||||
Billing.payments(),
|
Billing.payments(),
|
||||||
Billing.usages(),
|
Billing.usages(),
|
||||||
])
|
])
|
||||||
|
console.log("duration", Date.now() - now)
|
||||||
return { user, billing, payments, usage }
|
return { user, billing, payments, usage }
|
||||||
})
|
})
|
||||||
}, "billingInfo")
|
}, "billingInfo")
|
||||||
@@ -67,9 +69,7 @@ export default function () {
|
|||||||
/////////////////
|
/////////////////
|
||||||
// Keys section
|
// Keys section
|
||||||
/////////////////
|
/////////////////
|
||||||
const keys = createAsync(() => listKeys(), {
|
const keys = createAsync(() => listKeys())
|
||||||
deferStream: true,
|
|
||||||
})
|
|
||||||
const createKeyAction = useAction(createKey)
|
const createKeyAction = useAction(createKey)
|
||||||
const removeKeyAction = useAction(removeKey)
|
const removeKeyAction = useAction(removeKey)
|
||||||
const createKeySubmission = useSubmission(createKey)
|
const createKeySubmission = useSubmission(createKey)
|
||||||
|
|||||||
Reference in New Issue
Block a user