Revert "form reload update"

This reverts commit af86c28063.
This commit is contained in:
Michael Kret 2024-10-26 08:40:35 +03:00
parent 463ecb5cff
commit 7e0cd9d352
3 changed files with 34 additions and 26 deletions

View file

@ -1,5 +1,6 @@
import axios from 'axios';
import type express from 'express';
import { FORM_NODE_TYPE, Workflow } from 'n8n-workflow';
import { FORM_NODE_TYPE, sleep, Workflow } from 'n8n-workflow';
import { Service } from 'typedi';
import { ConflictError } from '@/errors/response-errors/conflict.error';
@ -37,6 +38,25 @@ 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(
req: WaitingWebhookRequest,
res: express.Response,
@ -62,7 +82,7 @@ export class WaitingForms extends WaitingWebhooks {
if (execution.status === 'running') {
if (this.includeForms && req.method === 'GET') {
await this.reloadForm(executionId, res);
await this.reloadForm(req, res);
return { noWebhookResponse: true };
}

View file

@ -1,4 +1,3 @@
import axios from 'axios';
import type express from 'express';
import {
FORM_NODE_TYPE,
@ -6,7 +5,6 @@ import {
type IWorkflowBase,
NodeHelpers,
SEND_AND_WAIT_OPERATION,
sleep,
WAIT_NODE_TYPE,
Workflow,
} from 'n8n-workflow';
@ -19,7 +17,6 @@ import type { IExecutionResponse, IWorkflowDb } from '@/interfaces';
import { Logger } from '@/logging/logger.service';
import { NodeTypes } from '@/node-types';
import * as WebhookHelpers from '@/webhooks/webhook-helpers';
import { getBase } from '@/workflow-execute-additional-data';
import * as WorkflowExecuteAdditionalData from '@/workflow-execute-additional-data';
import type {
@ -83,26 +80,6 @@ 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(
req: WaitingWebhookRequest,
res: express.Response,
@ -221,7 +198,6 @@ export class WaitingWebhooks implements IWebhookManager {
);
if (hasChildForms) {
await this.reloadForm(executionId, res);
return { noWebhookResponse: true };
}
}

View file

@ -751,6 +751,18 @@
.catch(function (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>