File size: 2,578 Bytes
4badc3b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env bash
# Export accounts.json → Hugging Face CONFIG_ENV secret format.
#
# Usage:
#   ./scripts/export-config-env.sh
#   ./scripts/export-config-env.sh /path/to/accounts.json
#   ./scripts/export-config-env.sh /path/to/accounts.json /path/to/output.txt
#
# Default output: <repo>/hf-config-env.txt (gitignored)
# Paste that file into HF Space Settings → Secrets → CONFIG_ENV.

set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"

ACCOUNTS_FILE="${1:-${HOME}/.config/antigravity-proxy/accounts.json}"
OUTPUT_FILE="${2:-${REPO_ROOT}/hf-config-env.txt}"

if [[ ! -f "${ACCOUNTS_FILE}" ]]; then
  echo "Error: accounts file not found: ${ACCOUNTS_FILE}" >&2
  echo "Usage: $0 [path/to/accounts.json] [path/to/output.txt]" >&2
  exit 1
fi

node --input-type=module - "${ACCOUNTS_FILE}" <<'EOF' > "${OUTPUT_FILE}"
import { readFileSync } from 'fs';

const accountsPath = process.argv[2];
let data;

try {
  data = JSON.parse(readFileSync(accountsPath, 'utf8'));
} catch (error) {
  console.error(`Error: failed to read ${accountsPath}: ${error.message}`);
  process.exit(1);
}

const accounts = data.accounts;
if (!Array.isArray(accounts) || accounts.length === 0) {
  console.error('Error: no accounts found in file');
  process.exit(1);
}

const lines = [];

for (let i = 0; i < accounts.length; i += 1) {
  const acc = accounts[i];
  const n = i + 1;
  const email = String(acc.email || '').trim();
  const refreshToken = String(acc.refreshToken || '').trim();

  if (!email || !refreshToken) {
    console.error(`Error: account ${n} is missing email or refreshToken`);
    process.exit(1);
  }

  const parts = refreshToken.split('|');
  const projectId = String(
    acc.subscription?.projectId || parts[1] || parts[2] || ''
  ).trim();

  let tier = String(acc.subscription?.tier || '').trim().toLowerCase();
  if (!tier || tier === 'unknown') {
    tier = 'pro';
  }

  lines.push(`ANTIGRAVITY_${n}_EMAIL=${email}`);
  lines.push(`ANTIGRAVITY_${n}_REFRESH_TOKEN=${refreshToken}`);
  if (projectId) {
    lines.push(`ANTIGRAVITY_${n}_PROJECT_ID=${projectId}`);
  }
  lines.push(`ANTIGRAVITY_${n}_TIER=${tier}`);
  lines.push('');
}

process.stdout.write(lines.join('\n'));
EOF

chmod 600 "${OUTPUT_FILE}"

account_count="$(grep -c '^ANTIGRAVITY_[0-9]\+_EMAIL=' "${OUTPUT_FILE}" || true)"
echo "Wrote ${account_count} account(s) to: ${OUTPUT_FILE}"
echo "Paste that file into Hugging Face → Space Settings → Secrets → CONFIG_ENV"
echo "Do not commit this file (listed in .gitignore)."