2023-07-18 23:35:33 -04:00
|
|
|
/** @jsx jsx */
|
2024-10-11 16:02:11 +02:00
|
|
|
import { jsx } from 'hono/jsx';
|
|
|
|
|
import { Handler } from 'hono';
|
|
|
|
|
import { HTTPException } from 'hono/http-exception';
|
|
|
|
|
import { fetchProfile } from '../lib/fetchProfile';
|
2023-07-18 23:35:33 -04:00
|
|
|
|
|
|
|
|
export const getProfileData: Handler<
|
|
|
|
|
Env,
|
2024-10-11 16:02:11 +02:00
|
|
|
'/profile/:user/json' | '/https://bsky.app/profile/:user/json'
|
2023-07-18 23:35:33 -04:00
|
|
|
> = async (c) => {
|
|
|
|
|
const { user } = c.req.param();
|
2024-10-11 16:02:11 +02:00
|
|
|
const agent = c.get('Agent');
|
|
|
|
|
try {
|
|
|
|
|
var { data } = await fetchProfile(agent, { user });
|
|
|
|
|
} catch (e) {
|
2023-07-18 23:35:33 -04:00
|
|
|
throw new HTTPException(500, {
|
2024-10-11 16:02:11 +02:00
|
|
|
message: `Failed to fetch the profile!\n${e}`,
|
2023-07-18 23:35:33 -04:00
|
|
|
});
|
|
|
|
|
}
|
2024-10-11 16:02:11 +02:00
|
|
|
|
2023-07-18 23:35:33 -04:00
|
|
|
return c.json(data);
|
|
|
|
|
};
|