MCPcopy Create free account
hub / github.com/Useful-Scripts-Extension/useful-script / downloadAlbum

Function downloadAlbum

scripts/test.js:674–713  ·  view source on GitHub ↗
({ albumId, progress, cursor = null })

Source from the content-addressed store, hash-verified

672 }
673
674 async function downloadAlbum({ albumId, progress, cursor = null }) {
675 let result = [];
676 let retry = 3;
677 let tried = 0;
678 while (true) {
679 try {
680 let res = await fetchGraphQl({
681 fb_api_req_friendly_name:
682 "ProfileCometLegacyAlbumGridViewPaginationQuery",
683 variables: {
684 id: albumId,
685 scale: 1.5,
686 count: 14,
687 cursor,
688 },
689 doc_id: 5520045484790315,
690 });
691 let json = JSON.parse(res);
692 console.log(json);
693 const { edges, page_info } = json.data.node.grid_media;
694 result.push(
695 ...edges.map((edge) => ({
696 creationId: edge.node.creation_story.id,
697 uri: edge.node.image.uri,
698 id: edge.node.id,
699 }))
700 );
701 progress?.(result.length);
702 tried = 0; // reset tried
703 if (page_info?.has_next_page) cursor = page_info.end_cursor;
704 else break;
705 } catch (e) {
706 console.log("ERROR", e);
707 tried++;
708 if (tried > retry) break;
709 else await new Promise((resolve) => setTimeout(resolve, 2000));
710 }
711 }
712 return result;
713 }
714
715 const id = prompt("Nhập user/page id muốn tải:");
716 if (!id) return;

Callers 1

test.jsFile · 0.85

Calls 2

parseMethod · 0.80
fetchGraphQlFunction · 0.70

Tested by

no test coverage detected