@@ -901,15 +901,15 @@ app.get('/oEmbed', async (req, res) => {
901901} ) ;
902902
903903app . get ( '/profileLookup' , async ( req , res ) => {
904- const { profile } = req . query ;
905- if ( ! profile ) {
904+ const { username , before , after , limit } = req . query ;
905+ if ( ! username ) {
906906 return res . render ( 'profile_lookup' , {
907907 title : 'Profile Lookup' ,
908908 } ) ;
909909 }
910910
911911 const params = {
912- [ PARAMS__USERNAME ] : profile ,
912+ [ PARAMS__USERNAME ] : username ,
913913 }
914914
915915 const profileLookupUrl = buildGraphAPIURL ( `profile_lookup` , params , req . session . access_token ) ;
@@ -921,7 +921,6 @@ app.get('/profileLookup', async (req, res) => {
921921 console . error ( e ?. response ?. data ?. error ?. message ?? e . message ) ;
922922 }
923923
924- const username = response . data ?. username ;
925924 const displayName = response . data ?. name ;
926925 const profilePictureUrl = response . data ?. profile_picture_url ;
927926 const isVerified = response . data ?. is_verified ;
@@ -934,8 +933,50 @@ app.get('/profileLookup', async (req, res) => {
934933 const repostsCount = formatCount ( response . data ?. reposts_count ) ;
935934 const viewsCount = formatCount ( response . data ?. views_count ) ;
936935
936+ const profilePostsParams = {
937+ [ PARAMS__FIELDS ] : [
938+ FIELD__TEXT ,
939+ FIELD__MEDIA_TYPE ,
940+ FIELD__MEDIA_URL ,
941+ FIELD__PERMALINK ,
942+ FIELD__TIMESTAMP ,
943+ ] . join ( ',' ) ,
944+ limit : limit ?? DEFAULT_THREADS_QUERY_LIMIT ,
945+ [ PARAMS__USERNAME ] : username ,
946+ } ;
947+ if ( before ) {
948+ profilePostsParams . before = before ;
949+ }
950+ if ( after ) {
951+ profilePostsParams . after = after ;
952+ }
953+
954+ let threads = [ ] ;
955+ let paging = { } ;
956+
957+ const queryThreadsUrl = buildGraphAPIURL ( `profile_posts` , profilePostsParams , req . session . access_token ) ;
958+
959+ try {
960+ const queryResponse = await axios . get ( queryThreadsUrl , { httpsAgent : agent } ) ;
961+ threads = queryResponse . data . data ;
962+
963+ if ( queryResponse . data . paging ) {
964+ const { next, previous } = queryResponse . data . paging ;
965+
966+ if ( next ) {
967+ paging . nextUrl = getCursorUrlFromGraphApiPagingUrl ( req , next ) ;
968+ }
969+
970+ if ( previous ) {
971+ paging . previousUrl = getCursorUrlFromGraphApiPagingUrl ( req , previous ) ;
972+ }
973+ }
974+ } catch ( e ) {
975+ console . error ( e ?. response ?. data ?. error ?. message ?? e . message ) ;
976+ }
977+
937978 return res . render ( 'profile_lookup' , {
938- title : 'Profile Lookup for @' . concat ( profile ) ,
979+ title : 'Profile Lookup for @' . concat ( username ) ,
939980 username,
940981 displayName,
941982 profilePictureUrl,
@@ -947,6 +988,8 @@ app.get('/profileLookup', async (req, res) => {
947988 repliesCount,
948989 repostsCount,
949990 viewsCount,
991+ paging,
992+ threads,
950993 } ) ;
951994} ) ;
952995
@@ -1065,6 +1108,7 @@ function getCursorUrlFromGraphApiPagingUrl(req, graphApiPagingUrl) {
10651108 setUrlParamIfPresent ( graphUrl , cursorUrl , 'limit' ) ;
10661109 setUrlParamIfPresent ( graphUrl , cursorUrl , 'before' ) ;
10671110 setUrlParamIfPresent ( graphUrl , cursorUrl , 'after' ) ;
1111+ setUrlParamIfPresent ( graphUrl , cursorUrl , 'username' ) ;
10681112
10691113 return cursorUrl . href ;
10701114}
0 commit comments