hi-server/test_agent_downloads.sh
2026-02-03 04:40:23 -08:00

77 lines
2.5 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 测试 OpenInstall Agent Downloads API
BASE_URL="https://tapi.hifast.biz"
API_PATH="/v1/public/user/agent/downloads"
echo "==============================================="
echo "测试 Agent Downloads API"
echo "==============================================="
# 如果您已经有 token请在这里设置
# 例如: TOKEN="your_jwt_token_here"
TOKEN=""
if [ -z "$TOKEN" ]; then
echo ""
echo "请提供用户 token 来测试此接口"
echo "您可以通过以下方式获取 token"
echo "1. 登录您的应用"
echo "2. 从浏览器开发者工具中复制 Authorization header 的 token"
echo ""
echo "或者使用邮箱/密码登录获取 token"
echo ""
read -p "请输入邮箱 (或直接按回车跳过): " EMAIL
if [ -n "$EMAIL" ]; then
read -sp "请输入密码: " PASSWORD
echo ""
# 尝试登录获取 token
LOGIN_RESPONSE=$(curl -s -X POST "${BASE_URL}/v1/auth/email/login" \
-H "Content-Type: application/json" \
-d "{\"email\":\"${EMAIL}\",\"password\":\"${PASSWORD}\"}")
echo "登录响应: $LOGIN_RESPONSE"
# 提取 token (需要 jq 工具,或者手动复制)
if command -v jq &> /dev/null; then
TOKEN=$(echo $LOGIN_RESPONSE | jq -r '.data.token // empty')
echo "提取到的 Token: $TOKEN"
else
echo "注意: 未安装 jq 工具,请手动从上面的响应中复制 token"
read -p "请粘贴 token: " TOKEN
fi
fi
fi
echo ""
echo "==============================================="
echo "调用 Agent Downloads API"
echo "==============================================="
if [ -z "$TOKEN" ]; then
echo "测试不带 token 的请求 (预期会失败)..."
curl -X GET "${BASE_URL}${API_PATH}" \
-H "Content-Type: application/json" \
-w "\n\nHTTP Status: %{http_code}\n"
else
echo "使用 Token 调用 API..."
curl -X GET "${BASE_URL}${API_PATH}" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${TOKEN}" \
-w "\n\nHTTP Status: %{http_code}\n"
fi
echo ""
echo "==============================================="
echo "当前 OpenInstall 配置:"
echo " Enable: true"
echo " AppKey: alf57p"
echo "==============================================="
echo ""
echo "注意: 当前 OpenInstall 集成使用的是 mock 数据"
echo "如需真实数据,需要实现 OpenInstall API 调用逻辑"
echo "文件位置: pkg/openinstall/openinstall.go"