wiki-plugin-shoppe 0.0.40 → 0.0.42
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/package.json +1 -1
- package/server/server.js +22 -1
package/package.json
CHANGED
package/server/server.js
CHANGED
|
@@ -3005,6 +3005,19 @@ async function startServer(params) {
|
|
|
3005
3005
|
if (!fs.existsSync(TMP_DIR)) fs.mkdirSync(TMP_DIR, { recursive: true });
|
|
3006
3006
|
console.log('🛍️ wiki-plugin-shoppe starting...');
|
|
3007
3007
|
|
|
3008
|
+
// Allow Shoppere desktop/mobile app (tauri://localhost) to call our JSON API
|
|
3009
|
+
const SHOPPERE_ORIGINS = ['tauri://localhost', 'https://tauri.localhost'];
|
|
3010
|
+
app.use('/plugin/shoppe', (req, res, next) => {
|
|
3011
|
+
const origin = req.headers.origin;
|
|
3012
|
+
if (origin && SHOPPERE_ORIGINS.includes(origin)) {
|
|
3013
|
+
res.setHeader('Access-Control-Allow-Origin', origin);
|
|
3014
|
+
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
|
|
3015
|
+
res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
|
|
3016
|
+
if (req.method === 'OPTIONS') return res.sendStatus(200);
|
|
3017
|
+
}
|
|
3018
|
+
next();
|
|
3019
|
+
});
|
|
3020
|
+
|
|
3008
3021
|
const owner = (req, res, next) => {
|
|
3009
3022
|
if (!app.securityhandler.isAuthorized(req)) {
|
|
3010
3023
|
return res.status(401).json({ error: 'must be owner' });
|
|
@@ -3767,7 +3780,15 @@ async function startServer(params) {
|
|
|
3767
3780
|
body: JSON.stringify({ timestamp: ts, signature: sig, order })
|
|
3768
3781
|
});
|
|
3769
3782
|
triggerTransfer();
|
|
3770
|
-
|
|
3783
|
+
// Return a download URL for digital goods so the Shoppere app can open the content
|
|
3784
|
+
const sanoraUrl = getSanoraUrl();
|
|
3785
|
+
const products = await fetchWithRetry(`${sanoraUrl}/products/${tenant.uuid}`).then(r => r.ok ? r.json() : {});
|
|
3786
|
+
const product = Object.values(products).find(p => p.uuid === productId || p.title === title);
|
|
3787
|
+
let downloadUrl = null;
|
|
3788
|
+
if (product && ['book', 'post', 'video'].includes(product.category)) {
|
|
3789
|
+
downloadUrl = `https://${req.get('host')}/plugin/shoppe/${tenant.uuid}/download/${encodeURIComponent(product.title)}`;
|
|
3790
|
+
}
|
|
3791
|
+
return res.json({ success: true, downloadUrl });
|
|
3771
3792
|
}
|
|
3772
3793
|
|
|
3773
3794
|
// ── Legacy recovery key paths ─────────────────────────────────────────
|