wiki-plugin-shoppe 0.0.34 → 0.0.35

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/server/server.js +32 -16
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wiki-plugin-shoppe",
3
- "version": "0.0.34",
3
+ "version": "0.0.35",
4
4
  "description": "Multi-tenant digital goods shoppe for federated wiki, powered by Sanora",
5
5
  "keywords": [
6
6
  "wiki",
package/server/server.js CHANGED
@@ -1186,8 +1186,13 @@ async function processArchive(zipPath, onProgress = () => {}) {
1186
1186
  const images = fs.readdirSync(entryPath).filter(f => IMAGE_EXTS.has(path.extname(f).toLowerCase()));
1187
1187
  const heroFile = images.find(f => /^hero\.(jpg|jpeg|png|webp)$/i.test(f)) || images[0];
1188
1188
  if (heroFile) {
1189
- const heroBuf = fs.readFileSync(path.join(entryPath, heroFile));
1190
- await sanoraUploadImage(tenant, title, heroBuf, heroFile);
1189
+ try {
1190
+ const heroBuf = fs.readFileSync(path.join(entryPath, heroFile));
1191
+ await sanoraUploadImage(tenant, title, heroBuf, heroFile);
1192
+ } catch (imgErr) {
1193
+ console.warn(`[shoppe] ⚠️ image upload for ${title}: ${imgErr.message}`);
1194
+ results.warnings.push(`Image upload for "${title}" failed: ${imgErr.message}`);
1195
+ }
1191
1196
  }
1192
1197
 
1193
1198
  results.products.push({ title, order, price, shipping });
@@ -3705,30 +3710,41 @@ async function startServer(params) {
3705
3710
  }
3706
3711
  });
3707
3712
 
3708
- // Music feed — adapts Sanora Canimus feed to { albums, tracks }
3713
+ // Music feed — builds { albums, tracks } from Sanora products directly
3709
3714
  app.get('/plugin/shoppe/:identifier/music/feed', async (req, res) => {
3710
3715
  try {
3711
3716
  const tenant = getTenantByIdentifier(req.params.identifier);
3712
3717
  if (!tenant) return res.status(404).json({ error: 'Shoppe not found' });
3713
- const feedResp = await fetchWithRetry(`${getSanoraUrl()}/feeds/music/${tenant.uuid}`, { timeout: 10000 });
3714
- if (!feedResp.ok) return res.status(502).json({ error: 'Feed unavailable' });
3715
- const feed = await feedResp.json();
3718
+ const sanoraUrl = getSanoraUrl();
3719
+ const productsResp = await fetchWithRetry(`${sanoraUrl}/products/${tenant.uuid}`, { timeout: 15000 });
3720
+ if (!productsResp.ok) return res.status(502).json({ error: 'Could not load products' });
3721
+ const products = await productsResp.json();
3716
3722
 
3717
3723
  const albums = [];
3718
3724
  const tracks = [];
3719
- for (const item of (feed.items || [])) {
3720
- const cover = (item.images && (item.images.cover?.url || item.images[0]?.url)) || null;
3721
- const mediaItems = (item.media || []).filter(m => m.url);
3722
- if (mediaItems.length === 0) continue;
3723
- if (mediaItems.length > 1) {
3725
+ for (const [key, product] of Object.entries(products)) {
3726
+ if (product.category !== 'music') continue;
3727
+ const cover = product.image ? `${sanoraUrl}/images/${product.image}` : null;
3728
+ const artifacts = product.artifacts || [];
3729
+ if (artifacts.length > 1) {
3724
3730
  albums.push({
3725
- name: item.name,
3731
+ name: product.title || key,
3726
3732
  cover,
3727
- description: item.summary || '',
3728
- tracks: mediaItems.map((m, i) => ({ number: i + 1, title: `Track ${i + 1}`, src: m.url, type: m.type || 'audio/mpeg' }))
3733
+ description: product.description || '',
3734
+ tracks: artifacts.map((a, i) => ({
3735
+ number: i + 1,
3736
+ title: `Track ${i + 1}`,
3737
+ src: `${sanoraUrl}/artifacts/${a}`,
3738
+ type: 'audio/mpeg'
3739
+ }))
3740
+ });
3741
+ } else if (artifacts.length === 1) {
3742
+ tracks.push({
3743
+ title: product.title || key,
3744
+ src: `${sanoraUrl}/artifacts/${artifacts[0]}`,
3745
+ cover,
3746
+ description: product.description || ''
3729
3747
  });
3730
- } else {
3731
- tracks.push({ title: item.name, src: mediaItems[0].url, cover, description: item.summary || '' });
3732
3748
  }
3733
3749
  }
3734
3750
  res.json({ albums, tracks });