Spaces:
Running
Running
Update index.html
Browse files- index.html +26 -7
index.html
CHANGED
@@ -149,6 +149,7 @@
|
|
149 |
userSpaces: [],
|
150 |
selectedSpaces: [],
|
151 |
spaceTypes: {},
|
|
|
152 |
|
153 |
buttonClass(attr, filter) {
|
154 |
if (this[attr] === filter) {
|
@@ -220,7 +221,7 @@
|
|
220 |
}
|
221 |
const res = await fetch(searchUrl);
|
222 |
data = await res.json();
|
223 |
-
console.log(data)
|
224 |
// Transform the API response to match the expected format
|
225 |
data = data.filter(item => item.runtime?.stage === "RUNNING").map(item => ({
|
226 |
id: item.id,
|
@@ -257,19 +258,35 @@
|
|
257 |
},
|
258 |
|
259 |
async authenticate() {
|
|
|
260 |
try {
|
|
|
|
|
|
|
|
|
|
|
|
|
261 |
const response = await fetch('https://huggingface.co/api/whoami', {
|
262 |
headers: { Authorization: `Bearer ${this.hfToken}` }
|
263 |
});
|
264 |
-
|
265 |
-
if (!response.ok)
|
|
|
|
|
|
|
266 |
const userData = await response.json();
|
267 |
-
|
|
|
|
|
268 |
const spacesRes = await fetch(
|
269 |
`https://huggingface.co/api/spaces?user=${userData.name}`,
|
270 |
{ headers: { Authorization: `Bearer ${this.hfToken}` } }
|
271 |
);
|
272 |
-
|
|
|
|
|
|
|
|
|
273 |
const spacesData = await spacesRes.json();
|
274 |
this.userSpaces = spacesData
|
275 |
.filter(space => space.runtime?.stage === "RUNNING")
|
@@ -279,13 +296,14 @@
|
|
279 |
likes: space.likes,
|
280 |
lastModified: space.lastModified
|
281 |
}));
|
282 |
-
|
283 |
this.spaceTypes = Object.fromEntries(
|
284 |
this.userSpaces.map(space => [space.id, 'tool'])
|
285 |
);
|
286 |
this.authenticated = true;
|
287 |
} catch (error) {
|
288 |
-
|
|
|
289 |
}
|
290 |
},
|
291 |
|
@@ -348,6 +366,7 @@
|
|
348 |
Cancel
|
349 |
</button>
|
350 |
</div>
|
|
|
351 |
</div>
|
352 |
</template>
|
353 |
|
|
|
149 |
userSpaces: [],
|
150 |
selectedSpaces: [],
|
151 |
spaceTypes: {},
|
152 |
+
authError: '',
|
153 |
|
154 |
buttonClass(attr, filter) {
|
155 |
if (this[attr] === filter) {
|
|
|
221 |
}
|
222 |
const res = await fetch(searchUrl);
|
223 |
data = await res.json();
|
224 |
+
console.log(data);
|
225 |
// Transform the API response to match the expected format
|
226 |
data = data.filter(item => item.runtime?.stage === "RUNNING").map(item => ({
|
227 |
id: item.id,
|
|
|
258 |
},
|
259 |
|
260 |
async authenticate() {
|
261 |
+
this.authError = ''; // Reset error message
|
262 |
try {
|
263 |
+
// Validate token format
|
264 |
+
if (!this.hfToken || this.hfToken.length < 10) {
|
265 |
+
throw new Error('Invalid token format');
|
266 |
+
}
|
267 |
+
|
268 |
+
// Fetch user info to validate token
|
269 |
const response = await fetch('https://huggingface.co/api/whoami', {
|
270 |
headers: { Authorization: `Bearer ${this.hfToken}` }
|
271 |
});
|
272 |
+
|
273 |
+
if (!response.ok) {
|
274 |
+
throw new Error('Authentication failed. Please check your token.');
|
275 |
+
}
|
276 |
+
|
277 |
const userData = await response.json();
|
278 |
+
console.log('Authenticated as:', userData.name);
|
279 |
+
|
280 |
+
// Fetch user spaces
|
281 |
const spacesRes = await fetch(
|
282 |
`https://huggingface.co/api/spaces?user=${userData.name}`,
|
283 |
{ headers: { Authorization: `Bearer ${this.hfToken}` } }
|
284 |
);
|
285 |
+
|
286 |
+
if (!spacesRes.ok) {
|
287 |
+
throw new Error('Failed to fetch spaces. Please try again.');
|
288 |
+
}
|
289 |
+
|
290 |
const spacesData = await spacesRes.json();
|
291 |
this.userSpaces = spacesData
|
292 |
.filter(space => space.runtime?.stage === "RUNNING")
|
|
|
296 |
likes: space.likes,
|
297 |
lastModified: space.lastModified
|
298 |
}));
|
299 |
+
|
300 |
this.spaceTypes = Object.fromEntries(
|
301 |
this.userSpaces.map(space => [space.id, 'tool'])
|
302 |
);
|
303 |
this.authenticated = true;
|
304 |
} catch (error) {
|
305 |
+
console.error('Authentication error:', error);
|
306 |
+
this.authError = error.message;
|
307 |
}
|
308 |
},
|
309 |
|
|
|
366 |
Cancel
|
367 |
</button>
|
368 |
</div>
|
369 |
+
<p x-show="authError" class="text-red-500" x-text="authError"></p>
|
370 |
</div>
|
371 |
</template>
|
372 |
|