form reload update

This commit is contained in:
Michael Kret 2024-10-25 16:19:38 +03:00
parent 151f4dd7b8
commit af86c28063
3 changed files with 26 additions and 34 deletions

View file

@ -1,6 +1,5 @@
import axios from 'axios';
import type express from 'express'; import type express from 'express';
import { FORM_NODE_TYPE, sleep, Workflow } from 'n8n-workflow'; import { FORM_NODE_TYPE, Workflow } from 'n8n-workflow';
import { Service } from 'typedi'; import { Service } from 'typedi';
import { ConflictError } from '@/errors/response-errors/conflict.error'; import { ConflictError } from '@/errors/response-errors/conflict.error';
@ -38,25 +37,6 @@ export class WaitingForms extends WaitingWebhooks {
}); });
} }
private async reloadForm(req: WaitingWebhookRequest, res: express.Response) {
try {
await sleep(1000);
const url = `${req.protocol}://${req.get('host')}${req.originalUrl}`;
const page = await axios({ url });
if (page) {
res.send(`
<script>
setTimeout(function() {
window.location.reload();
}, 1);
</script>
`);
}
} catch (error) {}
}
async executeWebhook( async executeWebhook(
req: WaitingWebhookRequest, req: WaitingWebhookRequest,
res: express.Response, res: express.Response,
@ -82,7 +62,7 @@ export class WaitingForms extends WaitingWebhooks {
if (execution.status === 'running') { if (execution.status === 'running') {
if (this.includeForms && req.method === 'GET') { if (this.includeForms && req.method === 'GET') {
await this.reloadForm(req, res); await this.reloadForm(executionId, res);
return { noWebhookResponse: true }; return { noWebhookResponse: true };
} }

View file

@ -1,3 +1,4 @@
import axios from 'axios';
import type express from 'express'; import type express from 'express';
import { import {
FORM_NODE_TYPE, FORM_NODE_TYPE,
@ -5,6 +6,7 @@ import {
type IWorkflowBase, type IWorkflowBase,
NodeHelpers, NodeHelpers,
SEND_AND_WAIT_OPERATION, SEND_AND_WAIT_OPERATION,
sleep,
WAIT_NODE_TYPE, WAIT_NODE_TYPE,
Workflow, Workflow,
} from 'n8n-workflow'; } from 'n8n-workflow';
@ -17,6 +19,7 @@ import type { IExecutionResponse, IWorkflowDb } from '@/interfaces';
import { Logger } from '@/logging/logger.service'; import { Logger } from '@/logging/logger.service';
import { NodeTypes } from '@/node-types'; import { NodeTypes } from '@/node-types';
import * as WebhookHelpers from '@/webhooks/webhook-helpers'; import * as WebhookHelpers from '@/webhooks/webhook-helpers';
import { getBase } from '@/workflow-execute-additional-data';
import * as WorkflowExecuteAdditionalData from '@/workflow-execute-additional-data'; import * as WorkflowExecuteAdditionalData from '@/workflow-execute-additional-data';
import type { import type {
@ -80,6 +83,26 @@ export class WaitingWebhooks implements IWebhookManager {
}); });
} }
protected async reloadForm(executionId: string, res: express.Response) {
try {
await sleep(1000);
const { formWaitingBaseUrl } = await getBase();
const url = `${formWaitingBaseUrl}/${executionId}`;
const page = await axios({ url });
if (page) {
res.send(`
<script>
setTimeout(function() {
window.location.reload();
}, 1);
</script>
`);
}
} catch (error) {}
}
async executeWebhook( async executeWebhook(
req: WaitingWebhookRequest, req: WaitingWebhookRequest,
res: express.Response, res: express.Response,
@ -198,6 +221,7 @@ export class WaitingWebhooks implements IWebhookManager {
); );
if (hasChildForms) { if (hasChildForms) {
await this.reloadForm(executionId, res);
return { noWebhookResponse: true }; return { noWebhookResponse: true };
} }
} }

View file

@ -751,18 +751,6 @@
.catch(function (error) { .catch(function (error) {
console.error('Error:', error); console.error('Error:', error);
}); });
const isWaitingForm = window.location.href.includes('form-waiting');
if(isWaitingForm) {
const interval = setInterval(function() {
const isSubmited = document.querySelector('#submitted-form').style.display;
if(isSubmited === 'block') {
clearInterval(interval);
return;
}
window.location.reload();
}, 2000);
}
} }
}); });
</script> </script>