本帖最后由 linuke 于 2024-10-30 19:19 编辑
# Set-PSDebug -Trace 1
$headers = @{
"Accept" = "application/json"
"User-Agent" = "Mozilla/5.0 (Windows NT 10.0; Microsoft Windows 10.0.19044; en-US)"
"Accept-Encoding" = "gzip, deflate"
"Host" = "rubick.caocaokeji.cn"
"Connection" = "keep-alive"
}
function UploadFile {
param (
[string]$FilePath,
[string]$URL
)
PROCESS {
try {
$Form = @{
file = Get-Item -Path $FilePath
}
return Invoke-RestMethod -Method Post -Uri $URL -Headers $headers -Form $Form
}
catch {
# 处理其他类型的异常
Write-Host "An error occurred: $($_.Exception)"
return -1
}
}
}
# typora 自定义命令
# Then the command may return something like:
# Upload Success:
# http://remote-image-1.png
# http://remote-image-2.png
Write-Host "Upload Success:"
foreach ($file in $args) {
$url = 'https://rubick.caocaokeji.cn/{0}/upload' -f (2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22 | Get-Random)
$res = UploadFile -FilePath $file -URL $url
# Write-Host($res)
if (0 -ne $res.code) {
Write-Host ("{0} 上传失败:{1}" -f $file, $res )
return
}
Write-Host ("https://ccimgs.oss.aliyuncs.com/" + $res.data.file)
}```
|