Spaces:
Running
Running
Commit
•
c4d103b
1
Parent(s):
abee439
sveltekit refactor
Browse files- src/routes/Leaderboard.svelte +1 -2
- src/routes/Vote.svelte +3 -4
- src/routes/api/fetchScenes/+server.ts +31 -0
- src/routes/api/leaderboard/+server.ts +28 -0
- src/routes/api/vote/+server.ts +33 -0
- static/global.css +1 -0
src/routes/Leaderboard.svelte
CHANGED
@@ -15,11 +15,10 @@
|
|
15 |
let leaderboard: Entry[] = [];
|
16 |
|
17 |
const fetchLeaderboardData = async () => {
|
18 |
-
const url = "
|
19 |
const response = await fetch(url, {
|
20 |
method: "GET",
|
21 |
headers: {
|
22 |
-
Authorization: "Bearer " + import.meta.env.VITE_HF_TOKEN,
|
23 |
"Cache-Control": "no-cache",
|
24 |
},
|
25 |
});
|
|
|
15 |
let leaderboard: Entry[] = [];
|
16 |
|
17 |
const fetchLeaderboardData = async () => {
|
18 |
+
const url = "/api/leaderboard";
|
19 |
const response = await fetch(url, {
|
20 |
method: "GET",
|
21 |
headers: {
|
|
|
22 |
"Cache-Control": "no-cache",
|
23 |
},
|
24 |
});
|
src/routes/Vote.svelte
CHANGED
@@ -47,11 +47,11 @@
|
|
47 |
try {
|
48 |
const username = getUsername();
|
49 |
console.log(`Fetching with username: ${username}`);
|
50 |
-
const url =
|
51 |
const response = await fetch(url, {
|
52 |
method: "GET",
|
53 |
headers: {
|
54 |
-
|
55 |
"Cache-Control": "no-cache",
|
56 |
},
|
57 |
});
|
@@ -113,7 +113,7 @@
|
|
113 |
better: option == "A" ? data.model1 : data.model2,
|
114 |
worse: option == "A" ? data.model2 : data.model1,
|
115 |
};
|
116 |
-
const url =
|
117 |
|
118 |
const startTime = Date.now();
|
119 |
|
@@ -121,7 +121,6 @@
|
|
121 |
const response = await fetch(url, {
|
122 |
method: "POST",
|
123 |
headers: {
|
124 |
-
Authorization: "Bearer " + import.meta.env.VITE_HF_TOKEN,
|
125 |
"Cache-Control": "no-cache",
|
126 |
"Content-Type": "application/json",
|
127 |
},
|
|
|
47 |
try {
|
48 |
const username = getUsername();
|
49 |
console.log(`Fetching with username: ${username}`);
|
50 |
+
const url = "/api/fetchScenes";
|
51 |
const response = await fetch(url, {
|
52 |
method: "GET",
|
53 |
headers: {
|
54 |
+
username: username,
|
55 |
"Cache-Control": "no-cache",
|
56 |
},
|
57 |
});
|
|
|
113 |
better: option == "A" ? data.model1 : data.model2,
|
114 |
worse: option == "A" ? data.model2 : data.model1,
|
115 |
};
|
116 |
+
const url = `/api/vote`;
|
117 |
|
118 |
const startTime = Date.now();
|
119 |
|
|
|
121 |
const response = await fetch(url, {
|
122 |
method: "POST",
|
123 |
headers: {
|
|
|
124 |
"Cache-Control": "no-cache",
|
125 |
"Content-Type": "application/json",
|
126 |
},
|
src/routes/api/fetchScenes/+server.ts
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import type { RequestHandler } from "@sveltejs/kit";
|
2 |
+
|
3 |
+
export const GET: RequestHandler = async ({ request }) => {
|
4 |
+
const username = request.headers.get("username");
|
5 |
+
const url = `https://dylanebert-3d-arena-backend.hf.space/pair?username=${username}`;
|
6 |
+
|
7 |
+
try {
|
8 |
+
const response = await fetch(url, {
|
9 |
+
method: "GET",
|
10 |
+
headers: {
|
11 |
+
Authorization: `Bearer ${import.meta.env.VITE_HF_TOKEN}`,
|
12 |
+
"Cache-Control": "no-cache",
|
13 |
+
},
|
14 |
+
});
|
15 |
+
|
16 |
+
if (response.ok) {
|
17 |
+
const result = await response.json();
|
18 |
+
return new Response(JSON.stringify(result), {
|
19 |
+
status: 200,
|
20 |
+
});
|
21 |
+
} else {
|
22 |
+
return new Response(JSON.stringify({ error: "Failed to fetch pair." }), {
|
23 |
+
status: response.status,
|
24 |
+
});
|
25 |
+
}
|
26 |
+
} catch (error) {
|
27 |
+
return new Response(JSON.stringify({ error: "Failed to fetch pair." }), {
|
28 |
+
status: 500,
|
29 |
+
});
|
30 |
+
}
|
31 |
+
};
|
src/routes/api/leaderboard/+server.ts
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import type { RequestHandler } from "@sveltejs/kit";
|
2 |
+
|
3 |
+
export const GET: RequestHandler = async ({ request }) => {
|
4 |
+
const url = `https://dylanebert-3d-arena-backend.hf.space/leaderboard`;
|
5 |
+
|
6 |
+
try {
|
7 |
+
const response = await fetch(url, {
|
8 |
+
method: "GET",
|
9 |
+
headers: {
|
10 |
+
Authorization: `Bearer ${import.meta.env.VITE_HF_TOKEN}`,
|
11 |
+
"Cache-Control": "no-cache",
|
12 |
+
},
|
13 |
+
});
|
14 |
+
|
15 |
+
if (response.ok) {
|
16 |
+
const result = await response.json();
|
17 |
+
return new Response(JSON.stringify(result), { status: 200 });
|
18 |
+
} else {
|
19 |
+
return new Response(JSON.stringify({ error: "Failed to fetch leaderboard." }), {
|
20 |
+
status: response.status,
|
21 |
+
});
|
22 |
+
}
|
23 |
+
} catch (error) {
|
24 |
+
return new Response(JSON.stringify({ error: "Failed to fetch leaderboard." }), {
|
25 |
+
status: 500,
|
26 |
+
});
|
27 |
+
}
|
28 |
+
};
|
src/routes/api/vote/+server.ts
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import type { RequestHandler } from "@sveltejs/kit";
|
2 |
+
|
3 |
+
export const POST: RequestHandler = async ({ request }) => {
|
4 |
+
const payload = await request.json();
|
5 |
+
const url = `https://dylanebert-3d-arena-backend.hf.space/vote`;
|
6 |
+
|
7 |
+
try {
|
8 |
+
const response = await fetch(url, {
|
9 |
+
method: "POST",
|
10 |
+
headers: {
|
11 |
+
Authorization: `Bearer ${import.meta.env.VITE_HF_TOKEN}`,
|
12 |
+
"Cache-Control": "no-cache",
|
13 |
+
"Content-Type": "application/json",
|
14 |
+
},
|
15 |
+
body: JSON.stringify(payload),
|
16 |
+
});
|
17 |
+
|
18 |
+
if (response.ok) {
|
19 |
+
const result = await response.json();
|
20 |
+
return new Response(JSON.stringify(result), {
|
21 |
+
status: 200,
|
22 |
+
});
|
23 |
+
} else {
|
24 |
+
return new Response(JSON.stringify({ error: "Failed to process vote." }), {
|
25 |
+
status: response.status,
|
26 |
+
});
|
27 |
+
}
|
28 |
+
} catch (error) {
|
29 |
+
return new Response(JSON.stringify({ error: "Failed to process vote." }), {
|
30 |
+
status: 500,
|
31 |
+
});
|
32 |
+
}
|
33 |
+
};
|
static/global.css
CHANGED
@@ -357,6 +357,7 @@ body {
|
|
357 |
.label {
|
358 |
font-weight: bold;
|
359 |
justify-content: flex-end;
|
|
|
360 |
width: 50px;
|
361 |
}
|
362 |
|
|
|
357 |
.label {
|
358 |
font-weight: bold;
|
359 |
justify-content: flex-end;
|
360 |
+
text-align: right;
|
361 |
width: 50px;
|
362 |
}
|
363 |
|