Merge branch 'fix/chore-fix' into dev/plugin-deploy
parent
cc28dafede
commit
59b76900d7
@ -1,7 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<svg width="800px" height="800px" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
||||
<g>
|
||||
<path fill="none" d="M0 0h24v24H0z"/>
|
||||
<path d="M16 17v-1h-3v-3h3v2h2v2h-1v2h-2v2h-2v-3h2v-1h1zm5 4h-4v-2h2v-2h2v4zM3 3h8v8H3V3zm2 2v4h4V5H5zm8-2h8v8h-8V3zm2 2v4h4V5h-4zM3 13h8v8H3v-8zm2 2v4h4v-4H5zm13-2h3v2h-3v-2zM6 6h2v2H6V6zm0 10h2v2H6v-2zM16 6h2v2h-2V6z"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 428 B |
@ -1,8 +0,0 @@
|
||||
from typing import Any
|
||||
|
||||
from core.tools.builtin_tool.provider import BuiltinToolProviderController
|
||||
|
||||
|
||||
class QRCodeProvider(BuiltinToolProviderController):
|
||||
def _validate_credentials(self, user_id: str, credentials: dict[str, Any]) -> None:
|
||||
pass
|
||||
@ -1,14 +0,0 @@
|
||||
identity:
|
||||
author: Bowen Liang
|
||||
name: qrcode
|
||||
label:
|
||||
en_US: QRCode
|
||||
zh_Hans: 二维码工具
|
||||
pt_BR: QRCode
|
||||
description:
|
||||
en_US: A tool for generating QR code (quick-response code) image.
|
||||
zh_Hans: 一个二维码工具
|
||||
pt_BR: A tool for generating QR code (quick-response code) image.
|
||||
icon: icon.svg
|
||||
tags:
|
||||
- utilities
|
||||
@ -1,70 +0,0 @@
|
||||
import io
|
||||
import logging
|
||||
from typing import Any, Union
|
||||
|
||||
from qrcode.constants import ERROR_CORRECT_H, ERROR_CORRECT_L, ERROR_CORRECT_M, ERROR_CORRECT_Q
|
||||
from qrcode.image.base import BaseImage
|
||||
from qrcode.image.pure import PyPNGImage
|
||||
from qrcode.main import QRCode
|
||||
|
||||
from core.tools.builtin_tool.tool import BuiltinTool
|
||||
from core.tools.entities.tool_entities import ToolInvokeMessage
|
||||
|
||||
|
||||
class QRCodeGeneratorTool(BuiltinTool):
|
||||
error_correction_levels: dict[str, int] = {
|
||||
"L": ERROR_CORRECT_L, # <=7%
|
||||
"M": ERROR_CORRECT_M, # <=15%
|
||||
"Q": ERROR_CORRECT_Q, # <=25%
|
||||
"H": ERROR_CORRECT_H, # <=30%
|
||||
}
|
||||
|
||||
def _invoke(
|
||||
self,
|
||||
user_id: str,
|
||||
tool_parameters: dict[str, Any],
|
||||
) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]:
|
||||
"""
|
||||
invoke tools
|
||||
"""
|
||||
# get text content
|
||||
content = tool_parameters.get("content", "")
|
||||
if not content:
|
||||
return self.create_text_message("Invalid parameter content")
|
||||
|
||||
# get border size
|
||||
border = tool_parameters.get("border", 0)
|
||||
if border < 0 or border > 100:
|
||||
return self.create_text_message("Invalid parameter border")
|
||||
|
||||
# get error_correction
|
||||
error_correction = tool_parameters.get("error_correction", "")
|
||||
if error_correction not in self.error_correction_levels:
|
||||
return self.create_text_message("Invalid parameter error_correction")
|
||||
|
||||
try:
|
||||
image = self._generate_qrcode(content, border, error_correction)
|
||||
image_bytes = self._image_to_byte_array(image)
|
||||
return self.create_blob_message(
|
||||
blob=image_bytes, meta={"mime_type": "image/png"}, save_as=self.VariableKey.IMAGE.value
|
||||
)
|
||||
except Exception:
|
||||
logging.exception(f"Failed to generate QR code for content: {content}")
|
||||
return self.create_text_message("Failed to generate QR code")
|
||||
|
||||
def _generate_qrcode(self, content: str, border: int, error_correction: str) -> BaseImage:
|
||||
qr = QRCode(
|
||||
image_factory=PyPNGImage,
|
||||
error_correction=self.error_correction_levels.get(error_correction),
|
||||
border=border,
|
||||
)
|
||||
qr.add_data(data=content)
|
||||
qr.make(fit=True)
|
||||
img = qr.make_image()
|
||||
return img
|
||||
|
||||
@staticmethod
|
||||
def _image_to_byte_array(image: BaseImage) -> bytes:
|
||||
byte_stream = io.BytesIO()
|
||||
image.save(byte_stream)
|
||||
return byte_stream.getvalue()
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue