Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/types
8 changes: 8 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"semi": true,
"singleQuote": true,
"printWidth": 100,
"tabWidth": 2,
"useTabs": false,
"trailingComma": "es5"
}
7 changes: 0 additions & 7 deletions src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ console.log('Initializing API server on port', port);

const app = new Hono();



// Endpoint to get user profiles based on userName
app.get('/api/users', async (context) => {
try {
Expand Down Expand Up @@ -69,7 +67,6 @@ app.get('/api/threads/:threadId/replies', async (context) => {
}
});


// Endpoint to get user profile threads
app.get('/api/users/:userId/threads', async (context) => {
try {
Expand All @@ -90,10 +87,6 @@ app.get('/api/users/:userId/threads', async (context) => {
}
});





app.use('*', async (c) => {
c.notFound();
});
Expand Down
10 changes: 4 additions & 6 deletions src/lib/consts.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
export const THREADS_APP_ID = "238260118697367"
export const GRAPHQL_ENDPOINT = 'https://www.threads.net/api/graphql'
export const THREADS_APP_ID = '238260118697367';
export const GRAPHQL_ENDPOINT = 'https://www.threads.net/api/graphql';

export const ENDPOINTS_DOCUMENT_ID = {

USER_PROFILE: 23996318473300828,
USER_PROFILE_THREADS: 6451898791498605,
USER_PROFILE_THREADS_REPLIES: 6529829603744567,
USER_REPLIES: 6684830921547925,
THREADS_REPLIES: 6960296570650501,

}
};

export const getMidudev = () => `pheralb`
export const getMidudev = () => `pheralb`;
2 changes: 1 addition & 1 deletion src/lib/env.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const IS_DEBUG = Boolean(Bun.env.DEBUG)
export const IS_DEBUG = Boolean(Bun.env.DEBUG);
6 changes: 1 addition & 5 deletions src/lib/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
ENDPOINTS_DOCUMENT_ID,
THREADS_APP_ID,
GRAPHQL_ENDPOINT,
} from './consts';
import { ENDPOINTS_DOCUMENT_ID, THREADS_APP_ID, GRAPHQL_ENDPOINT } from './consts';
import { IS_DEBUG } from './env';
import { ThreadsUserProfileResponse } from '../types/threads-api';
import { mapUserProfile } from './map';
Expand Down
2 changes: 1 addition & 1 deletion src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './fetch';
export * from './fetch';
37 changes: 25 additions & 12 deletions src/lib/map.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
import { ThreadsUserProfileResponse} from '../types/threads-api'
import { ThreadsUserProfileResponse } from '../types/threads-api';

/*
{"data":{"userData":{"user":{"is_private":false,"profile_pic_url":"https://scontent.cdninstagram.com/v/t51.2885-19/358174537_954616899107816_8099109910283809308_n.jpg?stp=dst-jpg_s150x150&_nc_ht=scontent.cdninstagram.com&_nc_cat=108&_nc_ohc=s5qTOIc_KREAX8qfpDD&edm=APs17CUBAAAA&ccb=7-5&oh=00_AfDaktW3vHUeFvaE14qoy7LmddGuAqWUh2uirC7ulm_TsQ&oe=64B34341&_nc_sid=10d13b","username":"midu.dev","hd_profile_pic_versions":[{"height":320,"url":"https://scontent.cdninstagram.com/v/t51.2885-19/358174537_954616899107816_8099109910283809308_n.jpg?stp=dst-jpg_s320x320&_nc_ht=scontent.cdninstagram.com&_nc_cat=108&_nc_ohc=s5qTOIc_KREAX8qfpDD&edm=APs17CUBAAAA&ccb=7-5&oh=00_AfBUgVik0k-VaqXmyuuJUp6bEmAyDHIkkB3ssbnHYwGg_A&oe=64B34341&_nc_sid=10d13b","width":320},{"height":640,"url":"https://scontent.cdninstagram.com/v/t51.2885-19/358174537_954616899107816_8099109910283809308_n.jpg?stp=dst-jpg_s640x640&_nc_ht=scontent.cdninstagram.com&_nc_cat=108&_nc_ohc=s5qTOIc_KREAX8qfpDD&edm=APs17CUBAAAA&ccb=7-5&oh=00_AfCG0VVjm58zezRMrUgG_HlTuOL0MlMMsUpGRDgn4CrMiA&oe=64B34341&_nc_sid=10d13b","width":640}],"is_verified":false,"biography":"👨‍💻 Ingeniero de Software + JavaScript\n⌨️ Aprende Programación conmigo\n🏆 Google Expert + GitHub Star\n🙌 Comparto recursos y tutoriales","biography_with_entities":null,"follower_count":34756,"profile_context_facepile_users":null,"bio_links":[{"url":"https://twitch.tv/midudev"}],"pk":"8242141302","full_name":"midudev • Programación y Desarrollo JavaScript","id":null}}},"extensions":{"is_final":true}}
*/

export const mapUserProfile = (rawResponse: ThreadsUserProfileResponse) => {
const userApiResponse = rawResponse?.data?.userData?.user
if (!userApiResponse) return null
const userApiResponse = rawResponse?.data?.userData?.user;
if (!userApiResponse) return null;

const { username, is_verified, biography, follower_count, bio_links, pk: id, full_name, hd_profile_pic_versions, profile_pic_url } = userApiResponse
const {
username,
is_verified,
biography,
follower_count,
bio_links,
pk: id,
full_name,
hd_profile_pic_versions,
profile_pic_url,
} = userApiResponse;

const profile_pics = [{
height: 150,
width: 150,
url: profile_pic_url
}, ...hd_profile_pic_versions]
const profile_pics = [
{
height: 150,
width: 150,
url: profile_pic_url,
},
...hd_profile_pic_versions,
];

return {
id,
Expand All @@ -24,6 +37,6 @@ export const mapUserProfile = (rawResponse: ThreadsUserProfileResponse) => {
follower_count,
bio_links,
full_name,
profile_pics
}
}
profile_pics,
};
};