feat(api): 添加安全上传 Skill 和 COS 图片归一化
This commit is contained in:
44
scripts/package-upload-skill.ps1
Normal file
44
scripts/package-upload-skill.ps1
Normal file
@@ -0,0 +1,44 @@
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
$repositoryRoot = Split-Path -Parent $PSScriptRoot
|
||||
$skillName = 'upload-delivery-desk-work'
|
||||
$sourcePath = Join-Path $repositoryRoot ".agents\skills\$skillName"
|
||||
$packageDirectory = Join-Path $repositoryRoot 'skill-packages'
|
||||
$packagePath = Join-Path $packageDirectory "$skillName.zip"
|
||||
|
||||
if (-not (Test-Path -LiteralPath (Join-Path $sourcePath 'SKILL.md'))) {
|
||||
throw "Skill not found: $sourcePath"
|
||||
}
|
||||
|
||||
$previousNoBytecode = $env:PYTHONDONTWRITEBYTECODE
|
||||
try {
|
||||
$env:PYTHONDONTWRITEBYTECODE = '1'
|
||||
python (Join-Path $repositoryRoot 'tests\test_upload_skill.py')
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw 'Upload Skill regression tests failed.'
|
||||
}
|
||||
} finally {
|
||||
$env:PYTHONDONTWRITEBYTECODE = $previousNoBytecode
|
||||
}
|
||||
|
||||
$runtimeFiles = Get-ChildItem -LiteralPath $sourcePath -Recurse -Force | Where-Object {
|
||||
$_.Name -eq '__pycache__' -or $_.Extension -in @('.pyc', '.pyo')
|
||||
}
|
||||
if ($runtimeFiles) {
|
||||
throw 'Skill contains Python runtime cache. Remove it before packaging.'
|
||||
}
|
||||
|
||||
New-Item -ItemType Directory -Force -Path $packageDirectory | Out-Null
|
||||
if (Test-Path -LiteralPath $packagePath) {
|
||||
Remove-Item -LiteralPath $packagePath -Force
|
||||
}
|
||||
|
||||
Add-Type -AssemblyName System.IO.Compression.FileSystem
|
||||
[System.IO.Compression.ZipFile]::CreateFromDirectory(
|
||||
$sourcePath,
|
||||
$packagePath,
|
||||
[System.IO.Compression.CompressionLevel]::Optimal,
|
||||
$true
|
||||
)
|
||||
|
||||
Write-Output $packagePath
|
||||
Reference in New Issue
Block a user