wiki-plugin-shoppe 0.0.8 → 0.0.10

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 +23 -13
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wiki-plugin-shoppe",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
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
@@ -9,9 +9,10 @@ const sessionless = require('sessionless-node');
9
9
 
10
10
  const SHOPPE_BASE_EMOJI = process.env.SHOPPE_BASE_EMOJI || '🛍️🎨🎁';
11
11
 
12
- const TENANTS_FILE = path.join(__dirname, '../.shoppe-tenants.json');
13
- const CONFIG_FILE = path.join(__dirname, '../.shoppe-config.json');
14
- const TMP_DIR = '/tmp/shoppe-uploads';
12
+ const DATA_DIR = path.join(process.env.HOME || '/root', '.shoppe');
13
+ const TENANTS_FILE = path.join(DATA_DIR, 'tenants.json');
14
+ const CONFIG_FILE = path.join(DATA_DIR, 'config.json');
15
+ const TMP_DIR = '/tmp/shoppe-uploads';
15
16
 
16
17
  // ============================================================
17
18
  // CONFIG (allyabase URL, etc.)
@@ -246,19 +247,27 @@ async function processArchive(zipPath) {
246
247
  zip.extractAllTo(tmpDir, true);
247
248
 
248
249
  try {
249
- // Find manifest.json — handle zips that wrap everything in a top-level folder
250
- let root = tmpDir;
251
- let manifestPath = path.join(tmpDir, 'manifest.json');
252
- if (!fs.existsSync(manifestPath)) {
253
- const entries = fs.readdirSync(tmpDir);
254
- if (entries.length === 1 && fs.statSync(path.join(tmpDir, entries[0])).isDirectory()) {
255
- root = path.join(tmpDir, entries[0]);
256
- manifestPath = path.join(root, 'manifest.json');
250
+ // Find manifest.json — handle zips wrapped in a top-level folder and
251
+ // macOS zips that include a __MACOSX metadata folder alongside the content.
252
+ function findManifest(dir, depth = 0) {
253
+ const direct = path.join(dir, 'manifest.json');
254
+ if (fs.existsSync(direct)) return dir;
255
+ if (depth >= 2) return null;
256
+ const entries = fs.readdirSync(dir).filter(f =>
257
+ f !== '__MACOSX' && fs.statSync(path.join(dir, f)).isDirectory()
258
+ );
259
+ for (const entry of entries) {
260
+ const found = findManifest(path.join(dir, entry), depth + 1);
261
+ if (found) return found;
257
262
  }
263
+ return null;
258
264
  }
259
- if (!fs.existsSync(manifestPath)) {
265
+
266
+ const root = findManifest(tmpDir);
267
+ if (!root) {
260
268
  throw new Error('Archive is missing manifest.json');
261
269
  }
270
+ const manifestPath = path.join(root, 'manifest.json');
262
271
 
263
272
  const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
264
273
  if (!manifest.uuid || !manifest.emojicode) {
@@ -705,7 +714,8 @@ function generateShoppeHTML(tenant, goods) {
705
714
  async function startServer(params) {
706
715
  const app = params.app;
707
716
 
708
- if (!fs.existsSync(TMP_DIR)) fs.mkdirSync(TMP_DIR, { recursive: true });
717
+ if (!fs.existsSync(DATA_DIR)) fs.mkdirSync(DATA_DIR, { recursive: true });
718
+ if (!fs.existsSync(TMP_DIR)) fs.mkdirSync(TMP_DIR, { recursive: true });
709
719
  console.log('🛍️ wiki-plugin-shoppe starting...');
710
720
 
711
721
  const owner = (req, res, next) => {