@@ -2507,24 +2507,42 @@ export async function runFocUploadFromJob(job) {
25072507
25082508 const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'tokenhost-netlify-upload-'));
25092509 const tmpFile = path.join(tmpDir, job.fileName || 'upload.bin');
2510+ const runtimeHome = path.join(os.tmpdir(), 'tokenhost-netlify-home');
2511+ const xdgConfigHome = path.join(runtimeHome, '.config');
2512+ const npmCacheDir = path.join(runtimeHome, '.npm');
2513+ const normalizedPrivateKey = privateKey.startsWith('0x') ? privateKey : \`0x\${privateKey}\`;
25102514
25112515 try {
2516+ await fs.mkdir(runtimeHome, { recursive: true });
2517+ await fs.mkdir(xdgConfigHome, { recursive: true });
2518+ await fs.mkdir(npmCacheDir, { recursive: true });
25122519 await fs.writeFile(tmpFile, Buffer.from(String(job.bodyBase64 || ''), 'base64'));
25132520 const command = String(process.env.TH_UPLOAD_FOC_COMMAND ?? DEFAULT_FOC_COMMAND).trim() || DEFAULT_FOC_COMMAND;
25142521 const chainId = parsePositiveInt(process.env.TH_UPLOAD_FOC_CHAIN, DEFAULT_CHAIN_ID);
25152522 const copies = parsePositiveInt(process.env.TH_UPLOAD_FOC_COPIES, DEFAULT_COPIES);
25162523 const withCDN = String(process.env.TH_UPLOAD_FOC_WITH_CDN ?? '').trim().toLowerCase();
25172524 const debug = String(process.env.TH_UPLOAD_FOC_DEBUG ?? '').trim().toLowerCase();
2525+ const sharedEnv = {
2526+ ...process.env,
2527+ HOME: runtimeHome,
2528+ XDG_CONFIG_HOME: xdgConfigHome,
2529+ NPM_CONFIG_CACHE: npmCacheDir,
2530+ npm_config_cache: npmCacheDir,
2531+ NPM_CONFIG_UPDATE_NOTIFIER: 'false',
2532+ PRIVATE_KEY: privateKey,
2533+ TH_UPLOAD_FOC_PRIVATE_KEY: privateKey
2534+ };
2535+ const focConfigDir = path.join(xdgConfigHome, 'foc-cli-nodejs');
2536+ const focConfigPath = path.join(focConfigDir, 'config.json');
2537+ await fs.mkdir(focConfigDir, { recursive: true });
2538+ await fs.writeFile(focConfigPath, JSON.stringify({ privateKey: normalizedPrivateKey }) + '\\n', 'utf8');
2539+
25182540 const shellCommand =
25192541 \`\${command} upload \${shellQuote(tmpFile)} --format json --chain \${chainId} --copies \${copies}\` +
25202542 ((withCDN === '1' || withCDN === 'true' || withCDN === 'yes' || withCDN === 'on') ? ' --withCDN true' : '') +
25212543 ((debug === '1' || debug === 'true' || debug === 'yes' || debug === 'on') ? ' --debug true --verbose' : '');
25222544
2523- const result = await runShellCommand(shellCommand, {
2524- ...process.env,
2525- PRIVATE_KEY: privateKey,
2526- TH_UPLOAD_FOC_PRIVATE_KEY: privateKey
2527- });
2545+ const result = await runShellCommand(shellCommand, sharedEnv);
25282546
25292547 if (result.code !== 0) {
25302548 throw new Error(String(result.stderr || result.stdout || \`foc-cli failed with status \${result.code}\`).trim());
0 commit comments