#!/bin/bash

# 使用 Node.js 获取 package.json 中的版本号
VERSION=$(node -pe "require('./package.json').version")

# 构建基础路径
BASE_PATH="bos:/mapv-three-assets/${VERSION}/assets"

# 检查第一个参数是上传还是下载
ACTION=$1

if [ "$ACTION" == "upload" ]; then
    echo "Uploading assets to BOS..."
    echo "Path is: $BASE_PATH"
    bcecmd --conf-path bos-conf bos sync src/assets "$BASE_PATH" --exclude '*/.DS_Store' --yes --quiet
    bcecmd --conf-path bos-conf bos sync dist/assets "$BASE_PATH" --exclude '*/.DS_Store' --yes --quiet
    echo "Upload completed."
elif [ "$ACTION" == "download" ]; then
    echo "Downloading assets from BOS..."
    bcecmd bos sync "$BASE_PATH" dist/assets --quiet
    echo "Download completed."
else
    echo "Unknown action: $ACTION"
    exit 1
fi
