@churchapps/content-providers 0.1.10 → 0.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +62 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +62 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1493,6 +1493,21 @@ async function fetchVenueActions(venueId) {
|
|
|
1493
1493
|
return null;
|
|
1494
1494
|
}
|
|
1495
1495
|
}
|
|
1496
|
+
async function fetchVenueImages(venueIds) {
|
|
1497
|
+
const map = /* @__PURE__ */ new Map();
|
|
1498
|
+
if (venueIds.length === 0) return map;
|
|
1499
|
+
try {
|
|
1500
|
+
const url = `${LESSONS_API_BASE}/venues/public/images?ids=${venueIds.join(",")}`;
|
|
1501
|
+
const response = await fetch(url, { method: "GET", headers: { Accept: "application/json" } });
|
|
1502
|
+
if (!response.ok) return map;
|
|
1503
|
+
const data = await response.json();
|
|
1504
|
+
for (const row of data) {
|
|
1505
|
+
if (row.venueId && row.lessonImage) map.set(row.venueId, row.lessonImage);
|
|
1506
|
+
}
|
|
1507
|
+
} catch {
|
|
1508
|
+
}
|
|
1509
|
+
return map;
|
|
1510
|
+
}
|
|
1496
1511
|
async function fetchFromProviderProxy(method, ministryId, providerId, path, authData, resolution) {
|
|
1497
1512
|
try {
|
|
1498
1513
|
const url = `${API_BASE3}/doing/providerProxy/${method}`;
|
|
@@ -1531,8 +1546,8 @@ function ministryToFolder(ministry) {
|
|
|
1531
1546
|
function planTypeToFolder(planType) {
|
|
1532
1547
|
return { type: "folder", id: planType.id, title: planType.name, path: "" };
|
|
1533
1548
|
}
|
|
1534
|
-
function planToFolder(plan) {
|
|
1535
|
-
return { type: "folder", id: plan.id, title: plan.name, path: "", isLeaf: true };
|
|
1549
|
+
function planToFolder(plan, thumbnail) {
|
|
1550
|
+
return { type: "folder", id: plan.id, title: plan.name, path: "", isLeaf: true, thumbnail };
|
|
1536
1551
|
}
|
|
1537
1552
|
function getFilesFromVenueFeed(venueFeed, itemType, relatedId) {
|
|
1538
1553
|
const files = [];
|
|
@@ -1728,9 +1743,15 @@ var B1ChurchProvider = class {
|
|
|
1728
1743
|
if (depth === 3) {
|
|
1729
1744
|
const ministryId = segments[1];
|
|
1730
1745
|
const planTypeId = segments[2];
|
|
1731
|
-
const
|
|
1746
|
+
const allPlans = await fetchPlans(planTypeId, authData);
|
|
1747
|
+
const yesterday = /* @__PURE__ */ new Date();
|
|
1748
|
+
yesterday.setDate(yesterday.getDate() - 1);
|
|
1749
|
+
yesterday.setHours(0, 0, 0, 0);
|
|
1750
|
+
const plans = allPlans.filter((p) => new Date(p.serviceDate).getTime() >= yesterday.getTime());
|
|
1751
|
+
plans.sort((a, b) => new Date(a.serviceDate).getTime() - new Date(b.serviceDate).getTime());
|
|
1752
|
+
const imageMap = await this.fetchPlanImages(plans, ministryId, authData);
|
|
1732
1753
|
return plans.map((p) => {
|
|
1733
|
-
const folder = planToFolder(p);
|
|
1754
|
+
const folder = planToFolder(p, imageMap.get(p.id));
|
|
1734
1755
|
return {
|
|
1735
1756
|
...folder,
|
|
1736
1757
|
isLeaf: true,
|
|
@@ -1740,6 +1761,43 @@ var B1ChurchProvider = class {
|
|
|
1740
1761
|
}
|
|
1741
1762
|
return [];
|
|
1742
1763
|
}
|
|
1764
|
+
async fetchPlanImages(plans, ministryId, authData) {
|
|
1765
|
+
const imageMap = /* @__PURE__ */ new Map();
|
|
1766
|
+
console.log(`[B1Church] fetchPlanImages: ${plans.length} plans, fields:`, plans.map((p) => ({ id: p.id, contentId: p.contentId, providerId: p.providerId, providerPlanId: p.providerPlanId })));
|
|
1767
|
+
const lessonsChurchPlans = plans.filter((p) => p.contentId && (!p.providerId || p.providerId === "lessonschurch"));
|
|
1768
|
+
const venueIds = lessonsChurchPlans.map((p) => p.contentId);
|
|
1769
|
+
console.log(`[B1Church] fetchPlanImages: ${lessonsChurchPlans.length} lessons.church plans, venueIds=${JSON.stringify(venueIds)}`);
|
|
1770
|
+
if (venueIds.length > 0) {
|
|
1771
|
+
const lcImages = await fetchVenueImages(venueIds);
|
|
1772
|
+
console.log(`[B1Church] fetchPlanImages: fetchVenueImages returned ${lcImages.size} images`);
|
|
1773
|
+
lcImages.forEach((img, venueId) => {
|
|
1774
|
+
const plan = lessonsChurchPlans.find((p) => p.contentId === venueId);
|
|
1775
|
+
if (plan) imageMap.set(plan.id, img);
|
|
1776
|
+
});
|
|
1777
|
+
}
|
|
1778
|
+
const externalPlans = plans.filter((p) => p.providerId && p.providerId !== "lessonschurch" && p.providerId !== "b1church" && p.providerPlanId);
|
|
1779
|
+
if (externalPlans.length > 0) {
|
|
1780
|
+
const groupKey = (p) => `${p.providerId}::${p.providerPlanId.split("/").slice(0, -1).join("/")}`;
|
|
1781
|
+
const groups = /* @__PURE__ */ new Map();
|
|
1782
|
+
for (const p of externalPlans) {
|
|
1783
|
+
const key = groupKey(p);
|
|
1784
|
+
if (!groups.has(key)) groups.set(key, []);
|
|
1785
|
+
groups.get(key).push(p);
|
|
1786
|
+
}
|
|
1787
|
+
await Promise.all(Array.from(groups.entries()).map(async ([key, groupPlans]) => {
|
|
1788
|
+
const [providerId, parentPath] = [key.split("::")[0], key.split("::").slice(1).join("::")];
|
|
1789
|
+
const items = await fetchFromProviderProxy("browse", ministryId, providerId, parentPath, authData);
|
|
1790
|
+
if (Array.isArray(items)) {
|
|
1791
|
+
for (const plan of groupPlans) {
|
|
1792
|
+
const leafId = plan.providerPlanId.split("/").pop();
|
|
1793
|
+
const match = items.find((item) => item.id === leafId || item.id === plan.contentId);
|
|
1794
|
+
if (match?.thumbnail) imageMap.set(plan.id, match.thumbnail);
|
|
1795
|
+
}
|
|
1796
|
+
}
|
|
1797
|
+
}));
|
|
1798
|
+
}
|
|
1799
|
+
return imageMap;
|
|
1800
|
+
}
|
|
1743
1801
|
// async getPresentations(path: string, authData?: ContentProviderAuthData | null): Promise<Plan | null> {
|
|
1744
1802
|
// const { segments, depth } = parsePath(path);
|
|
1745
1803
|
// if (depth < 4 || segments[0] !== "ministries") return null;
|