mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-30 03:01:54 +00:00
Remove uneeded inflight coalescing
This commit is contained in:
@@ -2,15 +2,6 @@ import { api } from '@/scripts/api'
|
|||||||
import { isCloud } from '@/platform/distribution/types'
|
import { isCloud } from '@/platform/distribution/types'
|
||||||
import { useFirebaseAuthStore } from '@/stores/firebaseAuthStore'
|
import { useFirebaseAuthStore } from '@/stores/firebaseAuthStore'
|
||||||
|
|
||||||
/**
|
|
||||||
* Tracks the in-flight createSession request to dedupe concurrent calls.
|
|
||||||
*/
|
|
||||||
let createSessionInFlight: Promise<void> | null = null
|
|
||||||
/**
|
|
||||||
* Tracks the in-flight deleteSession request to dedupe concurrent calls.
|
|
||||||
*/
|
|
||||||
let deleteSessionInFlight: Promise<void> | null = null
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Session cookie management for cloud authentication.
|
* Session cookie management for cloud authentication.
|
||||||
* Creates and deletes session cookies on the ComfyUI server.
|
* Creates and deletes session cookies on the ComfyUI server.
|
||||||
@@ -23,40 +14,27 @@ export const useSessionCookie = () => {
|
|||||||
const createSession = async (): Promise<void> => {
|
const createSession = async (): Promise<void> => {
|
||||||
if (!isCloud) return
|
if (!isCloud) return
|
||||||
|
|
||||||
if (createSessionInFlight) {
|
const authStore = useFirebaseAuthStore()
|
||||||
await createSessionInFlight
|
const authHeader = await authStore.getAuthHeader()
|
||||||
return
|
|
||||||
|
if (!authHeader) {
|
||||||
|
throw new Error('No auth header available for session creation')
|
||||||
}
|
}
|
||||||
|
|
||||||
createSessionInFlight = (async () => {
|
const response = await fetch(api.apiURL('/auth/session'), {
|
||||||
const authStore = useFirebaseAuthStore()
|
method: 'POST',
|
||||||
const authHeader = await authStore.getAuthHeader()
|
credentials: 'include',
|
||||||
|
headers: {
|
||||||
if (!authHeader) {
|
...authHeader,
|
||||||
throw new Error('No auth header available for session creation')
|
'Content-Type': 'application/json'
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
|
||||||
const response = await fetch(api.apiURL('/auth/session'), {
|
if (!response.ok) {
|
||||||
method: 'POST',
|
const errorData = await response.json().catch(() => ({}))
|
||||||
credentials: 'include',
|
throw new Error(
|
||||||
headers: {
|
`Failed to create session: ${errorData.message || response.statusText}`
|
||||||
...authHeader,
|
)
|
||||||
'Content-Type': 'application/json'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
const errorData = await response.json().catch(() => ({}))
|
|
||||||
throw new Error(
|
|
||||||
`Failed to create session: ${errorData.message || response.statusText}`
|
|
||||||
)
|
|
||||||
}
|
|
||||||
})()
|
|
||||||
|
|
||||||
try {
|
|
||||||
await createSessionInFlight
|
|
||||||
} finally {
|
|
||||||
createSessionInFlight = null
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,29 +45,16 @@ export const useSessionCookie = () => {
|
|||||||
const deleteSession = async (): Promise<void> => {
|
const deleteSession = async (): Promise<void> => {
|
||||||
if (!isCloud) return
|
if (!isCloud) return
|
||||||
|
|
||||||
if (deleteSessionInFlight) {
|
const response = await fetch(api.apiURL('/auth/session'), {
|
||||||
await deleteSessionInFlight
|
method: 'DELETE',
|
||||||
return
|
credentials: 'include'
|
||||||
}
|
})
|
||||||
|
|
||||||
deleteSessionInFlight = (async () => {
|
if (!response.ok) {
|
||||||
const response = await fetch(api.apiURL('/auth/session'), {
|
const errorData = await response.json().catch(() => ({}))
|
||||||
method: 'DELETE',
|
throw new Error(
|
||||||
credentials: 'include'
|
`Failed to delete session: ${errorData.message || response.statusText}`
|
||||||
})
|
)
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
const errorData = await response.json().catch(() => ({}))
|
|
||||||
throw new Error(
|
|
||||||
`Failed to delete session: ${errorData.message || response.statusText}`
|
|
||||||
)
|
|
||||||
}
|
|
||||||
})()
|
|
||||||
|
|
||||||
try {
|
|
||||||
await deleteSessionInFlight
|
|
||||||
} finally {
|
|
||||||
deleteSessionInFlight = null
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user