完善在线工具、插件运行时与安装卸载流程

This commit is contained in:
2026-08-19 16:15:52 +08:00
parent 80093f285e
commit 7a2af2646c
366 changed files with 6683 additions and 490 deletions
+54 -9
View File
@@ -5,6 +5,7 @@
$ErrorActionPreference = 'Stop'
$catalogPath = Join-Path $Root 'src\YMhut.Box.Core\Tools\ToolCatalog.cs'
$pearCatalogPath = Join-Path $Root 'src\YMhut.Box.Core\Api\PearApiCatalog.cs'
$nexPath = Join-Path $Root 'src\YMhut.Box.Core\Tools\NexNativeTools.cs'
$outputRoot = Join-Path $Root 'assets\data\tool-ui'
New-Item -ItemType Directory -Force -Path $outputRoot | Out-Null
@@ -32,6 +33,35 @@ foreach ($line in ($rawMatch.Groups['data'].Value -split "`r?`n")) {
}
}
$pearPattern = 'D\("(?<id>[^"]+)",\s*(?<apiId>\d+),\s*"(?<name>[^"]+)",\s*"(?<description>[^"]*)",\s*"(?<category>[^"]+)",\s*"(?<path>[^"]+)",\s*PearApiRequestMethod\.(?<method>\w+),\s*PearApiPrivacyClass\.(?<privacy>\w+),\s*PearApiResultKind\.(?<result>\w+)'
foreach ($line in (Get-Content -LiteralPath $pearCatalogPath -Encoding UTF8)) {
$match = [regex]::Match($line, $pearPattern)
if (-not $match.Success) { continue }
$id = $match.Groups['id'].Value
[void]$ids.Add($id)
$metadata[$id] = [ordered]@{
zh = $match.Groups['name'].Value
en = $match.Groups['name'].Value
descriptionZh = $match.Groups['description'].Value
descriptionEn = $match.Groups['description'].Value
category = 'network'
offline = $false
pear = $true
pearCategory = $match.Groups['category'].Value
privacy = $match.Groups['privacy'].Value
result = $match.Groups['result'].Value
apiId = $match.Groups['apiId'].Value
}
}
foreach ($alias in @{ baidu_hot = '百度'; bili_hot = '哔哩哔哩'; zhihu_hot = '知乎' }.GetEnumerator()) {
if (-not $metadata.ContainsKey($alias.Key)) { continue }
$metadata[$alias.Key].pear = $true
$metadata[$alias.Key].pearCategory = '网络'
$metadata[$alias.Key].privacy = 'Public'
$metadata[$alias.Key].result = 'RankedList'
$metadata[$alias.Key].apiId = '141'
}
foreach ($match in [regex]::Matches((Get-Content -LiteralPath $nexPath -Raw -Encoding UTF8), 'Tool\("(?<id>[^"]+)"')) {
$id = $match.Groups['id'].Value
[void]$ids.Add($id)
@@ -59,7 +89,13 @@ try {
$meta = $metadata[$id]
$category = [string]$meta.category
$risk = if ($category -in @('security', 'system', 'plugin', 'external')) { 'high' } else { 'normal' }
$primaryKind = switch ($category) {
$primaryKind = if ($meta.pear) {
switch ([string]$meta.privacy) {
'Public' { 'Output'; break }
'FileUpload' { 'FilePicker'; break }
default { 'Query' }
}
} else { switch ($category) {
'image' { 'FilePicker'; break }
'calculator' { 'Number'; break }
'network' { 'Query'; break }
@@ -69,12 +105,12 @@ try {
'plugin' { 'WebView'; break }
'external' { 'ExternalSurface'; break }
default { 'Text' }
}
} }
$maxLength = 4096
if ($category -eq 'text' -or $category -eq 'dev' -or $category -eq 'security') { $maxLength = 200000 }
$placeholder = '输入此工具所需的值'
if ($category -eq 'network') { $placeholder = '关键词、URL、域名或 IP' }
if ($category -eq 'network') { $placeholder = '按此接口页面的字段填写查询条件' }
$primaryControls = [Collections.Generic.List[object]]::new()
$primaryControls.Add([ordered]@{
id = 'primary'
@@ -88,7 +124,9 @@ try {
})
$sections = [Collections.Generic.List[object]]::new()
$primaryTitle = switch ($category) {
$primaryTitle = if ($meta.pear) {
[ordered]@{ zh = "PearAPI · $([string]$meta.pearCategory)"; en = "PearAPI · $([string]$meta.pearCategory)" }
} else { switch ($category) {
'calculator' { [ordered]@{ zh = '计算参数'; en = 'Calculation parameters' } }
'network' { [ordered]@{ zh = '查询条件'; en = 'Query criteria' } }
'image' { [ordered]@{ zh = '文件与媒体'; en = 'Files and media' } }
@@ -99,14 +137,14 @@ try {
'plugin' { [ordered]@{ zh = '插件安全容器'; en = 'Plugin security container' } }
'external' { [ordered]@{ zh = '外部程序运行'; en = 'External program launch' } }
default { [ordered]@{ zh = '主要操作'; en = 'Primary operation' } }
}
} }
if ($category -eq 'calculator') {
$primaryControls.Clear()
foreach ($numberId in @('number-primary', 'number-secondary', 'number-third', 'number-fourth')) {
$primaryControls.Add([ordered]@{ id = $numberId; kind = 'Number'; label = [ordered]@{ zh = '数值参数'; en = 'Numeric parameter' }; defaultValue = '1'; required = $true; isReadOnly = $false; validation = [ordered]@{ minimum = -100000000; maximum = 100000000 } })
}
} elseif ($category -eq 'network') {
} elseif ($category -eq 'network' -and -not $meta.pear) {
$primaryControls.Add([ordered]@{ id = 'parameter'; kind = 'ComboBox'; label = [ordered]@{ zh = '来源或分类'; en = 'Source or category' }; defaultValue = ''; required = $false; isReadOnly = $false })
} elseif ($category -eq 'image') {
$primaryControls.Add([ordered]@{ id = 'file'; kind = 'FilePicker'; label = [ordered]@{ zh = '文件'; en = 'File' }; placeholder = '选择本地文件'; defaultValue = ''; required = $false; isReadOnly = $false })
@@ -121,7 +159,7 @@ try {
layout = $(if ($category -eq 'calculator') { 'grid' } else { 'stack' })
})
if ($category -in @('text', 'dev', 'security', 'network', 'design')) {
if (-not $meta.pear -and $category -in @('text', 'dev', 'security', 'network', 'design')) {
$advancedControls = [Collections.Generic.List[object]]::new()
if ($category -in @('text', 'dev', 'security')) {
$advancedControls.Add([ordered]@{ id = 'rules'; kind = 'ComboBox'; label = [ordered]@{ zh = '处理规则'; en = 'Processing rules' }; defaultValue = ''; required = $false; isReadOnly = $false })
@@ -142,7 +180,9 @@ try {
})
}
$resultKind = switch ($category) {
$resultKind = if ($meta.pear) {
"pear-$(([string]$meta.result).ToLowerInvariant())"
} else { switch ($category) {
'calculator' { 'calculator-table' }
'image' { 'image-preview' }
'data' { 'ranked-list' }
@@ -153,7 +193,7 @@ try {
'plugin' { 'status-list' }
'external' { 'status-list' }
default { 'text' }
}
} }
$actions = [Collections.Generic.List[object]]::new()
$actionLabel = switch ($category) {
'calculator' { [ordered]@{ zh = '计算'; en = 'Calculate' } }
@@ -217,5 +257,10 @@ try {
} finally {
$aes.Dispose()
}
foreach ($stale in Get-ChildItem -LiteralPath $outputRoot -Filter '*.dat' -File -ErrorAction SilentlyContinue) {
if (-not $ids.Contains($stale.BaseName)) {
Remove-Item -LiteralPath $stale.FullName -Force
}
}
Write-Host "Generated $($ids.Count) tool UI definitions in $outputRoot"