-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
182 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { FreshContext } from "$fresh/server.ts"; | ||
|
||
export const handler = async ( | ||
req: Request, | ||
_ctx: FreshContext, | ||
): Promise<Response> => { | ||
if (req.method !== "POST") { | ||
return new Response(null, { status: 405 }); | ||
} | ||
|
||
const { emoji, access_token, postId, postUserId } = await req.json() as { | ||
emoji?: string; | ||
access_token?: string; | ||
postId?: string; | ||
postUserId?: string; | ||
}; | ||
|
||
if (!emoji || !access_token || !postId || !postUserId) { | ||
return new Response(null, { status: 400 }); | ||
} | ||
|
||
const reactResponse = await fetch( | ||
`https://mobile.bereal.com/api/content/realmojis?postId=${postId}&postUserId=${postUserId}`, | ||
{ | ||
headers: { | ||
authorization: `Bearer ${access_token}`, | ||
}, | ||
method: "POST", | ||
body: JSON.stringify({ | ||
emoji, | ||
}), | ||
}, | ||
); | ||
|
||
if (!reactResponse.ok) { | ||
return new Response( | ||
JSON.stringify( | ||
await reactResponse.json(), | ||
), | ||
{ | ||
status: 400, | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
}, | ||
); | ||
} | ||
|
||
return new Response( | ||
JSON.stringify( | ||
await reactResponse.json(), | ||
), | ||
{ | ||
status: 200, | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
}, | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { FreshContext } from "$fresh/server.ts"; | ||
import { FeedResp } from "~/types.ts"; | ||
|
||
export const handler = async ( | ||
req: Request, | ||
_ctx: FreshContext, | ||
): Promise<Response> => { | ||
if (req.method !== "POST") { | ||
return new Response(null, { status: 405 }); | ||
} | ||
|
||
const { access_token, emoji } = await req.json() as { | ||
access_token?: string; | ||
emoji?: string; | ||
}; | ||
|
||
if (!access_token || !emoji) { | ||
return new Response(null, { status: 400 }); | ||
} | ||
|
||
const initialFeedResponse = await fetch( | ||
"https://mobile.bereal.com/api/feeds/friends-v1", | ||
{ | ||
headers: { | ||
authorization: `Bearer ${access_token}`, | ||
}, | ||
}, | ||
); | ||
|
||
if (!initialFeedResponse.ok) { | ||
return new Response( | ||
JSON.stringify( | ||
await initialFeedResponse.json(), | ||
), | ||
{ | ||
status: 400, | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
}, | ||
); | ||
} | ||
|
||
const feed: FeedResp = await initialFeedResponse.json() as FeedResp; | ||
|
||
feed.friendsPosts.reduce(async (prms, batch) => { | ||
await prms; | ||
await batch.posts.reduce(async (prms, post) => { | ||
await prms; | ||
await fetch( | ||
`https://mobile.bereal.com/api/content/realmojis?postId=${post.id}&postUserId=${batch.user.id}`, | ||
{ | ||
headers: { | ||
authorization: `Bearer ${access_token}`, | ||
"content-type": "application/json", | ||
"accept": "application/json", | ||
}, | ||
method: "PUT", | ||
body: JSON.stringify({ emoji: `${emoji}` }), | ||
}, | ||
); | ||
await new Promise((resolve) => setTimeout(resolve, 300)); | ||
}, Promise.resolve()); | ||
}, Promise.resolve()); | ||
|
||
return new Response( | ||
JSON.stringify( | ||
{ success: true }, | ||
), | ||
{ | ||
status: 200, | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
}, | ||
); | ||
}; |