cduss commited on
Commit
e15d4cc
·
1 Parent(s): f19738b
Files changed (1) hide show
  1. index.html +28 -22
index.html CHANGED
@@ -103,8 +103,16 @@
103
  </div>
104
 
105
  <script>
106
- // 🔧 CUSTOMIZE THIS VALUE FOR YOUR APP:
107
- const APP_REPO_URL = "https://github.com/your-username/your-reachy-app.git";
 
 
 
 
 
 
 
 
108
 
109
  // Parse TOML content to extract project name
110
  function parseTomlProjectName(tomlContent) {
@@ -144,19 +152,11 @@
144
  }
145
  }
146
 
147
- // Fetch and parse pyproject.toml from the repository
148
- async function getAppNameFromRepo(repoUrl) {
149
  try {
150
- // Convert GitHub repo URL to raw content URL for pyproject.toml
151
- let rawUrl = repoUrl.replace(/\.git$/, '');
152
- if (rawUrl.includes('github.com')) {
153
- rawUrl = rawUrl.replace('github.com', 'raw.githubusercontent.com');
154
- rawUrl += '/main/pyproject.toml';
155
- } else {
156
- throw new Error('Only GitHub repositories are supported for automatic name detection');
157
- }
158
-
159
- const response = await fetch(rawUrl);
160
  if (!response.ok) {
161
  throw new Error(`Failed to fetch pyproject.toml: ${response.status}`);
162
  }
@@ -164,9 +164,12 @@
164
  const tomlContent = await response.text();
165
  return parseTomlProjectName(tomlContent);
166
  } catch (error) {
167
- console.error('Error fetching app name from repository:', error);
168
- // Fallback to a default name if parsing fails
169
- return 'app-from-repo';
 
 
 
170
  }
171
  }
172
 
@@ -195,10 +198,13 @@
195
  throw new Error('Cannot connect to dashboard. Make sure the URL is correct and the dashboard is running.');
196
  }
197
 
198
- showStatus('loading', 'Reading app configuration from repository...');
 
 
 
199
 
200
- // Get app name from pyproject.toml
201
- const appName = await getAppNameFromRepo(APP_REPO_URL);
202
 
203
  showStatus('loading', `Starting installation of "${appName}"...`);
204
 
@@ -210,7 +216,7 @@
210
  'Content-Type': 'application/json',
211
  },
212
  body: JSON.stringify({
213
- url: APP_REPO_URL,
214
  name: appName
215
  })
216
  });
@@ -262,7 +268,7 @@
262
  // Update the repository URL display if element exists
263
  const repoUrlElement = document.getElementById('repoUrl');
264
  if (repoUrlElement) {
265
- repoUrlElement.textContent = APP_REPO_URL;
266
  }
267
  });
268
 
 
103
  </div>
104
 
105
  <script>
106
+ // Get the current Hugging Face Space URL as the repository URL
107
+ function getCurrentSpaceUrl() {
108
+ // Get current page URL and convert to repository format
109
+ const currentUrl = window.location.href;
110
+
111
+ // Remove any trailing slashes and query parameters
112
+ const cleanUrl = currentUrl.split('?')[0].replace(/\/$/, '');
113
+
114
+ return cleanUrl;
115
+ }
116
 
117
  // Parse TOML content to extract project name
118
  function parseTomlProjectName(tomlContent) {
 
152
  }
153
  }
154
 
155
+ // Fetch and parse pyproject.toml from the current space
156
+ async function getAppNameFromCurrentSpace() {
157
  try {
158
+ // Fetch pyproject.toml from the current space
159
+ const response = await fetch('./pyproject.toml');
 
 
 
 
 
 
 
 
160
  if (!response.ok) {
161
  throw new Error(`Failed to fetch pyproject.toml: ${response.status}`);
162
  }
 
164
  const tomlContent = await response.text();
165
  return parseTomlProjectName(tomlContent);
166
  } catch (error) {
167
+ console.error('Error fetching app name from current space:', error);
168
+ // Fallback to extracting from URL if pyproject.toml is not accessible
169
+ const url = getCurrentSpaceUrl();
170
+ const parts = url.split('/');
171
+ const spaceName = parts[parts.length - 1];
172
+ return spaceName.toLowerCase().replace(/[^a-z0-9-_]/g, '-');
173
  }
174
  }
175
 
 
198
  throw new Error('Cannot connect to dashboard. Make sure the URL is correct and the dashboard is running.');
199
  }
200
 
201
+ showStatus('loading', 'Reading app configuration...');
202
+
203
+ // Get app name from pyproject.toml in current space
204
+ const appName = await getAppNameFromCurrentSpace();
205
 
206
+ // Get current space URL as repository URL
207
+ const repoUrl = getCurrentSpaceUrl();
208
 
209
  showStatus('loading', `Starting installation of "${appName}"...`);
210
 
 
216
  'Content-Type': 'application/json',
217
  },
218
  body: JSON.stringify({
219
+ url: repoUrl,
220
  name: appName
221
  })
222
  });
 
268
  // Update the repository URL display if element exists
269
  const repoUrlElement = document.getElementById('repoUrl');
270
  if (repoUrlElement) {
271
+ repoUrlElement.textContent = getCurrentSpaceUrl();
272
  }
273
  });
274