HS Updates
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
||||
bareHolesailManagedRuntimeRunning,
|
||||
bareHolesailManagedServiceIsRunning,
|
||||
bareHolesailManagedStartOne,
|
||||
bareHolesailManagedStopOne,
|
||||
bareHolesailManagedWriteState
|
||||
} from './bare-holesail-managed.js'
|
||||
|
||||
@@ -22,6 +23,24 @@ export function bareOsWwwHolesailConnectionId(port) {
|
||||
return `${BARE_OS_WWW_HOLESAIL_CONNECTION_ID_PREFIX}${port}`
|
||||
}
|
||||
|
||||
/**
|
||||
* Pick one persisted WWW holesail entry to reuse and return any duplicates to prune.
|
||||
* @param {{ connections: Record<string, unknown> }} state
|
||||
* @param {number} port
|
||||
*/
|
||||
function bareOsWwwResolveManagedIdentity(state, port) {
|
||||
const exactId = bareOsWwwHolesailConnectionId(port)
|
||||
const allIds = Object.keys(state.connections).filter((id) =>
|
||||
id.startsWith(BARE_OS_WWW_HOLESAIL_CONNECTION_ID_PREFIX)
|
||||
)
|
||||
if (allIds.includes(exactId)) {
|
||||
return { id: exactId, staleIds: allIds.filter((id) => id !== exactId) }
|
||||
}
|
||||
if (allIds.length === 0) return { id: exactId, staleIds: [] }
|
||||
const idsSorted = allIds.sort()
|
||||
return { id: idsSorted[0], staleIds: idsSorted.slice(1) }
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Record<string, string | undefined>} env
|
||||
*/
|
||||
@@ -43,7 +62,6 @@ export async function ensureBareOsWwwHolesailTunnel(ctx, env, port) {
|
||||
Number.isFinite(port) && port > 0 && port < 65536
|
||||
? Math.floor(port)
|
||||
: 8088
|
||||
const id = bareOsWwwHolesailConnectionId(p)
|
||||
const vfs = ctx.vfs
|
||||
if (!vfs || typeof vfs.readFile !== 'function' || typeof vfs.writeFile !== 'function') {
|
||||
return
|
||||
@@ -54,6 +72,7 @@ export async function ensureBareOsWwwHolesailTunnel(ctx, env, port) {
|
||||
ctx,
|
||||
/** @type {Record<string, string | undefined>} */ (env)
|
||||
)
|
||||
const { id, staleIds } = bareOsWwwResolveManagedIdentity(state, p)
|
||||
/** Holesail server mode requires an explicit loopback host. */
|
||||
const wantHost = '127.0.0.1'
|
||||
/** @type {Record<string, unknown>} */
|
||||
@@ -108,6 +127,7 @@ export async function ensureBareOsWwwHolesailTunnel(ctx, env, port) {
|
||||
next.seed = bareHolesailManagedGenerateSeedHex()
|
||||
}
|
||||
state.connections[id] = next
|
||||
for (const staleId of staleIds) delete state.connections[staleId]
|
||||
await bareHolesailManagedWriteState(
|
||||
ctx,
|
||||
/** @type {Record<string, string | undefined>} */ (env),
|
||||
@@ -119,6 +139,15 @@ export async function ensureBareOsWwwHolesailTunnel(ctx, env, port) {
|
||||
id
|
||||
)
|
||||
void path
|
||||
for (const staleId of staleIds) {
|
||||
if (bareHolesailManagedRuntimeRunning(staleId)) {
|
||||
try {
|
||||
await bareHolesailManagedStopOne(ctx, staleId)
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
}
|
||||
}
|
||||
if (
|
||||
bareHolesailManagedServiceIsRunning() &&
|
||||
!bareHolesailManagedRuntimeRunning(id)
|
||||
|
||||
Reference in New Issue
Block a user