mirror of
https://github.com/insistence/RuoYi-Vue3-FastAPI.git
synced 2026-09-23 21:18:10 +00:00
* feat: 初始化插件系统 * refactor: 收口插件系统运行时重构 * perf: 优化插件系统类型提示 * fix&perf: 修复和优化插件系统 * fix: 修复gitignore规则误忽略插件文件的问题 * fix: 修复运行时插件根路径算错的问题 * fix: 加强插件发现和路由注册的防护措施 * revert: 回滚定时任务白名单 * fix: 移除未使用的应用路由注册探测 * revert: 恢复部分代码 * perf: 优化插件系统 * docs: 新增插件开发文档 * perf: 优化插件管理模块 * perf: 提升插件系统核心能力 * refactor: 重构生命周期 step runner * fix: 修复lint错误 * test: 清理测试用例 * test: 调整测试目录名称 * fix: 修复前后端目录硬编码的问题 * fix: 修复插件系统安全性缺口 * refactor: 重新设计插件生命周期 Migration 事务与回滚 * perf: 优化插件系统边界问题 * refactor: 重构当前插件系统的依赖体系设计 * perf: 优化代码 * perf: 优化代码 * fix: 修复代码合并问题 * fix: 修复bug * perf: 优化代码 * perf&fix: 优化代码和修复bug * docs: 优化文档格式 * feat: 适配Vue2版本 * docs: 更新README文档 * fix: 修复ruff lint错误 * chore: 更新后端依赖文件
115 lines
3.9 KiB
Python
115 lines
3.9 KiB
Python
import json
|
||
from pathlib import Path
|
||
from typing import Any
|
||
|
||
from cli.exit_codes import ARGUMENT_ERROR
|
||
|
||
|
||
class PluginCommandFileAdapter:
|
||
"""
|
||
插件命令文件导入导出适配器。
|
||
|
||
这些能力只服务 CLI 参数交互,不属于插件 core runtime。
|
||
"""
|
||
|
||
@classmethod
|
||
def write_markdown_file(
|
||
cls,
|
||
payload: dict[str, Any],
|
||
output_file: str,
|
||
*,
|
||
content_key: str,
|
||
failure_message: str,
|
||
) -> dict[str, Any]:
|
||
"""
|
||
写入 Markdown 文本文件。
|
||
|
||
:param payload: 原始命令负载
|
||
:param output_file: 输出文件路径
|
||
:param content_key: Markdown 内容字段名
|
||
:param failure_message: 写入失败提示前缀
|
||
:return: 附加导出结果后的命令负载
|
||
"""
|
||
return cls._write_text_file(
|
||
payload,
|
||
output_file,
|
||
content=str(payload.get(content_key, '')),
|
||
failure_message=failure_message,
|
||
)
|
||
|
||
@classmethod
|
||
def write_json_file(
|
||
cls,
|
||
payload: dict[str, Any],
|
||
output_file: str,
|
||
*,
|
||
failure_message: str,
|
||
) -> dict[str, Any]:
|
||
"""
|
||
写入 JSON 文件。
|
||
|
||
:param payload: 原始命令负载
|
||
:param output_file: 输出文件路径
|
||
:param failure_message: 写入失败提示前缀
|
||
:return: 附加导出结果后的命令负载
|
||
"""
|
||
content = json.dumps(payload, ensure_ascii=False, indent=2, default=str)
|
||
return cls._write_text_file(payload, output_file, content=content, failure_message=failure_message)
|
||
|
||
@staticmethod
|
||
def read_config_import_file(input_file: str) -> dict[str, Any]:
|
||
"""
|
||
读取插件配置导入 JSON 文件。
|
||
|
||
:param input_file: 配置导入 JSON 文件路径
|
||
:return: 配置导入负载
|
||
"""
|
||
if not input_file.strip():
|
||
return {'ok': False, 'message': '导入配置必须指定 --input-file', 'values': {}}
|
||
|
||
input_path = Path(input_file).expanduser().resolve()
|
||
try:
|
||
raw_payload = json.loads(input_path.read_text(encoding='utf-8'))
|
||
except (OSError, json.JSONDecodeError) as exc:
|
||
return {'ok': False, 'message': f'读取配置导入文件失败:{exc}', 'values': {}}
|
||
|
||
if not isinstance(raw_payload, dict):
|
||
return {'ok': False, 'message': '配置导入文件必须是 JSON 对象', 'values': {}}
|
||
values = raw_payload.get('values', raw_payload)
|
||
if not isinstance(values, dict):
|
||
return {'ok': False, 'message': '配置导入文件 values 必须是 JSON 对象', 'values': {}}
|
||
|
||
return {'ok': True, 'message': '配置导入文件读取完成', 'values': values}
|
||
|
||
@staticmethod
|
||
def _write_text_file(
|
||
payload: dict[str, Any],
|
||
output_file: str,
|
||
*,
|
||
content: str,
|
||
failure_message: str,
|
||
) -> dict[str, Any]:
|
||
"""
|
||
写入文本文件并补充导出状态。
|
||
|
||
:param payload: 原始命令负载
|
||
:param output_file: 输出文件路径
|
||
:param content: 文件内容
|
||
:param failure_message: 写入失败提示前缀
|
||
:return: 附加导出结果后的命令负载
|
||
"""
|
||
export_payload = dict(payload)
|
||
output_path = Path(output_file).expanduser().resolve()
|
||
try:
|
||
output_path.parent.mkdir(parents=True, exist_ok=True)
|
||
output_path.write_text(content, encoding='utf-8')
|
||
export_payload['outputFile'] = str(output_path)
|
||
export_payload['exported'] = True
|
||
except OSError as exc:
|
||
export_payload['ok'] = False
|
||
export_payload['message'] = f'{failure_message}:{exc}'
|
||
export_payload['outputFile'] = str(output_path)
|
||
export_payload['exported'] = False
|
||
export_payload['exit_code'] = ARGUMENT_ERROR
|
||
return export_payload
|