State -> Session
This commit is contained in:
parent
ef282e6df7
commit
acabf8c4c6
|
|
@ -4,7 +4,7 @@ import { join, extname } from "path"
|
|||
|
||||
import type { CommandOutput } from "app/src/shared/types"
|
||||
import { NOSE_WWW } from "app/src/config"
|
||||
import { getState } from "app/src/state"
|
||||
import { getState } from "@/session"
|
||||
import { appPath } from "app/src/webapp"
|
||||
import { isBinaryFile } from "app/src/utils"
|
||||
import { highlight } from "../lib/highlight"
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import { join, extname } from "path"
|
|||
|
||||
import type { CommandOutput } from "app/src/shared/types"
|
||||
import { NOSE_WWW } from "app/src/config"
|
||||
import { getState } from "app/src/state"
|
||||
import { getState } from "@/session"
|
||||
import { appPath } from "app/src/webapp"
|
||||
import { isBinaryFile } from "app/src/utils"
|
||||
import { countChar } from "app/src/shared/utils"
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { apps } from "app/src/webapp"
|
||||
import { getState } from "app/src/state"
|
||||
import { getState } from "@/session"
|
||||
|
||||
export default function (project: string) {
|
||||
const state = getState()
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { readdirSync } from "fs"
|
||||
import { NOSE_WWW } from "app/src/config"
|
||||
import { getState } from "app/src/state"
|
||||
import { getState } from "@/session"
|
||||
import { appPath } from "app/src/webapp"
|
||||
|
||||
export default function () {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { getState } from "app/src/state"
|
||||
import { getState } from "@/session"
|
||||
|
||||
export default function () {
|
||||
const state = getState()
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { apps } from "app/src/webapp"
|
||||
import { getState } from "app/src/state"
|
||||
import { getState } from "@/session"
|
||||
|
||||
export default function () {
|
||||
const state = getState()
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
import { AsyncLocalStorage } from "async_hooks"
|
||||
|
||||
export type State = {
|
||||
id?: string
|
||||
session?: string
|
||||
export type Session = {
|
||||
taskId?: string
|
||||
sessionId?: string
|
||||
project?: string
|
||||
}
|
||||
|
||||
// Ensure "ALS" lives between bun's hot reloads
|
||||
const g = globalThis as typeof globalThis & { __thread?: AsyncLocalStorage<State> }
|
||||
export const ALS = g.__thread ??= new AsyncLocalStorage<State>()
|
||||
const g = globalThis as typeof globalThis & { __thread?: AsyncLocalStorage<Session> }
|
||||
export const ALS = g.__thread ??= new AsyncLocalStorage<Session>()
|
||||
|
||||
export function getState(): State | undefined {
|
||||
export function getState(): Session | undefined {
|
||||
return ALS.getStore()
|
||||
}
|
||||
|
|
@ -3,12 +3,12 @@
|
|||
|
||||
import { join } from "path"
|
||||
import type { CommandResult, CommandOutput } from "./shared/types"
|
||||
import type { State } from "./state"
|
||||
import type { Session } from "./session"
|
||||
import { NOSE_SYS_BIN, NOSE_BIN } from "./config"
|
||||
import { isFile } from "./utils"
|
||||
import { ALS } from "./state"
|
||||
import { ALS } from "./session"
|
||||
|
||||
const sessions: Map<string, State> = new Map()
|
||||
const sessions: Map<string, Session> = new Map()
|
||||
|
||||
export async function runCommand(session: string, id: string, input: string): Promise<CommandResult> {
|
||||
const [cmd = "", ...args] = input.split(" ")
|
||||
|
|
@ -56,13 +56,13 @@ function processExecOutput(output: string | any): ["ok" | "error", CommandOutput
|
|||
}
|
||||
}
|
||||
|
||||
function getState(session: string, id: string): State {
|
||||
let state = sessions.get(session)
|
||||
function getState(sessionId: string, taskId: string): Session {
|
||||
let state = sessions.get(sessionId)
|
||||
if (!state) {
|
||||
state = { session, project: "" }
|
||||
sessions.set(session, state)
|
||||
state = { sessionId: sessionId, project: "" }
|
||||
sessions.set(sessionId, state)
|
||||
}
|
||||
state.id = id
|
||||
state.taskId = taskId
|
||||
return state
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user