Skip to content

Commit f562cf2

Browse files
[API Node] Workaround custom node hijack on api.queuePrompt (#3589)
Co-authored-by: filtered <[email protected]>
1 parent 4244a0a commit f562cf2

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/scripts/api.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,20 @@ export class ComfyApi extends EventTarget {
215215

216216
reportedUnknownMessageTypes = new Set<string>()
217217

218+
/**
219+
* The auth token for the comfy org account if the user is logged in.
220+
* This is only used for {@link queuePrompt} now. It is not directly
221+
* passed as parameter to the function because some custom nodes are hijacking
222+
* {@link queuePrompt} improperly, which causes extra parameters to be lost
223+
* in the function call chain.
224+
*
225+
* Ref: https://cs.comfy.org/search?q=context:global+%22api.queuePrompt+%3D%22&patternType=keyword&sm=0
226+
*
227+
* TODO: Move this field to parameter of {@link queuePrompt} once all
228+
* custom nodes are patched.
229+
*/
230+
authToken?: string
231+
218232
constructor() {
219233
super()
220234
this.user = ''
@@ -517,21 +531,19 @@ export class ComfyApi extends EventTarget {
517531
* Queues a prompt to be executed
518532
* @param {number} number The index at which to queue the prompt, passing -1 will insert the prompt at the front of the queue
519533
* @param {object} prompt The prompt data to queue
520-
* @param {string} authToken The auth token for the comfy org account if the user is logged in
521534
* @throws {PromptExecutionError} If the prompt fails to execute
522535
*/
523536
async queuePrompt(
524537
number: number,
525-
data: { output: ComfyApiWorkflow; workflow: ComfyWorkflowJSON },
526-
authToken?: string
538+
data: { output: ComfyApiWorkflow; workflow: ComfyWorkflowJSON }
527539
): Promise<PromptResponse> {
528540
const { output: prompt, workflow } = data
529541

530542
const body: QueuePromptRequestBody = {
531543
client_id: this.clientId ?? '', // TODO: Unify clientId access
532544
prompt,
533545
extra_data: {
534-
auth_token_comfy_org: authToken,
546+
auth_token_comfy_org: this.authToken,
535547
extra_pnginfo: { workflow }
536548
}
537549
}

src/scripts/app.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1208,7 +1208,9 @@ export class ComfyApp {
12081208

12091209
const p = await this.graphToPrompt()
12101210
try {
1211-
const res = await api.queuePrompt(number, p, comfyOrgAuthToken)
1211+
api.authToken = comfyOrgAuthToken
1212+
const res = await api.queuePrompt(number, p)
1213+
delete api.authToken
12121214
executionStore.lastNodeErrors = res.node_errors ?? null
12131215
if (executionStore.lastNodeErrors?.length) {
12141216
this.canvas.draw(true, true)

0 commit comments

Comments
 (0)