| 127 | } |
| 128 | |
| 129 | function push() { |
| 130 | if (!existsSync(ENCRYPTED_PATH)) { |
| 131 | console.error(`Missing ${ENCRYPTED_PATH}. Run: npm run credentials:encrypt`); |
| 132 | process.exit(1); |
| 133 | } |
| 134 | |
| 135 | const bucket = process.env.R2_BUCKET_NAME; |
| 136 | if (!bucket) { |
| 137 | console.error( |
| 138 | 'Set R2_BUCKET_NAME in .env (optional R2_OBJECT_KEY). Authenticate with wrangler (e.g. wrangler login or CLOUDFLARE_API_TOKEN with R2 write).' |
| 139 | ); |
| 140 | process.exit(1); |
| 141 | } |
| 142 | |
| 143 | const wranglerBin = join(repoRoot, 'node_modules', 'wrangler', 'bin', 'wrangler.js'); |
| 144 | if (!existsSync(wranglerBin)) { |
| 145 | console.error('Missing wrangler. Run npm install.'); |
| 146 | process.exit(1); |
| 147 | } |
| 148 | |
| 149 | const objectPath = `${bucket}/${R2_OBJECT_KEY}`; |
| 150 | try { |
| 151 | execFileSync( |
| 152 | process.execPath, |
| 153 | [ |
| 154 | wranglerBin, |
| 155 | 'r2', |
| 156 | 'object', |
| 157 | 'put', |
| 158 | objectPath, |
| 159 | '--file', |
| 160 | ENCRYPTED_PATH, |
| 161 | '--content-type', |
| 162 | 'application/json', |
| 163 | '--remote', |
| 164 | '-y' |
| 165 | ], |
| 166 | { stdio: 'inherit', cwd: repoRoot, env: process.env } |
| 167 | ); |
| 168 | } catch { |
| 169 | process.exit(1); |
| 170 | } |
| 171 | |
| 172 | console.log(`Uploaded r2://${objectPath}`); |
| 173 | } |
| 174 | |
| 175 | async function presign() { |
| 176 | const env = requireR2S3Credentials('presign'); |