| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- #!/bin/bash
- # Upload local attachments to backend for persistent storage
- # Usage: ./upload_attachments.sh <project_id> <access_token>
- PROJECT_ID=${1:-10}
- TOKEN=${2:-""}
- API_BASE="${API_SERVER:-http://47.108.80.98:8001}/api/v1"
- ATTACHMENTS_DIR="/home/hws/workspace/GitLab/ay/lingyue-zhibao/frontend/vue-demo/public/attachments"
- # Attachment files with display names
- declare -A FILES=(
- ["att01-核心要素评审情况记录表.docx"]="附件1 成都院核心要素评审情况记录表.docx"
- ["att02-现场评审分工表.zip"]="附件2 成都院现场评审分工表.zip"
- ["att03-安全生产标准化通知.pdf"]="附件3 安全生产标准化建设通知.pdf"
- ["att04-材料真实性说明.png"]="附件4 成都院材料真实性说明.png"
- ["att05-在建项目一览表.docx"]="附件5 成都院在建项目一览表.docx"
- ["att06-安全管理制度清单.docx"]="附件6 成都院安全管理制度清单.docx"
- ["att07-现场评审末次会签到表.png"]="附件7 成都院现场评审末次会签到表.png"
- ["att08-工作方案.zip"]="附件8 工作方案.zip"
- ["att09-复审问题建议表.docx"]="附件9 复审问题建议表.docx"
- )
- echo "Uploading attachments to project $PROJECT_ID..."
- echo "API Base: $API_BASE"
- echo ""
- for filename in "${!FILES[@]}"; do
- displayName="${FILES[$filename]}"
- filepath="$ATTACHMENTS_DIR/$filename"
-
- if [ ! -f "$filepath" ]; then
- echo "❌ File not found: $filepath"
- continue
- fi
-
- echo "📤 Uploading: $displayName"
-
- if [ -n "$TOKEN" ]; then
- response=$(curl -s -X POST "$API_BASE/projects/$PROJECT_ID/attachments/upload" \
- -H "Authorization: Bearer $TOKEN" \
- -F "file=@$filepath" \
- -F "displayName=$displayName")
- else
- response=$(curl -s -X POST "$API_BASE/projects/$PROJECT_ID/attachments/upload" \
- -F "file=@$filepath" \
- -F "displayName=$displayName")
- fi
-
- # Check response
- code=$(echo "$response" | grep -o '"code":[0-9]*' | head -1 | cut -d: -f2)
- if [ "$code" = "200" ]; then
- id=$(echo "$response" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2)
- echo " ✅ Success (id: $id)"
- else
- echo " ❌ Failed: $response"
- fi
- done
- echo ""
- echo "Done. Verifying attachments..."
- if [ -n "$TOKEN" ]; then
- curl -s "$API_BASE/projects/$PROJECT_ID/attachments" -H "Authorization: Bearer $TOKEN" | python3 -c "
- import sys, json
- try:
- data = json.load(sys.stdin)
- atts = data.get('data', [])
- print(f'Total attachments: {len(atts)}')
- for a in atts:
- print(f' - [{a.get(\"id\")}] {a.get(\"displayName\")} (fileKey: {a.get(\"fileKey\", \"N/A\")})')
- except Exception as e:
- print(f'Error parsing response: {e}')
- "
- else
- curl -s "$API_BASE/projects/$PROJECT_ID/attachments" | python3 -c "
- import sys, json
- try:
- data = json.load(sys.stdin)
- atts = data.get('data', [])
- print(f'Total attachments: {len(atts)}')
- for a in atts:
- print(f' - [{a.get(\"id\")}] {a.get(\"displayName\")} (fileKey: {a.get(\"fileKey\", \"N/A\")})')
- except Exception as e:
- print(f'Error parsing response: {e}')
- "
- fi
|