upload_attachments.sh 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/bin/bash
  2. # Upload local attachments to backend for persistent storage
  3. # Usage: ./upload_attachments.sh <project_id> <access_token>
  4. PROJECT_ID=${1:-10}
  5. TOKEN=${2:-""}
  6. API_BASE="${API_SERVER:-http://47.108.80.98:8001}/api/v1"
  7. ATTACHMENTS_DIR="/home/hws/workspace/GitLab/ay/lingyue-zhibao/frontend/vue-demo/public/attachments"
  8. # Attachment files with display names
  9. declare -A FILES=(
  10. ["att01-核心要素评审情况记录表.docx"]="附件1 成都院核心要素评审情况记录表.docx"
  11. ["att02-现场评审分工表.zip"]="附件2 成都院现场评审分工表.zip"
  12. ["att03-安全生产标准化通知.pdf"]="附件3 安全生产标准化建设通知.pdf"
  13. ["att04-材料真实性说明.png"]="附件4 成都院材料真实性说明.png"
  14. ["att05-在建项目一览表.docx"]="附件5 成都院在建项目一览表.docx"
  15. ["att06-安全管理制度清单.docx"]="附件6 成都院安全管理制度清单.docx"
  16. ["att07-现场评审末次会签到表.png"]="附件7 成都院现场评审末次会签到表.png"
  17. ["att08-工作方案.zip"]="附件8 工作方案.zip"
  18. ["att09-复审问题建议表.docx"]="附件9 复审问题建议表.docx"
  19. )
  20. echo "Uploading attachments to project $PROJECT_ID..."
  21. echo "API Base: $API_BASE"
  22. echo ""
  23. for filename in "${!FILES[@]}"; do
  24. displayName="${FILES[$filename]}"
  25. filepath="$ATTACHMENTS_DIR/$filename"
  26. if [ ! -f "$filepath" ]; then
  27. echo "❌ File not found: $filepath"
  28. continue
  29. fi
  30. echo "📤 Uploading: $displayName"
  31. if [ -n "$TOKEN" ]; then
  32. response=$(curl -s -X POST "$API_BASE/projects/$PROJECT_ID/attachments/upload" \
  33. -H "Authorization: Bearer $TOKEN" \
  34. -F "file=@$filepath" \
  35. -F "displayName=$displayName")
  36. else
  37. response=$(curl -s -X POST "$API_BASE/projects/$PROJECT_ID/attachments/upload" \
  38. -F "file=@$filepath" \
  39. -F "displayName=$displayName")
  40. fi
  41. # Check response
  42. code=$(echo "$response" | grep -o '"code":[0-9]*' | head -1 | cut -d: -f2)
  43. if [ "$code" = "200" ]; then
  44. id=$(echo "$response" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2)
  45. echo " ✅ Success (id: $id)"
  46. else
  47. echo " ❌ Failed: $response"
  48. fi
  49. done
  50. echo ""
  51. echo "Done. Verifying attachments..."
  52. if [ -n "$TOKEN" ]; then
  53. curl -s "$API_BASE/projects/$PROJECT_ID/attachments" -H "Authorization: Bearer $TOKEN" | python3 -c "
  54. import sys, json
  55. try:
  56. data = json.load(sys.stdin)
  57. atts = data.get('data', [])
  58. print(f'Total attachments: {len(atts)}')
  59. for a in atts:
  60. print(f' - [{a.get(\"id\")}] {a.get(\"displayName\")} (fileKey: {a.get(\"fileKey\", \"N/A\")})')
  61. except Exception as e:
  62. print(f'Error parsing response: {e}')
  63. "
  64. else
  65. curl -s "$API_BASE/projects/$PROJECT_ID/attachments" | python3 -c "
  66. import sys, json
  67. try:
  68. data = json.load(sys.stdin)
  69. atts = data.get('data', [])
  70. print(f'Total attachments: {len(atts)}')
  71. for a in atts:
  72. print(f' - [{a.get(\"id\")}] {a.get(\"displayName\")} (fileKey: {a.get(\"fileKey\", \"N/A\")})')
  73. except Exception as e:
  74. print(f'Error parsing response: {e}')
  75. "
  76. fi