wip
Browse files- index.html +28 -22
index.html
CHANGED
@@ -103,8 +103,16 @@
|
|
103 |
</div>
|
104 |
|
105 |
<script>
|
106 |
-
//
|
107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
148 |
-
async function
|
149 |
try {
|
150 |
-
//
|
151 |
-
|
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
|
168 |
-
// Fallback to
|
169 |
-
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
199 |
|
200 |
-
// Get
|
201 |
-
const
|
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:
|
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 =
|
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 |
|