diff --git a/src/lib/server/ap/homepage.js b/src/lib/server/ap/homepage.js index c17a78a..de6990d 100644 --- a/src/lib/server/ap/homepage.js +++ b/src/lib/server/ap/homepage.js @@ -52,7 +52,13 @@ export async function getHomepage({ account, passphrase, server }) { const s = await fetchFollowings(loginFormData, getCookie(r), person); const followings = getFollowingsFromResponse(s); const t = await fetchFollowingsMap(loginFormData, getCookie(s), followings); - const followingsMap = getFollowingsMapFromRsponses(t); + const followingsMap = getFollowingsMapFromResponses(t); + const u = await fetchFollowingsCollaborators( + loginFormData, + getCookie(t[t.length - 1]), + followingsMap + ); + const collaboratorsMap = getFollowingsCollabotorsFromResponses(u); if (dom('h2:contains("Your teams") + p').text().includes("aren't a member")) { console.log('No teams'); @@ -81,7 +87,8 @@ export async function getHomepage({ account, passphrase, server }) { } return { - cookies: getCookie(t[t.length - 1]), + collaboratorsMap, + cookies: getCookie(u[u.length - 1]), followings, followingsMap, person, @@ -118,7 +125,11 @@ function getFollowingsFromResponse(response) { return response.data; } -function getFollowingsMapFromRsponses(responses) { +function getFollowingsMapFromResponses(responses) { + return responses.map((response) => response.data); +} + +function getFollowingsCollabotorsFromResponses(responses) { return responses.map((response) => response.data); } @@ -161,3 +172,28 @@ async function fetchFollowingsMap(loginFormData, cookie, followings) { return Promise.all(mappedFollowings); } + +async function fetchFollowingsCollaborators(loginFormData, cookie, followingsMap) { + const headers = new AxiosHeaders(); + headers.set({ Cookie: cookie }); + + const mappedCollaborators = followingsMap.map(async (following) => { + const { pathname } = new URL(following.collaborators); + let response = null; + try { + response = await loginFormData.instance.get(pathname, { headers }); + } catch (exc) { + // Repo Collaborators is not implemented yet + response = { + data: { + items: [], + details: exc.response.data.error + } + }; + } + + return response; + }); + + return Promise.all(mappedCollaborators); +}