dlouapre HF Staff commited on
Commit
036cb16
·
1 Parent(s): 82d282f

Adjust endpoint payload

Browse files
Files changed (1) hide show
  1. index.html +18 -5
index.html CHANGED
@@ -99,10 +99,12 @@ look right</pre>
99
  <script>
100
  function getCurrentSpaceUrl() {
101
  const url = window.location.href;
 
102
  const match = url.match(/https:\/\/huggingface\.co\/spaces\/([^\/]+\/[^\/]+)/);
103
  if (match) {
104
  return `https://huggingface.co/spaces/${match[1]}`;
105
  }
 
106
  if (url.includes('.hf.space')) {
107
  const hostMatch = url.match(/https?:\/\/([^\.]+)\.hf\.space/);
108
  if (hostMatch) {
@@ -121,7 +123,7 @@ look right</pre>
121
  async function getAppNameFromCurrentSpace() {
122
  try {
123
  const spaceUrl = getCurrentSpaceUrl();
124
- const tomlUrl = spaceUrl.replace('/spaces/', '/spaces/') + '/raw/main/pyproject.toml';
125
  const response = await fetch(tomlUrl);
126
  if (response.ok) {
127
  const tomlContent = await response.text();
@@ -148,8 +150,8 @@ look right</pre>
148
  showStatus('loading', 'Connecting to Reachy dashboard...');
149
 
150
  try {
151
- // Test connection
152
- const testResponse = await fetch(`${dashboardUrl}/api/apps`, {
153
  method: 'GET',
154
  mode: 'cors',
155
  });
@@ -163,15 +165,26 @@ look right</pre>
163
  const spaceUrl = getCurrentSpaceUrl();
164
  const appName = await getAppNameFromCurrentSpace();
165
 
 
166
  const installResponse = await fetch(`${dashboardUrl}/api/apps/install`, {
167
  method: 'POST',
168
  headers: { 'Content-Type': 'application/json' },
169
- body: JSON.stringify({ space_url: spaceUrl }),
 
 
 
 
 
170
  mode: 'cors',
171
  });
172
 
173
  if (installResponse.ok) {
174
- showStatus('success', `Successfully installed! Open the dashboard to run ${appName}.`);
 
 
 
 
 
175
  } else {
176
  const error = await installResponse.text();
177
  throw new Error(error || 'Installation failed');
 
99
  <script>
100
  function getCurrentSpaceUrl() {
101
  const url = window.location.href;
102
+ // Match huggingface.co/spaces/user/repo format
103
  const match = url.match(/https:\/\/huggingface\.co\/spaces\/([^\/]+\/[^\/]+)/);
104
  if (match) {
105
  return `https://huggingface.co/spaces/${match[1]}`;
106
  }
107
+ // Match user-repo.hf.space format
108
  if (url.includes('.hf.space')) {
109
  const hostMatch = url.match(/https?:\/\/([^\.]+)\.hf\.space/);
110
  if (hostMatch) {
 
123
  async function getAppNameFromCurrentSpace() {
124
  try {
125
  const spaceUrl = getCurrentSpaceUrl();
126
+ const tomlUrl = spaceUrl + '/raw/main/pyproject.toml';
127
  const response = await fetch(tomlUrl);
128
  if (response.ok) {
129
  const tomlContent = await response.text();
 
150
  showStatus('loading', 'Connecting to Reachy dashboard...');
151
 
152
  try {
153
+ // Test connection using the correct endpoint
154
+ const testResponse = await fetch(`${dashboardUrl}/api/apps/list-available`, {
155
  method: 'GET',
156
  mode: 'cors',
157
  });
 
165
  const spaceUrl = getCurrentSpaceUrl();
166
  const appName = await getAppNameFromCurrentSpace();
167
 
168
+ // Use correct API format: AppInfo schema with name, source_kind, url
169
  const installResponse = await fetch(`${dashboardUrl}/api/apps/install`, {
170
  method: 'POST',
171
  headers: { 'Content-Type': 'application/json' },
172
+ body: JSON.stringify({
173
+ name: appName || 'rmscript-app',
174
+ source_kind: 'hf_space',
175
+ url: spaceUrl,
176
+ description: 'Web IDE for programming Reachy Mini with rmscript'
177
+ }),
178
  mode: 'cors',
179
  });
180
 
181
  if (installResponse.ok) {
182
+ const result = await installResponse.json();
183
+ if (result.job_id) {
184
+ showStatus('success', `Installation started! Job ID: ${result.job_id}. Check the dashboard for progress.`);
185
+ } else {
186
+ showStatus('success', `Successfully installed! Open the dashboard to run ${appName}.`);
187
+ }
188
  } else {
189
  const error = await installResponse.text();
190
  throw new Error(error || 'Installation failed');