#!/bin/bash

BASE_URL="https://cdn.changes.tg/gifts/models"

# List of directories (items with spaces must be handled properly)
directories=(
    "astral shard" "diamond ring" "fool's cap" "loot bag" "mini oscar" "snow mittens" "vintage cigar"
    "b-day candle" "durov's cap" "genie lamp" "ion gem" "party sparkler" "santa hat" "spiced wine" "voodoo doll"
    "berry box" "durov’s cap" "ginger cookie" "jelly bunny" "love candle" "party sparklers" "scared cat" "spy agaric" "witch hat"
    "bunny muffin" "eternal candle" "hanging star" "jester hat" "love potion" "star notepad"
    "cookie heart" "eternal rose" "hex pot" "jingle bells" "lunar snake" "perfume bottle" "sharp tongue" "swiss watch"
    "crystal ball" "evil eye" "homemade cake" "kissed frog" "mad pumpkin" "plush pepe" "signet ring" "toy bear"
    "desk calendar" "flying broom" "hypno lollipop" "lol pop" "magic potion" "precious peach" "skull flower" "trapped heart"
)

# Loop through each directory
for dir in "${directories[@]}"; do
    # Convert space-containing directory names to a safe format
    safe_dir=$(echo "$dir" | awk '{for(i=1;i<=NF;i++) $i=toupper(substr($i,1,1)) substr($i,2)}1')

    echo "Processing: $dir"
    
    # Ensure directory exists
    cd "$dir" || { echo "Failed to enter $dir/png"; continue; }

    # Download PNG files from the given URL
    wget -r -np -nd -A "*.png" "${BASE_URL}/${safe_dir}/png/"

    # Apply chmod -R 755
    chmod -R 755 .

    # Go back to the parent directory
    cd ..
done

echo "Download and permission update complete!"
