Use backend proxy for Unsandbox API calls to keep API key secure
This commit is contained in:
parent
8c128878c4
commit
6e279c0ed5
1 changed files with 5 additions and 5 deletions
|
|
@ -98,7 +98,7 @@
|
||||||
const API_KEY = "dummy-api-key";
|
const API_KEY = "dummy-api-key";
|
||||||
const TTS_API_URL = "https://speech.ai.unturf.com/v1/audio/speech";
|
const TTS_API_URL = "https://speech.ai.unturf.com/v1/audio/speech";
|
||||||
const VOICES_API_URL = "https://speech.ai.unturf.com/v1/voices";
|
const VOICES_API_URL = "https://speech.ai.unturf.com/v1/voices";
|
||||||
const CODE_EXEC_URL = "https://api.unsandbox.com"; // Unsandbox code execution API
|
// Code execution API (proxied through backend to keep API key secure)
|
||||||
const room_name = "{{ room_name }}";
|
const room_name = "{{ room_name }}";
|
||||||
|
|
||||||
// Get username from server (authenticated user's display name or None)
|
// Get username from server (authenticated user's display name or None)
|
||||||
|
|
@ -1699,8 +1699,8 @@ async function executeCodeBlock(code, blockElement, playButton) {
|
||||||
language = 'python';
|
language = 'python';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use /execute/async endpoint with polling
|
// Use backend proxy for code execution (keeps API key secure)
|
||||||
const asyncResponse = await fetch(`${CODE_EXEC_URL}/execute/async`, {
|
const asyncResponse = await fetch('/api/code/execute', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
|
@ -1739,7 +1739,7 @@ async function executeCodeBlock(code, blockElement, playButton) {
|
||||||
cancelButton.style.cursor = 'pointer';
|
cancelButton.style.cursor = 'pointer';
|
||||||
cancelButton.onclick = async () => {
|
cancelButton.onclick = async () => {
|
||||||
try {
|
try {
|
||||||
await fetch(`${CODE_EXEC_URL}/jobs/${job_id}`, { method: 'DELETE' });
|
await fetch(`/api/code/jobs/${job_id}`, { method: 'DELETE' });
|
||||||
cancelButton.disabled = true;
|
cancelButton.disabled = true;
|
||||||
cancelButton.textContent = 'Cancelling...';
|
cancelButton.textContent = 'Cancelling...';
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
@ -1753,7 +1753,7 @@ async function executeCodeBlock(code, blockElement, playButton) {
|
||||||
await sleep(delays[Math.min(pollCount, delays.length - 1)]);
|
await sleep(delays[Math.min(pollCount, delays.length - 1)]);
|
||||||
pollCount++;
|
pollCount++;
|
||||||
|
|
||||||
const jobResponse = await fetch(`${CODE_EXEC_URL}/jobs/${job_id}`);
|
const jobResponse = await fetch(`/api/code/jobs/${job_id}`);
|
||||||
if (!jobResponse.ok) {
|
if (!jobResponse.ok) {
|
||||||
throw new Error(`Failed to fetch job status: ${jobResponse.status}`);
|
throw new Error(`Failed to fetch job status: ${jobResponse.status}`);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue