Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
refacto gallery route
Browse files
src/lib/components/community/reactions/Add.svelte
CHANGED
@@ -26,9 +26,9 @@
|
|
26 |
}
|
27 |
|
28 |
const handleReaction = async (emoji: string) => {
|
29 |
-
await fetch(`/api/community/reaction`, {
|
30 |
method: "POST",
|
31 |
-
body: JSON.stringify({ emoji
|
32 |
headers: {
|
33 |
"Content-Type": "application/json",
|
34 |
},
|
|
|
26 |
}
|
27 |
|
28 |
const handleReaction = async (emoji: string) => {
|
29 |
+
await fetch(`/api/community/${gallery_id}/reaction`, {
|
30 |
method: "POST",
|
31 |
+
body: JSON.stringify({ emoji }),
|
32 |
headers: {
|
33 |
"Content-Type": "application/json",
|
34 |
},
|
src/lib/components/community/reactions/Reaction.svelte
CHANGED
@@ -8,9 +8,9 @@
|
|
8 |
export let onReact: (emoji: string, id: string, deleted: boolean) => void;
|
9 |
|
10 |
const handleReaction = async (emoji: string) => {
|
11 |
-
await fetch(`/api/community/reaction`, {
|
12 |
method: "POST",
|
13 |
-
body: JSON.stringify({ emoji
|
14 |
headers: {
|
15 |
"Content-Type": "application/json",
|
16 |
},
|
|
|
8 |
export let onReact: (emoji: string, id: string, deleted: boolean) => void;
|
9 |
|
10 |
const handleReaction = async (emoji: string) => {
|
11 |
+
await fetch(`/api/community/${gallery_id}/reaction`, {
|
12 |
method: "POST",
|
13 |
+
body: JSON.stringify({ emoji }),
|
14 |
headers: {
|
15 |
"Content-Type": "application/json",
|
16 |
},
|
src/routes/api/community/{reaction β [id]/reaction}/+server.ts
RENAMED
@@ -5,60 +5,46 @@ import prisma from '$lib/prisma';
|
|
5 |
|
6 |
/** @type {import('./$types').RequestHandler} */
|
7 |
|
8 |
-
export async function POST({ cookies, request } : RequestEvent) {
|
|
|
|
|
9 |
const token = cookies.get('hf_access_token')
|
10 |
if (!token) {
|
11 |
return json({
|
12 |
-
error:
|
13 |
-
token: "You must be logged"
|
14 |
-
}
|
15 |
}, { status: 401 })
|
16 |
}
|
17 |
|
18 |
const is_token_available = await tokenIsAvailable(token)
|
19 |
if (!is_token_available) {
|
20 |
return json({
|
21 |
-
error:
|
22 |
-
token: "Invalid token"
|
23 |
-
}
|
24 |
}, { status: 401 })
|
25 |
}
|
26 |
|
27 |
-
const { emoji
|
28 |
|
29 |
if (!REACTION_EMOJIS.includes(emoji)) {
|
30 |
return json({
|
31 |
-
error:
|
32 |
-
emoji: "Invalid emoji"
|
33 |
-
}
|
34 |
-
}, { status: 400 })
|
35 |
-
}
|
36 |
-
|
37 |
-
if (!gallery_id ) {
|
38 |
-
return json({
|
39 |
-
error: {
|
40 |
-
gallery_id: "Invalid gallery_id"
|
41 |
-
}
|
42 |
}, { status: 400 })
|
43 |
}
|
44 |
|
45 |
const gallery = await prisma.gallery.findUnique({
|
46 |
where: {
|
47 |
-
id
|
48 |
}
|
49 |
})
|
50 |
|
51 |
if (!gallery) {
|
52 |
return json({
|
53 |
-
error:
|
54 |
-
gallery_id: "Gallery not found"
|
55 |
-
}
|
56 |
}, { status: 404 })
|
57 |
}
|
58 |
|
59 |
const reaction_exist = await prisma.reaction.findFirst({
|
60 |
where: {
|
61 |
-
galleryId:
|
62 |
userId: is_token_available.sub,
|
63 |
emoji
|
64 |
}
|
@@ -83,7 +69,7 @@ export async function POST({ cookies, request } : RequestEvent) {
|
|
83 |
emoji,
|
84 |
gallery: {
|
85 |
connect: {
|
86 |
-
id:
|
87 |
}
|
88 |
},
|
89 |
user: {
|
|
|
5 |
|
6 |
/** @type {import('./$types').RequestHandler} */
|
7 |
|
8 |
+
export async function POST({ cookies, request, params } : RequestEvent) {
|
9 |
+
const id = params.id
|
10 |
+
|
11 |
const token = cookies.get('hf_access_token')
|
12 |
if (!token) {
|
13 |
return json({
|
14 |
+
error: "You must be logged"
|
|
|
|
|
15 |
}, { status: 401 })
|
16 |
}
|
17 |
|
18 |
const is_token_available = await tokenIsAvailable(token)
|
19 |
if (!is_token_available) {
|
20 |
return json({
|
21 |
+
error: "Invalid token"
|
|
|
|
|
22 |
}, { status: 401 })
|
23 |
}
|
24 |
|
25 |
+
const { emoji } = await request.json()
|
26 |
|
27 |
if (!REACTION_EMOJIS.includes(emoji)) {
|
28 |
return json({
|
29 |
+
error: "Invalid emoji"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
}, { status: 400 })
|
31 |
}
|
32 |
|
33 |
const gallery = await prisma.gallery.findUnique({
|
34 |
where: {
|
35 |
+
id
|
36 |
}
|
37 |
})
|
38 |
|
39 |
if (!gallery) {
|
40 |
return json({
|
41 |
+
error: "Gallery not found"
|
|
|
|
|
42 |
}, { status: 404 })
|
43 |
}
|
44 |
|
45 |
const reaction_exist = await prisma.reaction.findFirst({
|
46 |
where: {
|
47 |
+
galleryId: id,
|
48 |
userId: is_token_available.sub,
|
49 |
emoji
|
50 |
}
|
|
|
69 |
emoji,
|
70 |
gallery: {
|
71 |
connect: {
|
72 |
+
id: id
|
73 |
}
|
74 |
},
|
75 |
user: {
|