Lenson commited on
Commit
1450f4d
·
1 Parent(s): 0350245

fix: download from each directory separately instead of recursive list

Browse files
Files changed (1) hide show
  1. .hf/setup.sh +43 -27
.hf/setup.sh CHANGED
@@ -30,39 +30,55 @@ download_from_supabase() {
30
  return 1
31
  fi
32
 
33
- # Get file list
34
- local remote_list=$(curl -s -X POST \
35
  -H "Authorization: Bearer $SUPABASE_KEY" \
36
  -H "Content-Type: application/json" \
37
- -d '{"prefix":"","search":"","limit":100,"offsets":[],"sortBy":{"column":"name","order":"asc"},"recursive":true}' \
38
  "$SUPABASE_URL/storage/v1/object/list/$SUPABASE_BUCKET")
39
 
40
- if [ -z "$remote_list" ] || echo "$remote_list" | grep -q "error"; then
41
- echo "No remote data found or error, starting fresh"
42
- return 1
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  fi
44
 
45
- # Parse JSON and download files using bash
46
- echo "$remote_list" | grep -o '"name":"[^"]*"' | sed 's/"name":"//g' | sed 's/"//g' | while read -r remote_path; do
47
- # Skip root level files and empty folder placeholders
48
- if [ -z "$remote_path" ] || [ "$remote_path" = ".emptyFolderPlaceholder" ] || [[ ! "$remote_path" =~ / ]]; then
49
- continue
50
- fi
51
-
52
- # Create local directory
53
- local_path="/app/$remote_path"
54
- mkdir -p "$(dirname "$local_path")"
55
-
56
- # Download file
57
- if curl -s -L \
58
- -H "Authorization: Bearer $SUPABASE_KEY" \
59
- -o "$local_path" \
60
- "$SUPABASE_URL/storage/v1/object/$SUPABASE_BUCKET/$remote_path"; then
61
- echo "Downloaded: $remote_path"
62
- else
63
- echo "Failed: $remote_path"
64
- fi
65
- done
 
 
 
66
 
67
  echo "Download complete"
68
  }
 
30
  return 1
31
  fi
32
 
33
+ # Download files from config/ directory
34
+ local config_list=$(curl -s -X POST \
35
  -H "Authorization: Bearer $SUPABASE_KEY" \
36
  -H "Content-Type: application/json" \
37
+ -d '{"prefix":"config/","search":"","limit":100,"offsets":[],"sortBy":{"column":"name","order":"asc"},"recursive":true}' \
38
  "$SUPABASE_URL/storage/v1/object/list/$SUPABASE_BUCKET")
39
 
40
+ if [ -n "$config_list" ] && ! echo "$config_list" | grep -q "error"; then
41
+ echo "$config_list" | grep -o '"name":"[^"]*"' | sed 's/"name":"//g' | sed 's/"//g' | while read -r remote_path; do
42
+ if [ -z "$remote_path" ] || [ "$remote_path" = ".emptyFolderPlaceholder" ] || [ "$remote_path" = "config" ]; then
43
+ continue
44
+ fi
45
+ local_path="/app/$remote_path"
46
+ mkdir -p "$(dirname "$local_path")"
47
+ if curl -s -L \
48
+ -H "Authorization: Bearer $SUPABASE_KEY" \
49
+ -o "$local_path" \
50
+ "$SUPABASE_URL/storage/v1/object/$SUPABASE_BUCKET/$remote_path"; then
51
+ echo "Downloaded: $remote_path"
52
+ else
53
+ echo "Failed: $remote_path"
54
+ fi
55
+ done
56
  fi
57
 
58
+ # Download files from data/ directory
59
+ local data_list=$(curl -s -X POST \
60
+ -H "Authorization: Bearer $SUPABASE_KEY" \
61
+ -H "Content-Type: application/json" \
62
+ -d '{"prefix":"data/","search":"","limit":100,"offsets":[],"sortBy":{"column":"name","order":"asc"},"recursive":true}' \
63
+ "$SUPABASE_URL/storage/v1/object/list/$SUPABASE_BUCKET")
64
+
65
+ if [ -n "$data_list" ] && ! echo "$data_list" | grep -q "error"; then
66
+ echo "$data_list" | grep -o '"name":"[^"]*"' | sed 's/"name":"//g' | sed 's/"//g' | while read -r remote_path; do
67
+ if [ -z "$remote_path" ] || [ "$remote_path" = ".emptyFolderPlaceholder" ] || [ "$remote_path" = "data" ]; then
68
+ continue
69
+ fi
70
+ local_path="/app/$remote_path"
71
+ mkdir -p "$(dirname "$local_path")"
72
+ if curl -s -L \
73
+ -H "Authorization: Bearer $SUPABASE_KEY" \
74
+ -o "$local_path" \
75
+ "$SUPABASE_URL/storage/v1/object/$SUPABASE_BUCKET/$remote_path"; then
76
+ echo "Downloaded: $remote_path"
77
+ else
78
+ echo "Failed: $remote_path"
79
+ fi
80
+ done
81
+ fi
82
 
83
  echo "Download complete"
84
  }