{"version":3,"file":"enable.mjs","names":[],"sources":["../../../../../../../src/astro/routes/api/admin/plugins/[id]/enable.ts"],"sourcesContent":["/**\n * Plugin enable endpoint\n *\n * POST /_emdash/api/admin/plugins/:id/enable - Enable a plugin\n */\n\nimport type { APIRoute } from \"astro\";\n\nimport { requirePerm } from \"#api/authorize.js\";\nimport { apiError, unwrapResult } from \"#api/error.js\";\nimport { handlePluginEnable } from \"#api/index.js\";\nimport { checkMediaUsageActivationWriteFence } from \"#api/media-usage-write-fence.js\";\nimport { setCronTasksEnabled } from \"#plugins/cron.js\";\n\nexport const prerender = false;\n\nexport const POST: APIRoute = async ({ params, locals }) => {\n\tconst { emdash, user } = locals;\n\tconst { id } = params;\n\n\tif (!emdash?.db) {\n\t\treturn apiError(\"NOT_CONFIGURED\", \"EmDash is not initialized\", 500);\n\t}\n\n\tconst denied = requirePerm(user, \"plugins:manage\");\n\tif (denied) return denied;\n\n\tconst activationFence = await checkMediaUsageActivationWriteFence(emdash.db);\n\tif (activationFence) return activationFence;\n\n\tif (!id) {\n\t\treturn apiError(\"INVALID_REQUEST\", \"Plugin ID required\", 400);\n\t}\n\n\tconst result = await handlePluginEnable(\n\t\temdash.db,\n\t\temdash.configuredPlugins,\n\t\temdash.sandboxedPluginEntries,\n\t\tid,\n\t);\n\n\tif (!result.success) return unwrapResult(result);\n\n\t// If this is a runtime-installed plugin (marketplace or registry),\n\t// the sandbox bundle may not be in memory yet -- a sync reloads it\n\t// from R2 so the just-enabled plugin can actually run hooks.\n\tconst source = result.data.item.source;\n\tif (source === \"registry\") {\n\t\tawait emdash.syncRegistryPlugins();\n\t} else if (source === \"marketplace\") {\n\t\tawait emdash.syncMarketplacePlugins();\n\t}\n\n\tawait emdash.setPluginStatus(id, \"active\");\n\tawait setCronTasksEnabled(emdash.db, id, true);\n\n\treturn unwrapResult(result);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcA,MAAa,YAAY;AAEzB,MAAa,OAAiB,OAAO,EAAE,QAAQ,aAAa;CAC3D,MAAM,EAAE,QAAQ,SAAS;CACzB,MAAM,EAAE,OAAO;AAEf,KAAI,CAAC,QAAQ,GACZ,QAAO,SAAS,kBAAkB,6BAA6B,IAAI;CAGpE,MAAM,SAAS,YAAY,MAAM,iBAAiB;AAClD,KAAI,OAAQ,QAAO;CAEnB,MAAM,kBAAkB,MAAM,oCAAoC,OAAO,GAAG;AAC5E,KAAI,gBAAiB,QAAO;AAE5B,KAAI,CAAC,GACJ,QAAO,SAAS,mBAAmB,sBAAsB,IAAI;CAG9D,MAAM,SAAS,MAAM,mBACpB,OAAO,IACP,OAAO,mBACP,OAAO,wBACP,GACA;AAED,KAAI,CAAC,OAAO,QAAS,QAAO,aAAa,OAAO;CAKhD,MAAM,SAAS,OAAO,KAAK,KAAK;AAChC,KAAI,WAAW,WACd,OAAM,OAAO,qBAAqB;UACxB,WAAW,cACrB,OAAM,OAAO,wBAAwB;AAGtC,OAAM,OAAO,gBAAgB,IAAI,SAAS;AAC1C,OAAM,oBAAoB,OAAO,IAAI,IAAI,KAAK;AAE9C,QAAO,aAAa,OAAO"}