174 lines
4.2 KiB
Bash
Executable file
174 lines
4.2 KiB
Bash
Executable file
#!/bin/bash
|
|
# Upload all stock avatar props to the server.
|
|
#
|
|
# Usage: ./stockavatar/upload-stockavatars.sh [--force|-f] [HOST]
|
|
#
|
|
# Options:
|
|
# --force, -f Update existing props instead of failing with 409 Conflict
|
|
#
|
|
# HOST defaults to http://localhost:3001 (owner admin port)
|
|
#
|
|
# Prerequisites:
|
|
# 1. Run the dev server: ./run-dev.sh -f
|
|
# 2. Wait for it to finish building: ./run-dev.sh -s
|
|
#
|
|
# The owner admin server (port 3001) uses the chattyness_owner DB role
|
|
# which bypasses RLS, so no authentication is required.
|
|
|
|
set -e
|
|
|
|
# Parse arguments
|
|
FORCE=""
|
|
HOST="http://localhost:3001"
|
|
|
|
for arg in "$@"; do
|
|
case "$arg" in
|
|
--force|-f)
|
|
FORCE="?force=true"
|
|
;;
|
|
http://*)
|
|
HOST="$arg"
|
|
;;
|
|
esac
|
|
done
|
|
# Script directory is the stockavatar directory
|
|
STOCKAVATAR_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
|
|
echo "Uploading stock avatars to $HOST/api/admin/props"
|
|
echo "Source directory: $STOCKAVATAR_DIR"
|
|
echo ""
|
|
|
|
# Check if server is running
|
|
echo "Checking server health..."
|
|
health_response=$(curl -s -o /dev/null -w "%{http_code}" "$HOST/api/admin/health" 2>/dev/null || echo "000")
|
|
if [ "$health_response" != "200" ]; then
|
|
echo "ERROR: Server is not responding at $HOST (HTTP $health_response)"
|
|
echo ""
|
|
echo "Make sure the server is running:"
|
|
echo " ./run-dev.sh -f"
|
|
echo " ./run-dev.sh -s # Check status"
|
|
exit 1
|
|
fi
|
|
echo "Server is healthy!"
|
|
echo ""
|
|
|
|
# Function to capitalize first letter
|
|
capitalize() {
|
|
echo "$1" | sed 's/.*/\u&/'
|
|
}
|
|
|
|
# Function to determine tags based on filename
|
|
# Tags complement default_layer - avoid redundant info
|
|
get_tags() {
|
|
local filename="$1"
|
|
case "$filename" in
|
|
face.svg)
|
|
# Base face prop - "skin" is already in default_layer
|
|
echo '["base", "face"]'
|
|
;;
|
|
neutral.svg | smile.svg | sad.svg | angry.svg | surprised.svg | thinking.svg | laughing.svg | crying.svg | love.svg | confused.svg | sleeping.svg | wink.svg)
|
|
# Facial expression props - "emote" is already in default_layer
|
|
echo '["face"]'
|
|
;;
|
|
*)
|
|
echo '["prop"]'
|
|
;;
|
|
esac
|
|
}
|
|
|
|
# Function to get positioning fields based on filename
|
|
# Returns: "layer:<value>" for content layer props, "none" for generic props
|
|
get_positioning() {
|
|
local filename="$1"
|
|
case "$filename" in
|
|
face.svg)
|
|
# Base face is a content layer prop (skin layer)
|
|
echo "layer:skin"
|
|
;;
|
|
neutral.svg | smile.svg | sad.svg | angry.svg | surprised.svg | thinking.svg | laughing.svg | crying.svg | love.svg | confused.svg | sleeping.svg | wink.svg)
|
|
# Facial expression props use the emote layer
|
|
echo "layer:emote"
|
|
;;
|
|
*)
|
|
echo "none"
|
|
;;
|
|
esac
|
|
}
|
|
|
|
# Track success/failure counts
|
|
success_count=0
|
|
fail_count=0
|
|
|
|
# Upload each SVG file
|
|
for file in "$STOCKAVATAR_DIR"/*.svg; do
|
|
if [ ! -f "$file" ]; then
|
|
continue
|
|
fi
|
|
|
|
filename=$(basename "$file")
|
|
name_without_ext="${filename%.svg}"
|
|
display_name=$(capitalize "$name_without_ext")
|
|
tags=$(get_tags "$filename")
|
|
positioning=$(get_positioning "$filename")
|
|
|
|
echo "Uploading: $filename -> $display_name (positioning: $positioning)"
|
|
|
|
# Build positioning fields based on type
|
|
positioning_type="${positioning%%:*}"
|
|
positioning_value="${positioning#*:}"
|
|
|
|
case "$positioning_type" in
|
|
layer)
|
|
# Content layer prop (skin, clothes, accessories, emote)
|
|
positioning_json="\"default_layer\": \"$positioning_value\", \"default_position\": 4"
|
|
;;
|
|
*)
|
|
# Generic prop (no default positioning)
|
|
positioning_json=""
|
|
;;
|
|
esac
|
|
|
|
# Create metadata JSON
|
|
if [ -n "$positioning_json" ]; then
|
|
metadata=$(
|
|
cat <<EOF
|
|
{
|
|
"name": "$display_name",
|
|
"tags": $tags,
|
|
$positioning_json
|
|
}
|
|
EOF
|
|
)
|
|
else
|
|
metadata=$(
|
|
cat <<EOF
|
|
{
|
|
"name": "$display_name",
|
|
"tags": $tags
|
|
}
|
|
EOF
|
|
)
|
|
fi
|
|
|
|
# Upload via curl
|
|
response=$(curl -s -w "\n%{http_code}" -X POST "$HOST/api/admin/props$FORCE" \
|
|
-F "metadata=$metadata" \
|
|
-F "file=@$file")
|
|
|
|
# Extract HTTP status code (last line)
|
|
http_code=$(echo "$response" | tail -n1)
|
|
body=$(echo "$response" | sed '$d')
|
|
|
|
if [ "$http_code" = "200" ] || [ "$http_code" = "201" ]; then
|
|
echo " ✓ Success: $body"
|
|
((++success_count))
|
|
else
|
|
echo " ✗ Failed (HTTP $http_code): $body"
|
|
((++fail_count))
|
|
fi
|
|
|
|
echo ""
|
|
done
|
|
|
|
echo "=========================================="
|
|
echo "Upload complete: $success_count succeeded, $fail_count failed"
|