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

Function fetchAlbumPhotos

scripts/test.js:537–578  ·  view source on GitHub ↗
({
          albumId,
          access_token,
          pageLimit = Infinity,
          fromPhotoId = null,
          progress = async () => {},
        })

Source from the content-addressed store, hash-verified

535 }
536 }
537 async function fetchAlbumPhotos({
538 albumId,
539 access_token,
540 pageLimit = Infinity,
541 fromPhotoId = null,
542 progress = async () => {},
543 }) {
544 let currentPage = 1;
545 let hasNextCursor = true;
546 let nextCursor = fromPhotoId
547 ? Buffer.from(fromPhotoId).toString("base64")
548 : null;
549
550 let photIds = new Set();
551 let allImgsData = [];
552 while (hasNextCursor && currentPage <= pageLimit) {
553 const data = await fetchAlbumPhotosFromCursor({
554 albumId,
555 access_token,
556 cursor: nextCursor,
557 });
558 if (data?.imgData) {
559 let added = false;
560 for (let img of data.imgData) {
561 if (!photIds.has(img.id)) {
562 added = true;
563 photIds.add(img.id);
564 allImgsData.push(img);
565 }
566 }
567 await progress(photIds.size);
568
569 nextCursor = data.nextCursor;
570 hasNextCursor = added && nextCursor != null;
571 currentPage++;
572 } else {
573 console.log("[!] ERROR.");
574 break;
575 }
576 }
577 return allImgsData;
578 }
579
580 function downloadData(data, filename) {
581 let file = new Blob([data], { type: "text/plain" });

Callers 1

test.jsFile · 0.85

Calls 2

addMethod · 0.45

Tested by

no test coverage detected