minor fix to EventBus, and trim all preset form fields.

This commit is contained in:
ArabCoders 2025-03-23 00:22:33 +03:00
parent 706dba9205
commit c46aa1cfe4
3 changed files with 19 additions and 7 deletions

View file

@ -160,7 +160,7 @@ class Event:
id: str = field(default_factory=lambda: str(uuid.uuid4()), init=False) id: str = field(default_factory=lambda: str(uuid.uuid4()), init=False)
"""The id of the event.""" """The id of the event."""
created_at: str = field(default_factory=lambda: str(datetime.datetime.now(tz=datetime.timezone.utc).isoformat())) created_at: str = field(default_factory=lambda: str(datetime.datetime.now(tz=datetime.UTC).isoformat()))
"""The time the event was created.""" """The time the event was created."""
event: str event: str
@ -209,8 +209,8 @@ class EventListener:
async def handle(self, event: Event, **kwargs): async def handle(self, event: Event, **kwargs):
if self.is_coroutine: if self.is_coroutine:
return self.call_back(event, self.name, **kwargs) return self.call_back(event, self.name, **kwargs)
else:
return asyncio.create_task(self.call_back(event, self.name, **kwargs)) return asyncio.create_task(self.call_back(event, self.name, **kwargs))
class EventBus(metaclass=Singleton): class EventBus(metaclass=Singleton):

View file

@ -2,8 +2,9 @@ import asyncio
import json import json
import logging import logging
import os import os
from collections.abc import Awaitable
from dataclasses import dataclass, field from dataclasses import dataclass, field
from datetime import UTC, datetime from datetime import datetime
from typing import Any from typing import Any
import httpx import httpx
@ -11,7 +12,7 @@ from aiohttp import web
from .config import Config from .config import Config
from .encoder import Encoder from .encoder import Encoder
from .Events import EventBus, Event, Events from .Events import Event, EventBus, Events
from .ItemDTO import ItemDTO from .ItemDTO import ItemDTO
from .Singleton import Singleton from .Singleton import Singleton
from .Utils import ag, validate_uuid from .Utils import ag, validate_uuid
@ -323,7 +324,7 @@ class Notification(metaclass=Singleton):
return True return True
async def send(self, ev: Event) -> list[dict]: async def send(self, ev: Event, wait: bool = True) -> list[dict] | Awaitable[list[dict]]:
if len(self._targets) < 1: if len(self._targets) < 1:
return [] return []
@ -339,7 +340,10 @@ class Notification(metaclass=Singleton):
tasks.append(self._send(target, ev)) tasks.append(self._send(target, ev))
return await asyncio.gather(*tasks) if wait:
return await asyncio.gather(*tasks)
return tasks
async def _send(self, target: Target, ev: Event) -> dict: async def _send(self, target: Target, ev: Event) -> dict:
try: try:
@ -367,6 +371,7 @@ class Notification(metaclass=Singleton):
if "form" == target.request.type.lower(): if "form" == target.request.type.lower():
reqBody["data"]["data"] = self._encoder.encode(reqBody["data"]["data"]) reqBody["data"]["data"] = self._encoder.encode(reqBody["data"]["data"])
logging.getLogger("httpx").setLevel(logging.WARNING)
response = await self._client.request(**reqBody) response = await self._client.request(**reqBody)
respData = {"url": target.request.url, "status": response.status_code, "text": response.text} respData = {"url": target.request.url, "status": response.status_code, "text": response.text}

View file

@ -345,6 +345,13 @@ const checkInfo = async () => {
} }
} }
// trim all fields in copy only if they are strings
for (const key in copy) {
if (typeof copy[key] === 'string') {
copy[key] = copy[key].trim()
}
}
emitter('submit', { reference: toRaw(props.reference), preset: toRaw(copy) }); emitter('submit', { reference: toRaw(props.reference), preset: toRaw(copy) });
} }